[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Linux (both 2.0.x and 2.2.x), ifconfig, and routing tables.



Okay, I've asked on comp.os.linux.networking, figured I'd ask here too
since I've seen similar topics come up.

I've discovered some differences between Linux's handling of the
routing table from other Unix and Unix-style OS's, and was wondering
if anyone could shed some light on things.

I have a program I am working on (high availability/failover stuff),
that as part of it's operation does the following steps:

1. Brings down an interface with 'ifconfig interfacename down'.
2. Depending on circumstances, either brings the interface up with an
   'ifconfig interfacename up', or changes it's IP address and then
   brings it back up with 'ifconfig interfacename up'.

The problem I've run into is that whenever I do an 'ifconfig
interfacename down', the kernel automagically removes all the routing
table entries for that interface.  If I bring the interface back up
with 'ifconfig interfacename up', I also have to run a bunch of route
commands to restore the routing table.

So the problem I have is that I need a way to either:

1. Get the kernel to leave the routing table intact when the interface
   is brought down, or...
2. Find a way to save all the routing table entries involving the
   interface I'm bringing down, and restore them after bringing the
   interface back up?

Anyone know how do do either of these?

On every other Unix OS I've worked, an 'ifconfig interfacename down'
followed by an 'ifconfig interfacename up' restores things to their
initial state, and never changes the routing table.

For example, on one of my old SunOS boxes (with addresses remove to
protect the innocent):

# ifconfig -a
le0: flags=63<UP,BROADCAST,NOTRAILERS,RUNNING>
        inet xx.xx.xx.xx netmask ffffff00 broadcast xx.xx.xx.xx
        ether xx:xx:xx:xx:xx:xx
lo0: flags=49<UP,LOOPBACK,RUNNING>
        inet 127.0.0.1 netmask ff000000

# netstat -r
Routing tables
Destination          Gateway              Flags    Refcnt Use        Interface
localhost            localhost            UH       16     562235     lo0
134.84.106.0         host-le0             U        3      50520      le0

# ifconfig le0 down
# ifconfig -a
lo0: flags=49<UP,LOOPBACK,RUNNING>
        inet 127.0.0.1 netmask ff000000

# netstat -r
Routing tables
Destination          Gateway              Flags    Refcnt Use        Interface
localhost            localhost            UH       16     562235     lo0


So as you can see, the routing table is completely unaffected by the
'ifconfig' commands.

On linux (with 2.0.x kernel), I get the follwoing

# ifconfig -a
eth0      Link encap:Ethernet  HWaddr xx:xx:xx:xx:xx:xx
          inet addr:xx.xx.xx.xx  Bcast:xx.xx.xx.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:3691642 errors:0 dropped:0 overruns:0 frame:0
          TX packets:3679365 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:100

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:3924  Metric:1
          RX packets:11495 errors:0 dropped:0 overruns:0 frame:0
          TX packets:11495 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0

# netstat -r
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
localnet        *               255.255.255.0   U         0 0          0 eth0
default         tc8x.router.umn 0.0.0.0         UG        0 0          0 eth0

# ifconifg eth0 down

# netstat -r
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface


As you can see, the ifconfig command is removing my route table entries.
Similar results are seen with the 2.2.x kernel, except the kernel
automagically handles the localnet entry when I bring the device back up.

Ideas?



-- 
Richard W Kaszeta 			PhD. Candidate and Sysadmin
bofh@me.umn.edu				University of MN, ME Dept
http://www.menet.umn.edu/~kaszeta


Reply to: