Linux NAT via iptables

Posted by lane

If eth0 has an external network connection and you want to NAT your eth1 connection, you can use the following commands (as root):

echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
iptables -A FORWARD -i eth0 -o eth1 -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i eth1 -o eth0 -j ACCEPT

Leave a Reply