Set a static route in CentOS/RHEL 6.x

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


How To: Set a static route in CentOS/RHEL 6.x -

Linux static route – Test the route before setting it as a permanent route

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 netmask gw dev eth0" > /etc/sysconfig/network-scripts/static-routes


# nano /etc/sysconfig/network-scripts/static-routes

And add this line:

any -net netmask gw 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.



1 Comment

  1. toms soes on May 3, 2014 at 8:02 pm

    toms soes

    Just want to say your article is astounding. The clarity in your post is simply spectacular and i can assume you are an expert on this field. Well with your permission allow me to grab your rss feed to keep up to date with incoming post. Thanks a milli…

Leave a Comment

You must be logged in to post a comment.