Route Traffic Through Linux Server With Two Devices

gatewayinterfacelinux-networkingnetworkingrouting

Here is my current setup (all servers are Ubuntu Server Edition 12.04):

Server 0 has two devices, eth0 and eth1. eth0 is connected to the wall (the internet), and eth1 is connected to a switch. eth1 has the following entry in /etc/network/interfaces:

auto eth1
iface eth1 inet static
address 192.168.1.1
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255

Servers 1-4 each have one device, eth0. They are all connected to the switch, and they all obtain their DHCP information from Server 0. eth0 has the following interfaces entry (This is because Servers 1-4 are diskless nodes that ask Server 0 for everything needed to boot):

iface eth0 inet manual

With this configuration, Server 0 is the only server that has access to the internet. How would I go about routing any web request (such as apt-get or HTTP) from Servers 1-4 through Server 0 in order to give Servers 1-4 internet access? This seems like a problem that has been encountered many times, but I cannot for the life of me figure out how to set up the network properly.

The output of route -n is:

Destination    Gateway         Genmask         Flags ... Iface
0.0.0.0        123.45.132.254  0.0.0.0         UG    ... eth0
123.45.132.0   0.0.0.0         255.255.255.0   U     ... eth0
192.168.1.0    0.0.0.0         255.255.255.0   U     ... eth1

Best Answer

You need to put two things : activating the forwarding (in /etc/sysctl.conf net.ipv4.ip_forward=1) and activate the NAT with iptables (/sbin/iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -o eth0 -j MASQUERADE). The NAT translate the private network to the external IP, so the internal machines can go on Internet. This line should be applied by your firewall. I don't know which firewall you have, so you must integrate it in your configuration.