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

network hopping tricks: an unsolicited plug for ifupdown-roaming

Hi, all.

There's been a lot of discussion on this list about tools to
detect which network a laptop is connected to and configure
various things.

I've tried several, and I think I advocated whereami to
someone at some point, but it seems Thomas Hood's
ifupdown-roaming is the best so far!  His solution has the 
configuration reside entirely in /etc/networks/interfaces.
And in many instances needs almost no configuration at all.

For example, for at one site, I had:

iface eth0-site1 inet static

With ifupdown-roaming, I now have:

iface eth0-site1 inet static

Huh?  Looks the same it me?  It is!  The genius here is that
the mention of a gateway gives the detection program (ifscout)
a way to identify that I'm at site1.  It can ping the gateway.  
If I visit more than one simlar network (10.n.n.n is common 
for some reason ;-) ), I can add a mention of a peer that 
should be on said network, with or without an mac addr.

iface eth0-site1 inet static
        peer 0B:E0:18:99:1E:8A

Without a mac address, ifscout pings the peer.

With a mac address, ifscout arpings the peer and checks its
mac addr.

It's very cool.  The config file (interfaces) describes the
networks we can connect to, and lets the tool choose the
right mechanism to uniquely identify the network from the
data provided.

Want to have something run when the network comes up?  Stuff
in if-up.d and if-down.d runs regardless of net or
interface.  But put an "up" or "down" line in your interfaces 
file, and you can be appropriate to the place.  For example, 
at work I might need galeon to run with a proxy.  So I add:

        up su - tony -c "gconftool --set /apps/galeon/Advanced/Network/proxy_mode -t int 1"

And now galeon knows that at site1 it should use its proxy
config.  At a home, I set proxy_mode to zero.

As Einstein said, make things as simple as possible, but no
simpler.  And I can't imagine any simpler solution that would 
actually work.  Thanks Mr. Hood.  

His announcement follows.

