In this article, How To set a static route in CentOS/RHEL 6.x I will explain when it is necessary to use a static route and how to set it up. Static routing is a type of method of network routing. Static routing in not actually a routing protocol a manual configuration on the network route. This is usually managed by network system administrators. In linux, static routes can be added and deleted using the route command. But the drawback is when a Linux server is rebooted or when the network service is restarted, it will forget the static routes configuration. To avoid network interruption on the Linux server, you can configure static routes 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 a CentOS/RHEL 6.x server, the following steps should be performed:
Setting a static route:
Step 1 – Test the route before setting it as a permanent route
The command to add a static route is:
# route add -net netmask gw <gateway_ip> dev
Once you verify that the route is working properly you are ready to make it a permanent change.
Step 2 – Create a permanent route according to the route you created manually
To apply the configuration on next reboot or after the next network service restart, create a file called static-routes in:
And add the route there, like so:
# echo "any -net 192.168.60.0 netmask 255.255.255.0 gw 192.168.57.253 dev eth0" > /etc/sysconfig/network-scripts/static-routes
# nano /etc/sysconfig/network-scripts/static-routes
And add this line:
any -net 192.168.60.0 netmask 255.255.255.0 gw 192.168.57.253 dev eth0
Hit Ctrl+X to save the file.
Now you can safely reboot your server or restart the network service without worrying that the route you added will disappear.
I hope you liked this article, please feel free to leave comments or ask questions.
No Comments Yet