How do I setup NAT on the WiFi interface on the rpiboot test images?

~ 0 min

Setup the wireless connection as normal by following the documentation.

Install the package to allow saving the iptables rules, say no to saving existing ipv4/ipv6 rules as you won't have any.

sudo apt-get -y install iptables-persistent

Add a default gateway to the IP configuration for the Pi Zeros

sudo sed -i "s/" /var/lib/clusterhat/nfs/p*/boot/cmdline.txt

Enable IPv4 forwarding

sudo sh -c "echo 'net.ipv4.ip_forward=1' >> /etc/sysctl.conf"
sudo sysctl -p /etc/sysctl.conf

Setup and save the NAT rules for traffic from the Pi Zero internal network range.

sudo iptables -t nat -A POSTROUTING -s ! -o brint -j MASQUERADE
sudo iptables -A FORWARD -i brint ! -o brint -j ACCEPT
sudo iptables -A FORWARD -o brint -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
sudo sh -c "iptables-save > /etc/iptables/rules.v4"

You should now be able to power up the Pi Zeros and access the internet through the wifi connection on the controller.

Average rating 5 (1 Vote)

You cannot comment on this entry