To enable a machine to act as a gateway for a network:
echo "1" > /proc/sys/net/ipv4/ip_forward iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -j MASQUERADE
Where 192.168.1.0/24 is the network which will use this machine as a gateway.
To make this permanent, on Debian/Ubuntu:
touch /etc/network/if-up.d/iptables chmod 755 /etc/network/if-up.d/iptables
And add the following to the new file:
#!/bin/bash echo "1" > /proc/sys/net/ipv4/ip_forward iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -j MASQUERADE
For Red Hat/Fedora:
iptables-save
and edit /etc/sysctl.conf, changing the line net.ipv4.ip_forward=0
to:
net.ipv4.ip_forward=1
Then running sysctl -p to make sysctl restart with the new values.
Good IP Tables Tutorial: