So here's a step-by-step list of things you need to do to NAT-route between 2 networks.
Let's say your network settings are as follows:
a) LAN_INTERFACE="eth0"
b) INET_INTERFACE="eth1"
c) INET_GATEWAY="192.168.1.1"
First things first:
1) Enable IPv4 forwarding:
Edit /etc/sysctl.conf, and enable "net.ipv4.ip_forward=1", to look like this:
In order to enable IPv4 forwarding immediately, do the following:# Uncomment the next line to enable packet forwarding for IPv4
net.ipv4.ip_forward=1
Code: Select all
sudo su
echo "1" > /proc/sys/net/ipv4/ip_forward
Code: Select all
cat /proc/sys/net/ipv4/ip_forward
2) Enable network-address-translation (NAT) between the networks, using "iptables":
Code: Select all
iptables -t nat -A POSTROUTING -o $INET_INTERFACE -j MASQUERADE
Code: Select all
route add default gw $INET_GATEWAY
Code: Select all
route