I've been trying to understand what's the correct way to add a static route on a CentOS 6.x machine. In some forums they say to create a file named route-dev_name (for example route-eth0) with the relevant route and place it in /etc/sysconfig/network-scripts , in some forums they say the file should be named static-routes , in both cases I'm unable to set a static route. It seems like in some CentOS releases it works only when naming the file route-dev_name and in some it only works when naming the file static-routes.. Can anyone please assist me? This is the content of my route file: via dev eth0

Thanks in advance

  • I'm using different CentOS versions on different servers, but mainly CentOS 6.3-6.5
    – Itai Ganot
    Feb 17, 2014 at 14:50

6 Answers 6


RH style device dependent routes defined using /etc/sysconfig/network-scripts/route-device files has caused lots of problems.

So real sysadmins use only /etc/sysconfig/static-routes file without device dependency:

any net netmask gw


  • When physical devices are bonded, you need to remember to chance route-device file too
  • When you reorganize adapters in a virtual machine.

Naturally one should always use bridge devices, so one could avoid route-device file problems.

Also notice the syntax in /etc/sysconfig/static-routes file, sniplet from /etc/init.d/network:

    # Add non interface-specific static-routes.
    if [ -f /etc/sysconfig/static-routes ]; then
       if [ -x /sbin/route ]; then
           grep "^any" /etc/sysconfig/static-routes | while read ignore args ; do
               /sbin/route add -$args
           net_log $"Legacy static-route support not available: /sbin/route not found"

Create a file in /etc/syconfig/network-scripts/route-eth0

add add the following via dev eth0

I have always used this approach. I have found this to be the best approach.

FYI: Check -- https://access.redhat.com/site/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Deployment_Guide/s1-networkscripts-static-routes.html

  • 1
    Okay's that's the approach I've been using myself until now, but recently on CentOS 6.5 machines I find that the route-devX file is being ignored and the servers do not Up the route when the server is rebooted or the network service is being restarted, any idea what could cause it?
    – Itai Ganot
    Feb 17, 2014 at 19:10
  • Not sure.. Does the interface come up on boot/restart?.. I do not have a CENTOS/RHEL 6.5 test box ATM.. I'm not sure if there is any change in ifup-routes on RHEL 6.5. Feb 18, 2014 at 8:24
  • Yea the interfaces operate properly... only the route is not coming up and i'm talking about freshly installed machine or about 2-3 months old. Anyways, I see that I use the correct approach so i'll just accept your question, thanks.
    – Itai Ganot
    Feb 18, 2014 at 8:57

There is an easier way to add routes...

This file - /etc/init.d/network - is launched when the PC is booting, and it uses a file /etc/sysconfig/static-routes to add static routes

You have to create it because it doesn't exist.

If you read carefully the file /etc/init.d/network, it reads in this file each line to add routes, those line must begin by "any", and "route add -" is already known.

So in the file you are going to create >> /etc/sysconfig/static-routes, you have to write :

any net netmask gw eth0
  • where is the network you want to reach ( is the mask)
  • where gw is the gateway to reach (certainly the router)
  • where eth0 is the interface where to use.

This is the best way for adding static routes, 1 file for everything (not X files for X interfaces)


I always use the route-ethX file approach on my CentOS 6.4 and 6.5 :

Create/edit file /etc/sysconfig/network-scripts/route-ethX (where X is your interface number) and set your route in this file : via dev eth0

You can also edit this file using the following format (personally i prefer the first syntax) :


Then restart the network to apply the changes :

service network restart

Further reading : https://www.centos.org/docs/5/html/5.2/Deployment_Guide/s1-networkscripts-static-routes.html


In /etc/sysconfig/network-scripts there's a script ifup-routes. It looks for files with the name route-dev_name, e.g. route-eth0.


On my case the file "/etc/sysconfig/network-scripts/route-device" didnt exist.

I proceed to add the required network or ip on the file "/etc/sysconfig/static-routes" and to make it permanently, I rebooted the machine and it turned out working as expected.

it was done in a : cat /etc/centos-release CentOS Linux release 7.5.1804 (Core)

Best regards,

Manuel Lazo

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.