Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

On CentOS 5 I manually added a static route to make all packets to one specific IP address use the second network interface:

ip route add 123.456.7.89/32 via 192.168.10.101 dev eth1

Is there a way to make this change be persistent on reboot without adding it to the startup script /etc/rc.d/rc.local?

share|improve this question

migrated from stackoverflow.com Feb 1 '10 at 13:13

This question came from our site for professional and enthusiast programmers.

Yes. Add the line:

123.456.7.89/32 via 192.168.10.101 dev eth1

to /etc/sysconfig/netowrk-scripts/route-eth1 as shown here.

share|improve this answer
    
thanks, much appreciated. I did a lot of googling but it seems I skip this one, way too many tabs opened :) – Dragos Feb 1 '10 at 13:09

While this answer works, the current preferred format for /etc/sysconfig/network-scripts/route-ethX is:

GATEWAY0=10.156.196.1
NETMASK0=255.255.254.0
ADDRESS0=10.156.248.0
GATEWAY1=10.156.196.1
NETMASK1=255.255.254.0
ADDRESS1=10.156.244.0

Be sure to increment the value of the numeral when you add a route.

Unfortunately, the new preferred format of GATEWAYX:/ADDRESSx:/NETMASKx:/ makes it harder to programmatically add static routes via the older format of 192.168.1.0/24 via 10.1.1.1. It can be worked around, but adds unnecessary complications to scripting routes.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.