-   Linux - Networking (
-   -   permanently add static route (

glock19 03-21-2002 05:24 PM

permanently add static route
There is another network in my office, on a different sub-net, to which I need to connect on a regular basis.

The two sub-nets are connected by a computer with 2 network cards, running a linux software router.

This is what I've been doing to get connected:


/sbin/route add -net netmask gw
Which works fine. The only problem is that this route disappears if I reboot my system. So, what would be the best way to permanently add that route to my system?

Sixpax 03-21-2002 05:57 PM

Take a look at this script:


It references a file called /etc/static-routes. It looks like you list them there and this file will handle adding them to the routing table for you on bootup.

glock19 03-21-2002 06:46 PM

I don't have a file called 'static-routes' anywhere on my system.

acid_kewpie 03-21-2002 07:32 PM

my gateways etc.. are defined in /etc/sysconfig/network.

Sixpax 03-21-2002 08:27 PM

Acid, do static routes go there? if so, what's the syntax?

The /etc/sysconfig/network-scripts/ifup-routes specifically looks for /etc/sysconfig/static-routes, if the file isn't found it simply exits, but if not, it parses the entries one line at a time doing a "/sbin/route add -$args" on each entry.

All you should need to do is create that file and put in the following line:

eth0 net netmask gw

of course if your nic isn't eth0, use whatever is appropriate for your system.

acid_kewpie 03-21-2002 08:40 PM

mine just says


and i *think* that's all the parameters there are. i think you can alternatively speciffy the interface to use rather than the IP with GATEDEV= or something, but that's it.

Sixpax 03-21-2002 10:21 PM

Yeah, that is how you setup your default gw, but in order to setup a static route you need more information than that. I honestly don't think you can put a static route definition in there. I suspect the script that sources that file is only looking for the information you listed.

aaronsols 03-22-2002 03:03 AM


your problems are solved if you add that route add statement in /etc/rc.d/rc.local file , every time your machine starts this will be executed and your route tables are updated,

Sixpax 03-22-2002 11:52 AM

Until you ever upgrade your initscripts package, then rc.local will get overwritten :rolleyes:

jrwsod 06-05-2009 05:42 PM

The correct way to add a permanent is as follows...
I know this is an old thread but it kills me to see people using the rc.local file for this. This is not the right way to do this.
The correct way to add permanent static routes to a system besides setting the default gateway is to create a file /etc/sysconfig/network-scripts/route-eth0 (or whichever interface you want to route through). You can add as many routes as you would like per interface by simply incrementing the number at the end of each statement. Once saved a restart of the network services will force a read of this route file.
The syntax of the file should look like this:


MyProvider 10-18-2009 11:58 AM


Originally Posted by jrwsod (Post 3564635)
I know this is an old thread ...
The syntax of the file should look like this:


Thank you jrwsod,

Was finding a lot of different ways, this looks like the right and most simple way. Worked perfectly (ofcourse..)


marrydavidson101 04-17-2010 05:36 AM

I cannot understand your conception (what do you wont to achieve), bu change parent of filters to 1: (filter ... parent 1. Now the packets will be directed to 1:2 class.

sumansameer 05-05-2010 02:58 AM

impressive keep it up

bigfootw 05-28-2010 05:21 AM

is "/etc/sysconfig/static_routes" deprecated in rhel?

Sometime people say using "/etc/sysconfig/network-scripts/route-ethx"; sometime people say using "/etc/sysconfig/static_routes", this only makes me confusing.

traqs 06-16-2010 04:42 PM

does this work in gentoo linux?

All times are GMT -5. The time now is 02:39 PM.