LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 03-21-2002, 04:24 PM   #1
glock19
Member
 
Registered: Aug 2001
Distribution: Debian Etch
Posts: 510

Rep: Reputation: 32
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:

Code:
/sbin/route add -net 192.168.1.0 netmask 255.255.255.0 gw 192.168.168.72
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?
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 03-21-2002, 04:57 PM   #2
Sixpax
Member
 
Registered: Mar 2002
Distribution: Mandrake 8.1
Posts: 386

Rep: Reputation: 31
Take a look at this script:

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

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.
 
Old 03-21-2002, 05:46 PM   #3
glock19
Member
 
Registered: Aug 2001
Distribution: Debian Etch
Posts: 510

Original Poster
Rep: Reputation: 32
I don't have a file called 'static-routes' anywhere on my system.
 
Old 03-21-2002, 06:32 PM   #4
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
my gateways etc.. are defined in /etc/sysconfig/network.
 
Old 03-21-2002, 07:27 PM   #5
Sixpax
Member
 
Registered: Mar 2002
Distribution: Mandrake 8.1
Posts: 386

Rep: Reputation: 31
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 192.168.1.0 netmask 255.255.255.0 gw 192.168.168.72

of course if your nic isn't eth0, use whatever is appropriate for your system.
 
Old 03-21-2002, 07:40 PM   #6
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
mine just says

NETWORKING=yes
FORWARD_IPV4=false
HOSTNAME=trevor
GATEWAY=10.0.0.2

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.
 
Old 03-21-2002, 09:21 PM   #7
Sixpax
Member
 
Registered: Mar 2002
Distribution: Mandrake 8.1
Posts: 386

Rep: Reputation: 31
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.
 
Old 03-22-2002, 02:03 AM   #8
aaronsols
Member
 
Registered: Feb 2002
Location: INDIA
Distribution: Red Hat
Posts: 30

Rep: Reputation: 15
hi

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,
 
Old 03-22-2002, 10:52 AM   #9
Sixpax
Member
 
Registered: Mar 2002
Distribution: Mandrake 8.1
Posts: 386

Rep: Reputation: 31
Until you ever upgrade your initscripts package, then rc.local will get overwritten
 
Old 06-05-2009, 04:42 PM   #10
jrwsod
LQ Newbie
 
Registered: Mar 2009
Posts: 4

Rep: Reputation: 3
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:
ADDRESS0=x.x.x.x
GATEWAY0=x.x.x.x
NETMASK0=x.x.x.x
ADDRESS1=x.x.x.x
GATEWAY1=x.x.x.x
NETMASK1=x.x.x.x

Enjoy!
 
3 members found this post helpful.
Old 10-18-2009, 10:58 AM   #11
MyProvider
LQ Newbie
 
Registered: Oct 2009
Posts: 1

Rep: Reputation: 2
Quote:
Originally Posted by jrwsod View Post
I know this is an old thread ...
The syntax of the file should look like this:
ADDRESS0=x.x.x.x
GATEWAY0=x.x.x.x
NETMASK0=x.x.x.x
ADDRESS1=x.x.x.x
GATEWAY1=x.x.x.x
NETMASK1=x.x.x.x

Enjoy!

Thank you jrwsod,

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


MyProvider
 
2 members found this post helpful.
Old 04-17-2010, 04:36 AM   #12
marrydavidson101
LQ Newbie
 
Registered: Apr 2010
Posts: 1

Rep: Reputation: 0
Hi,
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.
 
Old 05-05-2010, 01:58 AM   #13
sumansameer
LQ Newbie
 
Registered: May 2010
Posts: 1

Rep: Reputation: 0
impressive keep it up
 
Old 05-28-2010, 04:21 AM   #14
bigfootw
LQ Newbie
 
Registered: Jan 2009
Posts: 3

Rep: Reputation: 0
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.
 
Old 06-16-2010, 03:42 PM   #15
traqs
LQ Newbie
 
Registered: May 2010
Posts: 1

Rep: Reputation: 0
does this work in gentoo linux?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
I am not able to add a new route to my route table using route command prashanth s j Linux - Networking 2 09-03-2005 04:34 AM
add a static route in Network init files Ghitza Linux - Networking 1 11-19-2004 05:26 AM
How to permanently add localhost via xhost? h00chman Linux - Newbie 1 04-23-2004 11:57 PM
how to permanently add route? rob99 Linux - Networking 5 07-19-2003 06:39 AM
Permanently set "route add" -host and default gw sacants Linux - Newbie 1 07-18-2003 04:04 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 08:21 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration