[KLUG Members] routing

Adam Williams members@kalamazoolinux.org
22 Jul 2002 18:33:05 -0400


>>Everytime my machine boots, I have to manually delete my default route
>>and create the correct one.  I can add more in the netconf, but I don't
>>see a place to drop routes.  
>Shouldn't be a problem, you never need to reboot Linux!  :-)
>If your running Redhat (if not, see above), the default route is kept in
>the text file /etc/sysconfig/network .   Other routes are kept somewhere
>in that directory, or in a subdirectory underneath it (forget which
> filename, but should be easy to find with grep).

/etc/sysconfig/static-routes.  It has a format like -
eth0 net 192.168.4.0 netmask 255.255.255.0 gw 192.168.3.1

So when eth0 goes UP the route is added.  When eth0 goes DOWN all routes
associated with it are automatically removed by the stack (kernel). 
This is handled by the script "ifup-routes" that is called by
"ifup-post" which is the last thing called by the script "ifup"  All
these scripts live in /etc/sysconfig/network-scripts

The above works pretty good when interfaces are tightly coupled to
physical devices. 

But with loosely couple interfaces like ppp0 that can be attached to one
network in one instance and be ppp1 next time the system is attached to
that network is it easier to use the ipparam provided by ppppd.  Thus a
peer file (/etc/ppp/peers) associated with a particular network passes a
parameter to the /etc/ppp/ip-up script that in turn passes it to
ip-up.local where you can put anything you want.

So I can "pppd call morrison-vpn" so pppd reads the
/etc/ppp/peers/morrison-vpn config file which contains the "ipparam
morrison-vpn" options.  Then ip-up.local receives "morrison-vpn" as its
6th parameter and adds a whole pile of routes.    ip-up doesn't get
called until if/when the ppp connection is established.  It also
receives the interface name (ppp0, ppp1, etc...) as its first
parameter.  

/etc/ppp/ip-up.local -
#!/bin/sh

case $6 in
   morrison-vpn)
        /sbin/route add -net 192.168.1.0 netmask 255.255.255.0 dev $1
        /sbin/route add -net 192.168.10.0 netmask 255.255.255.0 dev $1
        /sbin/route add -net 192.168.11.0 netmask 255.255.255.0 dev $1
        /sbin/route add -net 192.168.12.0 netmask 255.255.255.0 dev $1
        /sbin/route add -net 192.168.13.0 netmask 255.255.255.0 dev $1
        /sbin/route add -net 192.168.14.0 netmask 255.255.255.0 dev $1
        /sbin/route add -net 192.168.15.0 netmask 255.255.255.0 dev $1
        /sbin/route add -net 192.168.16.0 netmask 255.255.255.0 dev $1
        /sbin/route add -net 192.168.17.0 netmask 255.255.255.0 dev $1
        /sbin/route add -net 192.168.18.0 netmask 255.255.255.0 dev $1
        /sbin/route add -net 192.168.19.0 netmask 255.255.255.0 dev $1
        /sbin/route add -net 192.168.20.0 netmask 255.255.255.0 dev $1
        /sbin/route add -net 192.168.21.0 netmask 255.255.255.0 dev $1
        /sbin/route add -net 192.168.22.0 netmask 255.255.255.0 dev $1
        /sbin/route add -net 192.168.23.0 netmask 255.255.255.0 dev $1
        /sbin/route add -net 192.168.24.0 netmask 255.255.255.0 dev $1
        /sbin/route add -net 192.168.25.0 netmask 255.255.255.0 dev $1
        /sbin/route add -net 192.168.26.0 netmask 255.255.255.0 dev $1
     ;;
    wm-india)
   . . . 
     ;;
  . . .
esac