IP forwarding for compute nodes

In order to enable the nodes to have internet or LAN access from its private network, we need to forward the internet traffic on its private network eth0 to public network eth1 on the master node

Master node

On the master, allow IP forwarding for IPv4:

sudo echo 1 > /proc/sys/net/ipv4/ip_forward

Uncomment the net.ipv4.ip_forward=1 line in /etc/sysctl.conf. This is the same change as above, but makes it persistent. Make this change with your favorite editor, or with sed on the command line:

sudo sed -i 's/#net.ipv4.ip_forward=1/net.ipv4.ip_forward=1/g' /etc/sysctl.conf

Add the following rules to iptables and make them persistent:

sudo iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE
sudo iptables -A FORWARD -i eth1 -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
sudo iptables -A FORWARD -i eth0 -o eth1 -j ACCEPT
sudo apt-get update
sudo apt-get install iptables-persistent
sudo iptables-save > /etc/iptables/rules.v4

The above should be tested to ensure it survives a reboot. Anytime you add new rules to iptables manually, you will need to save them as per above for them to be persistent.

Compute nodes

On each compute node, set default routing through the eth0 network connection, using the master node as the gateway:

sudo ip route add default via 10.0.0.100

This can be done using pdsh.

You will also need to make this change permanent, which can be done by adding

          gateway 10.0.0.100

to /etc/network/interfaces.d/eth0.

Last updated