In this how to, I am going to share how to add persistent or static routes on CentOS 5.9 and 6.4 versions. Assuming the network information below configured on the server itself with one network interface card, eth0: –
IP Address: 172.16.0.1
We need to add two static routes below and these routes don’t route to the default route of eth0 interface, 172.16.0.254: -
Here is how we can do it by creating this /etc/sysconfig/network-scripts/route-eth0 file. You have two ways to define the content. I had tested on CentOS 5.9 and 6.4 version and it works.
Option 1, include the below in /etc/sysconfig/network-scripts/route-eth0 file: -
Option 2, include the below in /etc/sysconfig/network-scripts/route-eth0 file: -
192.168.1.0/24 via 172.16.0.11 dev eth0
10.20.30.0/24 via 172.16.0.12 dev eth0
You can restart the network service to have the changes to take effect using this command: -
# service network restart
If there is no error, you can verify the routes using this command: -
# route -n
# netstat -rn
Your routes will be added automatically after every reboot. Please note that if you need to add routes to eth1 interface then you need to create /etc/sysconfig/network-scripts/route-eth1 file. Hope this helps you. Thank you.