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

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



On Tue, Sep 21, 1999 at 06:44:43PM -0500, Richard Kaszeta wrote
> 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.
> 

Reading the output you posted, I see all routes which refer
to the downed interface disappear; this is also what
happens with Linux. The visible difference seems to be
mainly that SunOS lists a route for the configured IP on
each interface (thus, it shows a route for localhost via
lo0 even after le0 is downed), whereas Linux does not
(thus, there are no routes after eth0 is downed).  This
difference should have no actual effect on routing
behaviour.

>[balance snipped]

John P.
-- 
huiac@camtech.net.au
john@huiac.apana.org.au
"Oh - I - you know - my job is to fear everything." - Bill Gates in Denmark


Reply to: