LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (https://www.linuxquestions.org/questions/linux-networking-3/)
-   -   permanently add static route (https://www.linuxquestions.org/questions/linux-networking-3/permanently-add-static-route-16769/)

mwburden 07-01-2010 01:43 PM

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.)

dantux 10-02-2010 03:31 AM

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

ngwasuma 06-06-2011 01:04 PM

add it to /etc/rc.local
 
Ad your commandline to /etc/rc.local and it be run each time the computer starts

mwburden 06-07-2011 08:19 AM

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.

ngwasuma 06-07-2011 08:43 AM

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

mwburden 06-08-2011 07:51 AM

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.

elmohandesRagab 06-28-2012 08:05 AM

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.

auroraflame 09-06-2012 05:14 AM

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

prowla 02-25-2013 10:11 AM

If it's just the default gateway, you can add a GATEWAY statement in the ifcfg-eth<N> file.

markyd 04-05-2013 09:03 AM

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

prowla 04-06-2013 03:03 AM

Of course, assuming that your ethN device doesn't change...

prowla 04-08-2013 04:07 AM

Que?

InterceptorF 07-27-2015 04:59 PM

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 .


All times are GMT -5. The time now is 01:25 AM.