WhereAmI - ifPlugd - WIFI (WEP/WPA)

Version 1.0
Author: Clifford W. Hansen <iam [at] nighthawk [dot] co [dot] za>
Last edited 29/08/2007

This tutorial describes how to configure automatic network setup, based on where you are on a Debian Etch server. Whereami is a program that runs checks on your current interfaces to check which network you are on. ifplugd is a daemon that checks for a link on your network card. It can run programs on link up and down.

This document comes without warranty of any kind! I do not issue any guarantee that this will work for you!


1 Preliminary Note

I am using Debian 4.0r1, and therefore the commands below will be for a Debian based system. In this tutorial I use the networks example.com (work) and flat.lan (home). These settings might differ for you, so you have to replace them where appropriate. I run all commands with sudo. If you don't use sudo then you will need to become root.

You should have all your interfaces setup and working, this includes wireless.


2 Installing applications

Open a terminal and run:

sudo apt-get install ifplugd whereami wireless-tools fping resolvconf

You will be asked a couple of questions:

  • static interfaces to be watched by ifplugd: <-- eth0
  • All the others I left as default.


3 Configuring


ifplugd was set up when the package was installed and there is nothing you need to do.



Whereami has two config files that are of importance: /etc/whereami/detect.conf and /etc/whereami/whereami.conf.

First let's set up the location detection: /etc/whereami/detect.conf:

# It is a good idea to default to somewhere...
default     undocked
# Test for the presence of an ethernet connection plugged into eth0
testmii     eth0          lan
# Get a list of the access points that we can see
testap      wlan0,scan    wlan
if lan
  # If the testmii at the top was successful
  set INTERFACE eth0
  testdhcp    '*.*.*.*'    dhcp
elif wlan
  # If we found an accesspoint
  set INTERFACE wlan0
  testap    "flat ap"      flat
  testap    "example ap"   example
  always at undocked
if dhcp
  testdhcp    192.168.1.*      flat
  testdhcp    10.0.0.*         example

Firstly what this does is test for a network link on eth0 and set the location to lan (if the cable is plugged in). Then we check for an available access point and set the location to wlan (if there is an accesspoint).

If we are in the lan, then test for dhcp, which then tests to see if our IP is in one of the recognised ranges (flat/example).

If we find one of the recognised access points then set the location based on what was found.

Now that detection has been set up we can move on to the setup. This is in /etc/whereami/whereami.conf.

## This only happens if we are not at a WLAN
!wlan ifconfig wlan0 down
!wlan resolvconf -d wlan0
## This only happens if we are not at a LAN
!lan ifconfig eth1 down
!lan resolvconf -d eth1
## Setup wlan connections
!wlan if /bin/false; then
=any iwconfig wlan0 mode managed
=any ifconfig wlan0 up
## example
=example iwconfig wlan0 essid "example ap"
=example iwconfig wlan0 key <wep key>
## flat
=flat iwpriv wlan0 set AuthMode=WPAPSK
=flat iwpriv wlan0 set EncrypType=TKIP
=flat iwconfig wlan0 essid "flat"
=flat iwpriv wlan0 set WPAPSK=<wpa key>
=flat iwconfig wlan0 essid "flat"
## Get IP from dhcp
=any dhclient wlan0
!wlan fi

The fist thing we do is bring down the interfaces that are not being used.

Then we check if we are using wlan and then set up the wireless connections.

Example is using WEP, so you will need to replace <wep key> with your actual key.

flat is using WPA, so to get your WPA key you would run:

wpa_passphrase flat mywpakey

This will give you:


Then replace <wpa key> with the value of psk.

Assuming everything is set up and correct, run:

sudo /usr/sbin/whereami

And your networking should be configured.

You can test this with:

sudo /sbin/ifconfig

You should see something similar to:

eth0      Link encap:Ethernet  HWaddr 00:00:00:00:00:00
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)
          Interrupt:209 Base address:0xc000
lo        Link encap:Local Loopback
          inet addr:  Mask:
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)
wlan0     Link encap:Ethernet  HWaddr 00:00:00:00:00:00
          inet addr:  Bcast:  Mask:
          inet6 addr: fe80::214:85ff:feda:716d/64 Scope:Link
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)


4 Conclusion

This is not the only way to do this, also I know that there is a new application (network-manager) which basically does this for you, but unfortunatly my wireless card's (RaLink) drivers are not compatible with network-manager.

Also whilst writing this howto I saw a couple of other ways to do this using these tools, but this was the easiest.

I hope this helps someone out there, as I know it took me a while to figure this out, google is your friend, but sometimes it gives you the wrong stuff (or incomplete at least ;)...

Share this page:

0 Comment(s)

Add comment