On Wed, Jan 29, 2003 at 06:26:02AM +0100, Thomas Hood wrote:
> Abstract: Debian does not contain an adequate automagical
> network configurer at present.  So I have begun writing
> one and have packaged it as "iupdown-roaming".  Try it out!
> ========================================================
> I have been looking for software that will automagically
> configure network interfaces with as little user intervention
> as possible, and with as little need for configuration as 
> possible.  The following packages already exist in Debian.
> (If there are any others, please let me know.)
>     * ifupdown: Configure or deconfigure network
>          (These are the standard Debian tools for
>          configuring and deconfiguring a network
>          interface.)
>     * netenv: At boot time, set environment variables to 
>          manually selected values.  This can be used
>          to switch between network configurations.
>     * switchconf: Manually select configuration files.
>          This can be used to switch between network
>          configurations.
>     * divine: (replaced by intuitively)
>     * intuitively: Select network configuration for 
>          current environment
>     * laptop-netconf: Select network configuration for 
>          current environment
>     * ifplugd: Continually enable or disable Ethernet 
>          interface according to presence of link beat
>     * laptop-net: Continually select network configuration 
>          for current environment
>     * whereami: On boot, APM event, pcmcia event, or 
>          execution, clock state machine. Tests and actions
>          are furnished that are useful for testing current
>          environment and for configuring the network
>     * guessnet: Report current network environment.  This
>          can be used as an ifupdown "mapping" script to
>          select configuration for current environment.
> ifupdown does not work correctly if other utilities 
> independently futz with network configuration.  Therefore, 
> any adequate solution must be one that either replaces 
> ifupdown entirely or else cooperates with it somehow. 
> intuitively and laptop-netconf are network configuration 
> switchers that automatically select the right configuration 
> for the current environment by scouting for hosts on the 
> network (using tools such as ping and arping).  ifplugd is 
> a daemon that monitors an Ethernet interface for link beat 
> starting or ending and runs scripts.  This can be used to 
> run one of the preceding utilities or ifup/ifdown.  With 
> further hook scripts inserted in /etc/init.d and /etc/rc*.d 
> and in /etc/apm/event.d to run the configurer on bootup and 
> on APM events, this would add up to a fairly well automated 
> configurer.  To make this work with the PCMCIA subsystem, 
> one would replace the default start_fn() and stop_fn() in 
> /etc/pcmcia/network.opts (which call ifup and ifdown) with 
> calls to the configurer.  laptop-net is like laptop-netconf 
> plus ifplugd combined with well written documentation in a 
> well thought out package.  Unfortunately, none of the above 
> cooperates with ifupdown.  whereami is also flawed in that 
> respect, and, although it is highly configurable, it is
> more of a toolkit than an application.  It requires a lot 
> of configuration and its hooks haven't been thought out 
> properly.  To make this work with the PCMCIA subsystem, 
> one would delete the default start_fn() and stop_fn() in 
> /etc/pcmcia/network.opts (which call ifup and ifdown) and 
> set WHEREAMI=y.  guessnet, on the other hand, is designed 
> to integrate into ifupdown: it is a script that "maps" the 
> specified "physical interface" to the first "logical
> interface that it finds by scouting around.  When using
> guessnet, ifplugd and boot and APM hook scripts can be
> configured to run ifdown and ifup, which calls guessnet.
> The disadvantage of guessnet is that it is not very 
> configurable. 
> I think it is possible to make something better than 
> guessnet, so I have started work on a package of utilities
> that will provide more fully automatic network configuration
> by cooperating with ifupdown.  I have cooked up a package
> called "ifupdown-roaming".  Its key component is a script
> called "ifscout".  Like guessnet, ifscout is a mapping
> script for ifupdown.  Unlike guessnet, ifscout uses
> ifupdown's /etc/network/interfaces file to store all its
> configuration information.  This makes ifscout easier to
> set up.
> To see how it works, let us define two logical interfaces,
> "home" and "work", for eth0.  /etc/network/interfaces might
> look something like the following. 
>     auto lo
>     iface lo inet loopback
>     mapping eth0
>        script /usr/local/sbin/ifscout
>        map office home
>     iface home inet static
>        address
>        netmask
>        gateway
>        up cp -a /an/important/file /my/backup/directory
>        up set-mail-relay
>        down set-mail-relay queue
>        up set-named-forwarders
>     iface office inet dhcp
>        up set-mail-relay
>        down set-mail-relay queue
> Note that ifscout is named as the mapping script for eth0
> and the office and home logical interfaces are listed on
> the following "map" line.  This means that when "ifup eth0"
> is executed, ifscout will first try the "office"
> configuration (by attempting to obtain a dhcp lease) then
> the "home" configuration (by setting the indicated address
> and netmask and trying to ping the gateway).  It returns
> the name of the first logical interface it detects, and
> ifup proceeds to configure that using the appropriate
> values and to run the appropriate "up" scripts.
> (The set-mail-relay and set-named-forwarders scripts are
> cribbed from the whereami package.)  The scouting procedure
> for a statically configured logical interface can be
> modified by adding lines like these: 
>        peer ma:ca:dd:re:ss
> which will make ifscout ping instead of the 
> gateway and will compare the MAC address it reports (in
> response to an ARP request) with ma:ca:dd:re:ss.
> Alternatively, an arbitrary test script can be specified
> for any logical interface:
>        test mycustomscript --option1=val2
> Whatever is specified here should return success (status 0) 
> if this logical interface is to be used; otherwise failure. 
> There is no limit to the number of logical interfaces that
> can be specified.  Thus, a /etc/network/interfaces file for
> a system that roams more networks might look like this:
>     auto lo
>     #pm-auto eth0
>     iface lo inet loopback
>     mapping eth0
>        script /usr/local/sbin/ifscout
>        map office0 office1 home
>     mapping eth1
>        script /usr/local/sbin/ifscout
>        map office2 bruces
>     iface home inet static
>        address
>        netmask
>        gateway
>        peer 03:a3:93:02:93:18
>        up cp -a /an/important/file /my/backup/directory
>        up set-mail-relay
>        down set-mail-relay queue
>        up set-named-forwarders
>     iface bruces inet static
>        address
>        netmask
>        gateway
>        test /usr/local/sbin/niftyscript --option1=3
>     iface office0 inet dhcp
>        up set-mail-relay
>        down set-mail-relay queue
>     iface office1 inet dhcp
>        test mycustomscript --option1=val2
>        up set-mail-relay
>        down set-mail-relay queue
>     iface office2 inet static
>        address
>        netmask
>        gateway
>        up set-named-forwarders
>        up set-mail-relay
>        down set-mail-relay queue
> With such a setup one's interface will be reconfigured every
> time it is upped with ifup.  To increase automation, one
> wants ifup to be run on events such as (1) boot, (2) APM
> resume, (3) PCMCIA network card insertion, (4) restoration
> of Ethernet cable, etc.  
> (1) ifup is already run at boot time by /etc/init.d/ifupdown.
> (2) The ifupdown-roaming package includes a hook script in
> /etc/apm/event.d which downs interfaces before suspend and
> ups them again on resume.  The line beginning with
> "#pm-auto" in /etc/network/interfaces names the physical
> interfaces to which this should be done.  (For now this
> keyword has to start with a "#" so that ifup and ifdown
> won't gag on it.)  (3) The default settings in
> /etc/pcmcia/network.opts will cause the inserted interface
> to be configured by ifup and deconfigured by ifdown.
> Be sure not to set any of WHEREAMI, DHCLIENT, PUMP, BOOTP
> or DHCP to "y".  (4) This package can be used with the
> ifplugd package.  The ifplugd daemon will call ifup when
> the Ethernet adapter detects a link beat (presence of
> active network cable) and ifdown when the link beat
> disappears (cable disconnected).  Note that ifplugd uses
> its own configuration files: set INTERFACES=eth0 in
> /etc/ifplugd/ifplugd.conf to monitor eth0, and make sure
> that /etc/ifplugd/ifplugd.action is set up to call ifup
> and ifdown.  For interfaces on PCMCIA cards, ifplugd
> should not call ifup or ifdown directly but should signal
> cardmgr by means of such commands as "cardctl suspend";
> cardmgr will in turn run ifup or ifdown as appropriate
> (if the pcmcia-cs package is set up correctly, natch).
> Current Linux kernels run the hot-plugging script
> /sbin/hotplug when a network card is hot-plugged.  The
> current default configuration of the hotplug package will
> cause ifup to be called whenever a new network card is
> found.  This happens even if the card is a PCMCIA card.
> Since this duplicates what the pcmcia-cs package already
> does, this part of hotplug had better be disabled.  If
> required, edit /etc/hotplug/net.agent to delete the calls
> to ifup and ifdown.
> Also, do not install whereami; or if you do install it,
> remove the file /etc/network/if-pre-up.d/whereami
> which is a brain-damaged attempt to hook whereami into
> ifup, even though it is not compatible with ifup.
> Also make sure that whereami is not called at boot or
> on APM events.  If you want to make use of the nifty
> scripts in the whereami package then the safest thing to
> do is install the package, copy the scripts and then
> purge the package.
> I would like to know which scripts from other packages
> (whereami, etc.) you would like to see included in
> ifupdown-roaming.  This includes both custom detection
> scripts and action scripts such as set-named-forwarders
> and set-mail-relay.
> ifupdown-roaming is little more than a proof of concept
> at the moment, even though it Works For Me (tm).  The
> ifscout script parses /etc/network/interfaces and isn't
> won't be very tolerant of non-standard formatting at
> present.  You are welcome to try it by downloading the deb:
>   http://panopticon.csustan.edu/thood/ifupdown-roaming.html
> provided you forgive me for the abominable awk script in
> ifscout and resolve to send me all and only constructive
> criticisms (which could includes the criticism "This was
> a big waste of time, because yadda yadda yadda.").
> --
> Thomas Hood
> jdthood@yahoo.co.uk
> __________________________________________________
> Do You Yahoo!?
> Everything you'll ever need on one web page
> from News and Sport to Email and Music Charts
> http://uk.my.yahoo.com
> -- 
> To UNSUBSCRIBE, email to debian-laptop-request@lists.debian.org
> with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org

Reply to: