LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 07-01-2010, 01:43 PM   #16
mwburden
LQ Newbie
 
Registered: Aug 2009
Posts: 13

Rep: Reputation: 1

Just wanted to add my $0.02 to say that jrwsod has the correct answer (and, IMHO, is correct for chastising those who use the rc files to do this.)
 
1 members found this post helpful.
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 10-02-2010, 03:31 AM   #17
dantux
LQ Newbie
 
Registered: Jul 2006
Location: Romania, Brasov, Harman
Distribution: Fedora, RedHat
Posts: 17
Blog Entries: 2

Rep: Reputation: 0
Thanks jrwsod, your instructions were great. I finally got my default gateway to stick by adding the following to
/etc/sysconfig/network-scripts/route-eth2

ADDRESS0=0.0.0.0
GATEWAY0=192.168.1.1
NETMASK0=0.0.0.0
 
Old 06-06-2011, 01:04 PM   #18
ngwasuma
Member
 
Registered: Jan 2005
Distribution: Fedora11
Posts: 45

Rep: Reputation: 16
add it to /etc/rc.local

Ad your commandline to /etc/rc.local and it be run each time the computer starts
 
Old 06-07-2011, 08:19 AM   #19
mwburden
LQ Newbie
 
Registered: Aug 2009
Posts: 13

Rep: Reputation: 1
NO! NO! NO!

This does NOT belong in the rc files!

It belongs in /etc/sysconfig/network-scripts/route-{interface}

If you put it where it belongs, it will get executed when the interface is initialized, which is when it is supposed to happen.
 
Old 06-07-2011, 08:43 AM   #20
ngwasuma
Member
 
Registered: Jan 2005
Distribution: Fedora11
Posts: 45

Rep: Reputation: 16
Quote:
echo "/sbin/route add -net 192.168.1.0 netmask 255.255.255.0 gw 192.168.1.72" >> /etc/rc.local
That works for me perfectly and I can't change it for anything else

Last edited by ngwasuma; 06-07-2011 at 08:53 AM.
 
Old 06-08-2011, 07:51 AM   #21
mwburden
LQ Newbie
 
Registered: Aug 2009
Posts: 13

Rep: Reputation: 1
It will work only if you have just one network interface and if you don't change what that interface is connected to AND (and this is the big one!) no one else will ever need to try to figure out what you did.

If you put it in the right place, than the route will activate with the interface, and any admin that knows Linux will know where to find the static route you added in case it ever needs to be changed later.

I don't like to make assumptions about network topology that are likely to come back and bite someone in the hiney, and I've had my fill of dealing with systems where someone made the invalid assumption and left the mess for someone else (ie, me) to clean up.


If this is a personal machine at home, then fine... just keep in mind what you did if you change your network later.

If this is a work machine at the office, then you should really take the time to figure out how to do this correctly.

Last edited by mwburden; 06-08-2011 at 08:28 AM.
 
Old 06-28-2012, 08:05 AM   #22
elmohandesRagab
LQ Newbie
 
Registered: Dec 2010
Posts: 3

Rep: Reputation: 0
the right way to add/delete a permanent route

I have tested with fedora 16 to add a route to the /etc/sysconfig/network-scripts/route-{network interface}
and it worked perfectly.

note that if you add the route by using the Gnome network setting window, you will have the same result and the /etc/sysconfig/network-scripts/route-{network interface} will be created if it wasn't exist.
 
Old 09-06-2012, 05:14 AM   #23
auroraflame
LQ Newbie
 
Registered: Aug 2009
Posts: 3

Rep: Reputation: 0
thank you for the great discussion

googling on static routes and found some useful documentation, hopefully it will be useful for other.

https://www.centos.org/docs/5/html/5...ic-routes.html

Regards,
auroraflame
 
Old 02-25-2013, 10:11 AM   #24
prowla
Member
 
Registered: Feb 2011
Location: UK
Distribution: RHEL 5 & 6, Ubuntu 10
Posts: 93

Rep: Reputation: 3
If it's just the default gateway, you can add a GATEWAY statement in the ifcfg-eth<N> file.
 
Old 04-05-2013, 09:03 AM   #25
markyd
LQ Newbie
 
Registered: Dec 2011
Location: Shepperton - UK
Distribution: Lubuntu & Puppy ... mostly ;-)
Posts: 25
Blog Entries: 16

Rep: Reputation: Disabled
wow who would have thought adding a static route in Linux would be such a pain in the arse! I mostly use Debian based stuff I get a little out of my comfort zone with RH & CentOS but FreePBX runs on CentOS so I have to play on the dark side of the force ;-)

Reading the above I think at some stage all was true but things have moved on, I read the above, got confused and carried on reading http://www.softpanorama.net/Net/Netu...in_linux.shtml that article proved the most useful and what this post is based upon.

My system is CentOS which is a host for FreePBX and I need a static route pointing to a private internal network. The way that worked for me was to add a new file to /etc/sysconfig/network-scripts called route-eth0 ... here are the contents:
default 192.168.0.1 dev eth0
192.168.2.0/24 via 192.168.0.254 dev eth0
I know this thread is ancient but I found it when I need a hand and hope the above helps someone else.

MarkyD
 
Old 04-06-2013, 03:03 AM   #26
prowla
Member
 
Registered: Feb 2011
Location: UK
Distribution: RHEL 5 & 6, Ubuntu 10
Posts: 93

Rep: Reputation: 3
Of course, assuming that your ethN device doesn't change...
 
Old 04-08-2013, 04:07 AM   #27
prowla
Member
 
Registered: Feb 2011
Location: UK
Distribution: RHEL 5 & 6, Ubuntu 10
Posts: 93

Rep: Reputation: 3
Que?
 
Old 07-27-2015, 04:59 PM   #28
InterceptorF
LQ Newbie
 
Registered: Jun 2014
Location: Colorado
Distribution: Redhat, Wheezy and Ubuntu
Posts: 8

Rep: Reputation: Disabled
route-eth9

Here is what a /etc/sysconfig/network-scripts/route-eth8 file looks like using Stornext File System :

default via 17.218.184.174 dev eth8
17.218.184.179 via 17.218.184.174 dev eth8
17.111.120.5 via 17.218.184.1 dev eth8
17.111.120.133 via 17.218.184.1 dev eth8
17.218.184.172 via 17.218.184.174 dev eth8
17.111.120.6 via 17.218.184.1 dev eth8
17.111.120.134 via 17.218.184.1 dev eth8
17.218.184.173 via 17.218.184.174 dev eth8


Adding it here for comparison. Hopefully it helps get you what you are seeking .
 
  


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 02:44 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