Raspberry PI NAT (for WiFi Router)

Configure Network Address Translation

Setting up NAT will allow multiple clients to connect to the WiFi and have all the data ‘tunneled’ through the single Ethernet IP. (But you should do it even if only one client is going to connect)


sudo vi /etc/sysctl.conf

uncomment this line (or scroll to the bottom and add if it is not there!)


Save the file. This will start IP forwarding on boot up.

To reload the file without rebooting .. 
sudo sysctl -p

Run the following commands to create the network translation between the ethernet port eth0 and the wifi port wlan0

sudo iptables t nat A POSTROUTING o eth0 j MASQUERADE

sudo iptables A FORWARD i eth0 o wlan0 m state state RELATED,ESTABLISHED j ACCEPT

sudo iptables A FORWARD i wlan0 o eth0 j ACCEPT

You can check to see whats in the tables with

sudo iptables -t nat -S
sudo iptables -S

To make this happen on reboot (so you don’t have to type it every time) run

sudo sh -c “iptables-save > /etc/iptables.ipv4.nat”


sudo vi /etc/network/interfaces

and add

up iptables-restore < /etc/iptables.ipv4.nat

to the very end

3 thoughts on “Raspberry PI NAT (for WiFi Router)

Leave a Reply