Linux - Persistent routes not working

Hello,

I'm having problems with persistent routes.
I have the route added to route-eth1.

But when I run the 'route' command to display the routes, it does not show the newly added route.
I did restart the network service. That did not help.
I also rebooted the server, but still did not help.

I'm able to add route via command line, but they are not persistent. They go away once the network service is restarted or the server is rebooted.

Any help is appreciated.
Thanks.

When you set route with route command, it sets temporary and restarting network service will brush up all your temporary set routes.

In case of linux, permanent static routes are added on a per interface basis in files located in the /etc/sysconfig/network-scripts directory. The filename format is route-interface-name so the filename for interface wlan0 would be route-wlan0.

The format of the file is quite intuitive with the target network coming in the first column followed by the word via and then the gateway's IP address. In our routing example, to set up a route to network 10.0.0.0 with a subnet mask of 255.0.0.0 (a mask with the first 8 bits set to 1) via the 192.168.1.254 gateway, we would have to configure file /etc/sysconfig/network-scripts/route-wlan0 to look like this:

Note: The /etc/sysconfig/network-scripts/route-* filename is very important. Adding the wrong interface extension at the end will result in the routes not being added after the next reboot. There will also be no reported errors on the screen or any of the log files in the /var/log/ directory.

You can test the new file by running the

/etc/sysconfig/network-scripts/ifup-routes 

You can try this too..

 netstat -nr
  • nilesh