How to Setup Persistent Static Routes on Linux CentOS 6.4

linuxStatic routing is a type of method of network routing. Static routing is not actually a routing protocol but it’s just a manual configuration on the network route. This usualy managed by network system administrator. In Linux, static route can be added and delete using “route” command. But the drawback is when linux server is rebooted, it will forget the static routes configuration. To avoid network interruption on the linux server, you can configure static route to take effect immediately without rebooting and also should apply after the next reboot. Static Routes that apply after next reboot is called Persistent Static Routes. To achieve this on CentOS 6.4, the following steps should be perform :

1. To make configuration take effect immediately, run the following command :

[root@centos62 ~]# route add -net <network> netmask <netmask> gw <gateway_ip> dev <interface>

Examples :

[root@centos64 ~]# route add -net 192.168.1.0 netmask 255.255.255.0 gw 192.168.1.1 dev eth0
[root@centos64 ~]# route add -net 172.13.1.0 netmask 255.255.0.0 gw 172.13.1.1 dev eth1

2. To apply the configuration on next reboot, configure the following in /etc/sysconfig/static-routes :

[root@centos62 ~]# vi /etc/sysconfig/static-routes

Add the followings :

any -net 192.168.1.0 netmask 255.255.255.0 gw 192.168.1.1
any -net 172.13.1.0 netmask 255.255.0.0 gw 172.13.1.1

Three Ways to Configure Persistent Static Routes on Linux CentOS

centos6There are several different ways to configure persistent static routes on Linux CentOS. By using Static routes, we can improves overall performance of the network and static routing is achieved by manually adding routes to the routing table. Static route can be added and delete using “route” command. But it will forget the static routes configuration when server rebooted. This will lead to the network interruption. Follow one of these three options to configure static route on CentOS.

1. Edit the file /etc/sysconfig/network-scripts/route- and then add the following lines :

[root@centos63 ~]# vi /etc/sysconfig/network-scripts/route-eth0

GATEWAY0=<gateway address>
NETMASK0=<network netmask>
ADDRESS0=<network address>
GATEWAY1=<gateway address>
NETMASK1=<network netmask>
ADDRESS1=<network address>

Examples :

GATEWAY0=192.168.1.1
NETMASK0=255.255.255.0
ADDRESS0=192.168.1.54
GATEWAY1=192.168.2.1
NETMASK1=255.255.255.0
ADDRESS1=192.168.2.54

2. Edit the file /etc/sysconfig/network-scripts/route- and then add the following lines :

192.168.1.0/24 via 192.168.1.1 dev eth0
192.168.2.0/24 via 192.168.2.1 dev eth0

3. Edit the file /etc/sysconfig/static-routes as below :

any -net 192.168.1.0 netmask 255.255.255.0 gw 192.168.1.1
any -net 192.168.2.0 netmask 255.255.255.0 gw 192.168.2.1

How to Configure Persistent Static Routes on Linux CentOS 6.2

In this post, i will share on how to configure persistent static routes on linux CentOS 6.2 server. By using Static routes, we can improves overall performance of the network. Static route can be added and delete using “route” command. But the drawback is when linux server is rebooted, it will forget the static routes configuration. To avoid network interruption the following condition should be follow :

1. The static route configuration should take effect immediately without rebooting.
2. The static route configuration should also apply after the next reboot.

Solutions :
To make configuration take effect immediately, run the following command :

[root@centos62 ~]# route add -net <network> netmask <netmask> gw <gateway_ip> dev <interface>

Examples :

[root@centos62 ~]# route add -net 192.168.1.0 netmask 255.255.255.0 gw 192.168.1.1 dev eth0
[root@centos62 ~]# route add -net 192.168.2.0 netmask 255.255.255.0 gw 192.168.2.1 dev eth1
[root@centos62 ~]# route add -net 192.168.3.0 netmask 255.255.255.0 gw 192.168.3.1 dev eth2

To apply the configuration on next reboot, configure the following in /etc/sysconfig/static-routes :

[root@centos62 ~]# vi /etc/sysconfig/static-routes

Add the followings :

any -net 192.168.1.0 netmask 255.255.255.0 gw 192.168.1.1
any -net 192.168.2.0 netmask 255.255.255.0 gw 192.168.2.1
any -net 192.168.3.0 netmask 255.255.255.0 gw 192.168.3.1