Simple internet sharing with NAT linux

From Kenneth Noyens
Jump to: navigation, search

activate ip forward:

echo 1 > /proc/sys/net/ipv4/ip_forward

Because changes is /proc/ are not saved and will be lost at every reboot you can edit /etc/sysctl.conf:

net.ipv4.ip_forward = 1

Now all packets are forwarded without NAT, to enable NAT enter this command:

iptables -t nat -A POSTROUTING -o wan0 -j MASQUERADE

Or make a script that executes before network bring up:

Make a file /etc/network/if-pre-up.d/routing:

iptables -t nat -A POSTROUTING -o wan0 -j MASQUERADE

Make the script executable:

chmod a+x routing