Enabling IP routing
Say a cluster exports a disk to one machine, and you want to make that disk available to all machines in your cluster. Basically, you want to use that one machine as a router. Here is how to do it:
- 1. Change `net.ipv4.ip_forward = 0` to `net.ipv4.ip_forward = 1` in `/etc/sysctl.conf
- 2. Also run `sysctl -w net.ipv4.ip_forward=1` to avoid restarting.
- 3. Add the following at the top of `/etc/sysconfig/iptables` (before `*filter`)
*nat -A POSTROUTING -o bond0.100 -j MASQUERADE COMMIT
- 4. Add the following to the end of `/etc/sysconfig/iptables` (before `-A FORWARD -j REJECT --reject-with icmp-host-prohibited`)
-A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT -A FORWARD -m state --state NEW -i bond0.101 -d 169.230.79.14 -j ACCEPT
5. Restart iptables: `service iptables restart`
Alternative method:
Ben: Same as steps 1 & 2 above. However, in step 3 & 4:
3. # enable post route
*nat :POSTROUTING ACCEPT [0:0] -A POSTROUTING -o <name of interface to route traffic out of> -j MASQUERADE COMMIT
4. # NAT forwarding
-A FORWARD -i <input interface> -o <output interface> -j ACCEPT -A FORWARD -i <output interface> -o <input interface> -m state --state RELATED,ESTABLISHED -j ACCEPT
5. Restart iptables with 'service iptables restart'
on the nodes
echo "169.230.79.14:/diva2 /mnt/sali/diva2 nfs ro,noatime,tcp,intr 0 0" >> /etc/fstab mkdir -pv /mnt/sali/diva2 route add 169.230.79.14 gw 10.0.1.157
For CentOS 7.5.1804
Temporary:
# route add default gw <IP Address of machine that will route>
For Ubuntu 16.04
Our Ubuntu 16.04 server had no public IP address but needed public network connectivity. This server got its network configuration from our DHCP server but the DHCP server config did not include routes. To have a permanent routing configuration even after network/system restarts for this DHCP client, we must edit the dhclient configurations to maintain a route through our other host, epsilon. To do this:
1. Edit /etc/dhcp/dhclient.conf
2. Add the following line to the bottom of the configuration file:
supersede routers <ip address of routing machine>;
Example: We use epsilon as our routing machine. The private IP address of epsilon is 10.20.1.5 so the resulting dhclient.conf for the client would look like:
supersede routers 10.20.1.5;