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

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:

192.168.20.0/24 via 192.168.20.253 dev eth0

Thanks in advance


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 10.0.0.0 netmask 255.255.255.0 gw 192.168.0.1

Problems:

  • 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
           done
       else
           net_log $"Legacy static-route support not available: /sbin/route not found"
       fi
    fi

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

add add the following

192.168.20.0/24 via 192.168.20.253 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