How to add a persistant route in linux?

In a windows system a switch -p is used make a static route persistant in the routing table. How can a route be made persistant in linux?
route add -net x.x.x.x /x gw x.x.x.x adds the route but gets automatically flushed from the table if the route is not used for sometime or the system is restarted.
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

nabeelmoiduConnect With a Mentor Commented:
did u read that first link?
add that rule in

/etc/rc.local file

so when system will reboot, it will added automaticaly
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Monis MontherSystem ArchitectCommented:
This issue has been resolved successfully a week a go , check this question

Meru_ITAuthor Commented:
Thanks small student. My situation is a little different than that. I have a server on an ethernet network connected on eth0 and using the IP of my L3 switch as the default gateway. Now I need to connect to a particular host on the on internet through a USB CDMA modem such that any traffic from my server to this host takes the CDMA route through the virtual ppp0 interface and not the eth0 interface.
I need to add a static route 'route add -host x.x.x.x gw x.x.x.x' (the gateway IP should be the remote IP assigned dynamically by the CDMA service provider). This route needs to be persistant and should not be flushed from the server's routing table if the connection is idle or even if the server is restarted.

Hope I am clear about the requirement.

Thanks in advance
Monis MontherSystem ArchitectCommented:
Ok I assume the when you do it manually with route add it worked fine for you, its just that you want it persistent after reboots

Fosiual01 provided a good solution.

Just make sure that it will also work in case you disconnect the USB and connect it back again after a while (in theory it will) in case it will not there is another solution but it would be more complecated, just let me know how it goes

Meru_ITAuthor Commented:
Hi small_student, sorry for the delay in responding. On disconnecting the USB modem or in case the connection is inactive for a while, the route gets flushed from the routing table.

I have added the route in rc.local which only helps adding the route at boot time but not to make it persistent in the table.

Please help!
Meru_ITAuthor Commented:
Follow the link for the solution.

Create a route- file in /etc/sysconfig/network-scripts/ and add static route with syntax as -
x.x.x.x/x via x.x.x.x dev

In my case, I added a route-bond0 file, made it executable  with chmod 777 and added the static route in the file. Then restarted network service.

Thanks all.
All Courses

From novice to tech pro — start learning today.