Home » Random Goodies » Out of network gateway IP on CentOS

Out of network gateway IP on CentOS

I recently noticed that CentOS will refuse to assign an out of network gateway IP. Even though your network scripts syntax may be correct, it will still refuse to work no matter how many times you restart your network 🙂

Assuming your configuration is:

IP: 1.2.3.4
Device: eth0
Netmask: 255.255.255.255
Gateway: 5.6.7.8

The default gateway route will have to be created as follows:

route add -host 5.6.7.8 dev eth0
route add default dev eth0 gw 5.6.7.8

Now to have eth0 use 5.6.7.8 as the gateway on boot, you would have to add the above lines to:

/etc/sysconfig/network-scripts/ifcfg-eth0

This was tested on a CentOS 6.3 x86_64 Virtual Machine using ESXi 5.0 😀