Wireless profiles

Kenton Brede kbrede at nixnotes.org
Wed Apr 6 02:19:09 UTC 2005


On Tue, Apr 05, 2005 at 05:56:21PM -0400, Zach (uid000 at gmail.com) wrote:
> Kent,
> 
> More details, please.  Sounds like what you're doing really rocks. 
> I'm especially interested in the ifplugd doohickey.  Sounds like a
> daemon that detects media presence on your eth0, then fires off some
> script to ifdown eth1, ifup eth0, or something like that.  I'd like to
> know more.

OK first off, a disclaimer.  This is a hack, use at your own risk.  I
hope it isn't a complete faux pas.  There is probably a better way to 
do the following but for the time being this meets my needs.  Perhaps 
someone will share a better solution.

My situation:  Wireless network with WEP at home as well as wired.  Work
network with wireless (no WEP) and wired.  I want only one network interface 
live at a time.  Our wireless network at work is a separate subnet from
the wired so both interfaces could play nice with each other, but for security 
reasons I see no reason to run more than one interface at a time.  At home both 
wireless and wired are served from the same network so the routes
conflict, if both interfaces are live.  My laptop has both built in wireless 
and wired network cards.  eth0 is my wired interface, eth1 is my wireless.

For debugging purposes in /etc/default/rcS change VERBOSE=no to yes.
# Set VERBOSE to "no" if you would like a more quiet bootup.
VERBOSE=yes

First I comment out all lines in /etc/network/interfaces and created 
three files in /etc/network/ their names and contents are as follows -

/etc/network/eth0-interface
auto lo
iface lo inet loopback

auto eth0
    iface eth0 inet dhcp


/etc/network/eth1-home
auto lo
iface lo inet loopback

auto eth1
iface eth1 inet dhcp
    wireless-key xxxxxxxxxx 
    wireless-essid MySID
    wireless-mode managed

/etc/network/eth1-public
auto lo
iface lo inet loopback

auto eth1
iface eth1 inet dhcp
    wireless-mode managed

Next I backed up /etc/init.d/networking file and added the following
function, just after the line sourcing "init-functions."

function ss_wireless () {
AP=`/sbin/iwlist eth1 scan | /bin/grep "ESSID:\"MySID\"" | /usr/bin/awk -F \" '{print $2}'`
    if [ "$AP" = "MySID" ]; then
        /sbin/$1 -i /etc/network/eth1-home -a
    else
        /sbin/$1 -i /etc/network/eth1-public -a
    fi
}

Next, in the same file I commented out all ifup and ifdown lines
replacing them with the function ss_wireless with one of the following
combinations -

#ifup -a
ss_wireless ifup

#ifup -a >/dev/null 2>&1
ss_wireless ifup >/dev/null 2>&1

#ifdown -a
ss_wireless ifdown

#ifdown -a >/dev/null 2>&1
ss_wireless ifdown >/dev/null 2>&1

At this point you should be able to - 
/etc/init.d/networking stop|start
and wireless should work.

To set up the wired interface I installed ifplugd.

The daemon defaults to eth0 but I explicitly stated it in the config
file /etc/default/ifplugd
INTERFACES="eth0"

I modified /etc/ifplugd/action.d/ifupdown in the following manner -

-------------------------------------------------------------------
#!/bin/sh
set -e

function ss_wireless () {
AP=`/sbin/iwlist eth1 scan | /bin/grep "ESSID:\"MySID\"" | /usr/bin/awk -F \" '{print $2}'`
    if [ "$AP" = "MySID" ]; then
        /sbin/$1 -i /etc/network/eth1-home -a
    else
        /sbin/$1 -i /etc/network/eth1-public -a
    fi
}

case "$2" in
up)
    ss_wireless ifdown
    /sbin/ifup -i /etc/network/eth0-interface -a
    ;;
down)
    /sbin/ifdown -i /etc/network/eth0-interface -a
    ss_wireless ifup
    ;;
esac
-------------------------------------------------------------------

I think that is about it.  I hope I didn't forget something.  One thing
I don't like about it, is if ifplugd is activated at boot and no network
cable is plugged in, it hangs forever trying to grab an IP.  For the
time being I've removed ifplugd from the boot sequence but that means I
have to run /etc/init.d/ifplugd after bootup to activate eth0 for wired.
Expect a few seconds between unplugging and plugging the network cable
in before the interfaces are active/inactive.  

Kent

-- 
"Our lives begin to end the day we become silent about things that matter."
  - Martin Luther King Jr.





More information about the ubuntu-users mailing list