Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Having read "two gateways / two providers with different ips", and the Clinton East article that it links to, I have successfully set up a multi-homed RHEL5 system. However, I am hoping for a better way to preserve this state than by calling the ip rule and ip route commands from rc.local. Is there a configuration file that I could edit that would get read as the interfaces come up? Something like iptables-save and iptables-restore perhaps?

share|improve this question
    
My related question: serverfault.com/questions/2986/linux-tc-policy-routing-tools –  Zoredache Sep 15 '09 at 19:49
add comment

2 Answers

up vote 0 down vote accepted

In RHEL, there's two places where these things should probably go.

For adding static routes in RHEL, you add them to /etc/sysconfig/network-scripts/route-INTERFACE where INTERFACE matches the name of the ifcfg-INTERFACE entries. The statements in the route-* files will be passed to ip route add and ip route del when the interface is brought up or down.

Now, for the ip rule commands, the best place I can think of would probably be in /sbin/ifup-local. If this file exists, it gets run after an interface is brought up. One note with this one, if /sbin/ifup-local exists, it will get called as an executable and passed an argument of the interface name. So you'll have to write handler code to check that argument against the interfaces you want to add configs for and then take the appropriate action.

As an example:

#/bin/bash

case $1 in
  eth0)
    /sbin/ip rule foo
    /sbin/ip rule bar
    ;;
  eth1)
    /sbin/ip rule baz
    /sbin/ip rule quux
    ;;
  *)
    /usr/bin/logger -t 'ifup-local' 'Called with unknown interface:  $1'
    ;;
esac

If you wanted to, you could include the ip route rules for each interface in ifup-local, too. If you wanted to remove the corresponding rules when an interface is downed, you could create a similar /sbin/ifdown-local script to handle that.

If it were me, even though RHEL provides a standardized way of handling static routes, I'd probably do everything in ifup-local and ifdown-local, just to keep all my interface specific bits together.

share|improve this answer
add comment

RedHat: I don't have any boxes on hand to check, but there should be something like a /etc/sysconfig/network/routes file in which to configure static routes.

SuSE:

$ cat /etc/sysconfig/network/ifroute-eth-id-MAC:
#NETWORK/MASK GATEWAY_IP
192.168.100.0/24 192.168.1.1

Debian:

$ cat /etc/network/interfaces
auto eth0
iface eth0 inet static
address 192.168.1.2
netmask 255.255.255.0
gateway 192.168.1.1
up ip route add 192.168.100.0/24 via 192.168.1.1
down ip route del 192.168.100.0/24 via 192.168.1.1
share|improve this answer
add comment

Your Answer

 
discard

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