Software >> OS >> Unix >> Linux >> RHEL >> 7 >> How to set persistent IP static route

The script /etc/init.d/network will check for /etc/sysconfig/static-routes and execute if found.

Add the static routes into /etc/sysconfig/static-routes

 

/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

...

 add your custom persistent route accordingly into the file /etc/sysconfig/static-routes

 

example

any net 10.0.0.0 netmask 255.0.0.0 gw 10.1.1.254 dev eth0