CentOS 6 – Persistant Static Routes
I know how to use ‘ip’ to set up a static route, e.g.:
ip route add 192.168.128.0/17 via 40.53.24.3 dev eth0
But if you reboot or restart network, you loose this. Thus you have to make it persistant. I found:
http://www.cyberciti.biz/tips/configuring-static-routes-in-debian-or-red-hat-linux-systems.html
where it says to add to ifcfg-eth0:
192.168.128.0/17 via 40.53.24.3
But this did not work after the interface was restarted. So what is the proper to set up persistant static routes?
12 thoughts on - CentOS 6 – Persistant Static Routes
I have used this document [0] in the past and it worked for me, let me know if it works for you.
[0]
https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Deployment_Guide/sec-networkscripts-static-routes-network-netmask-directives.html
Create the file /etc/sysconfig/network-scripts/route-eth0
Add the following for each static route, incrementing the numeric for each:
ADDRESS02.168.128.0
NETMASK0%5.255.128.0
GATEWAY0@.53.24.3
Yes it did. Brings back some really old memories of doing this way some
10 years ago. Back when I built a firewall on CentOS4 with lots of ethernets and Shorewall and stuff.
thanks
That’s only for RHEL 7: http://goo.gl/AtjIyI
This is the scheme used in prior versions of RHEL.
Are you saying this should not work in RHEL/Cent 7? It works fine for me
in 5/6/7.
Aside from being irritating, that’s just wrong. I’m using that syntax on CentOS5,
I think both types of syntax will work in all versions. The GUI tools do the latter form.
—
Les Mikesell
lesmikesell@gmail.com
AH, I think I see what I did wrong. I put that line in the ifcfg-eth0
when according to this page, it goes in the route-eth0 just like the old format. I will give that a try tomorrow…
Yes, I missed that part. You can put a default gateway in the ifcfg-xxxx file with GATEWAY= but if you have more than one NIC you should only have one GATEWAY= entry for the NIC facing that router, and any routes in a route-xxx file should be through a router where the next hop specified is reachable though the xxx-named interface. The routes are added as the interfaces are brought up and will fail if the gateway specified isn’t reachable – as might happen if they need to go through an interface that isn’t up yet. If you only have one interface you don’t have to worry about that – the default GATEWAY=
can be in ifcfg-eth0 and the static route(s) through a different router on the same subnet go in route-eth0.
—
Les Mikesell
lesmikesell@gmail.com
servers to listen to RIP…
One leap at a time!
The usual quick-fix in a small network is to make your default router know about everything else. That is, your internet-facing router knows the route to your internal router – and vice versa. Then if you send to a single default and have a destination address that the other router on the same network should handle, it will forward the packet for you _and_ send you an icmp redirect telling you that it will save time if you send to the other router yourself. That way the computers don’t have to participate in real routing protocols.
Are you using NetworkManager? I think you have to specifically remove it although I am not quite sure when RH made it the default (nor am I sure if it would override routes, but it frequently seems to cause issues.)
Also, the article doesn’t say add the lineifcfg-eth0. The article says add it to route-eth0. Was that just a typo on your part?
No NetworkManager on these systems.
Misread on my part. My dyslexia at work (have to have something to blame!).