How to Create a Persistent Network Route in CentOS/RHEL 6

Routing is normally configured on routing devices, for example, your standard gateway, however if persistent routers are necessary they can be configured for each interface. This post describes how to configure a network route in the configuration files that will be persistent even after a reboot.

1. On CentOS/RHEL 6 systems, create a the file /etc/sysconfig/network-scripts/route-eth0 and set an persistent route for eth0 like:

# vi /etc/sysconfig/network-scripts/route-eth0
GATEWAY0=192.168.71.1
NETMASK0=255.255.255.0
ADDRESS0=192.168.55.0

GATEWAY1=192.168.70.1
NETMASK1=255.255.255.0
ADDRESS1=192.168.51.0

This will create two routes, one to the network 192.168.55.0 via 192.168.71.1 and another to network 192.168.51.0 via 192.168.70.1, both routes will use eth0.

2. There a different syntax that can be used as well:

192.168.71.0/24 via 192.168.55.0 dev eth0
192.168.70.0/24 via 192.168.51.0 dev eth0

Sample route outputs:

# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use  Iface
192.168.51.0    192.168.70.1    255.255.255.0   UG    0      0        0  eth0
192.168.55.0    192.168.71.1    255.255.255.0   UG    0      0        0  eth0
192.168.79.0    0.0.0.0         255.255.255.0   U     0      0        0  eth1
169.254.0.0     0.0.0.0         255.255.0.0     U     0      0        0  eth1
0.0.0.0         139.184.151.57  0.0.0.0         UG    0      0        0  eth0
# ip route show
192.168.51.0/24 via 192.168.70.1 dev eth0
192.168.55.0/24 via 192.168.71.1 dev eth0
192.168.79.0/24 dev eth1  proto kernel  scope link  src 192.168.79.120
169.254.0.0/16 dev eth1  scope link
default via 139.184.151.57 dev eth0