Iptables masquarading simple and working rule

This is a simple masquerading rule, to allow computers behind a Unix machine to access Internet.


echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -F
iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -j MASQUERADE

These three lines stand for:
– allow “IP” forwarding
– flush the “-t nat” table to ensure that there are no other rules that apply to your policy
– masquerade the traffic generated by the 192.168.1.0-192.168.1.255 network

You can add these three lines at the bottom of your “/etc/rc.local” file to ensure that after a reboot your machine will continue to masquerade.

Categories