How to Add Persistent Static Routes on RHEL 6/CentOS 6

This example will show you on how to configure the Persistent static route in RedHat Enterprise Linux 6 (RHEL 6) server. This configuration may different with other version of RHEL but the basic is almost the same. Persistent static route will permanently stored the setting and will not be deleted after rebooted. The following setting is just example only, you need to update the ip addresses and netmask in order to fit your environment :

To add a persistent static route in Redhat Enterprise Linux 6, create a file called route-X in the /etc/sysconfig/network-scripts/ directory. In this case, i will add persistent static route for eth0 and eth1.
1. Create a file route-eth0 rot eth0 routing :

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

2. Create a file route-eth1 rot eth1 routing :

[root@rhel6 ~]# vi /etc/sysconfig/network-scripts/route-eth1

Display routing table :

[root@rhel6 ~]# netstat -rn

How to Configure Static Routes on CentOS 6.2

Routing is the process of selecting paths in a network along which to send network traffic. It’s not necessary to configure Static Routes on Red Hat Enterprise Linux servers or CentOS servers since routing will be configured on routing devices such as routers, bridges, gateways, firewalls and switches. However, if static routes are required they can be configured for each interface. This can be useful when you have multiple network interfaces in different subnets such as eth0, eth1 and eth2. The following static route commands has been tested on Linux CentOS 6.2 server.

Display routing table using the following command :

[root@centos62 ~]# netstat -rn

This command will add the Static Routes on CentOS 6.2 server. For example network available via on device eth1 :

[root@centos62 ~]# ip route add via dev eth1

Alternatively, you can use this command :

[root@centos62 ~]# route add -net netmask gw dev eth1

Note : The drawback of using these two commands is it will forget the static routes when server rebooted.

How to Check Routing Table on Linux CentOS 6.2

In Linux operating system, routing table is used by the computer networks or servers to stores the routes of the destinations that responsible for forwarding. Routing tables contain a list of IP addresses and each of IP addresses identifies a network gateway. In this post, i will show you three ways to check and display the linux Routing Table. This command has been tested on CentOS 6.2 server.

1. Display routing table using “netstat -rn” :

[root@centos62 ~]# netstat -rn
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface   U         0 0          0 eth0     U         0 0          0 eth0         UG        0 0          0 eth0

2. Display routing table using “ip route show” :

[root@centos62 ~]# ip route show dev eth0  proto kernel  scope link  src dev eth0  scope link  metric 1002
default via dev eth0

3. Display routing table using “route -n” :

[root@centos62 ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface   U     0      0        0 eth0     U     1002   0        0 eth0         UG    0      0        0 eth0