Trying to understand the correct way to create a static route in CentOS, please assist

Solution 1:

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 --

Solution 2:

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"

Solution 3:

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)