WhereAmI - ifPlugd - WIFI (WEP/WPA)
WhereAmI - ifPlugd - WIFI (WEP/WPA)
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:
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 else always at undocked fi if dhcp testdhcp 192.168.1.* flat testdhcp 10.0.0.* example fi
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:
And your networking should be configured.
You can test this with:
You should see something similar to:
eth0 Link encap:Ethernet HWaddr 00:00:00:00:00:00
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 ;)...