Configure NAT on Raspberry Pi

In this blog we will see how to setup NAT on Raspberry Pi between eth0 and wlan0

sudo nano /etc/sysctl.conf

add the following line at the end of the file

net.ipv4.ip_forward=1

Pi_IP_fwd

run the following to setup the bridge between wlan0 and eth0


sudo iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE

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

sudo iptables -A FORWARD -i eth0 -o wlan0 -j ACCEPT

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

Pi_Routing_tables

run sudo nano /etc/network/interfaces and add

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

at the very end

etc_network_interfaces

@Source : adafruit

Add a Comment

Your email address will not be published. Required fields are marked *