I keep moving between various work/home locations and [sub-]networks where I use wired or wireless access.
- Two wired networks at work where I have a static IP address assigned.
- There are a few other subnets at work where I can get a DHCP lease.
- A wireless network at work which I use in case I am in a meeting room.
- My tiny wired / wireless network at home with three machines.
- Other arbitrary locations where I can find a wireless access point.
I use guessnet, ifplugd, waproamd and resolvconf in Debian to handle this diversity rather nicely after a one time configuration.
As soon as a I power-on my laptop or plug-in my laptop somewhere,
ifplugd detects the link pulse if any on the ethernet and
waproamd configures the appropriate WEP keys according to wireless networks found. It is
guessnet that performs some tests in parallel and parks me to the first found configuration.
resolvconf manages /etc/resolv.conf based on the directives in the network configuration. All these play neatly with each other. Fantabulous!
[majuli ~]
[majuli ~]$ sudo apt-get install guessnet ifplugd waproamd resolvconf
[majuli ~]
[majuli ~]$ cat /etc/network/interfaces
auto lo
iface lo inet loopback
auto eth0
mapping eth?
script /usr/sbin/get-mac-address.sh
map 00:11:25:D5:35:A0 wired
map 00:12:F0:E9:82:9E wireless
mapping wired
script guessnet-ifupdown
map eth-home-static
map eth-home-dhcp
map eth-work-static8
map eth-work-static11
map default: eth-work-dhcp
map timeout: 9
map verbose: true
# Static / DHCP profiles for home LAN
iface eth-home-static inet static
address 192.168.1.3
netmask 255.255.255.0
gateway 192.168.1.1
dns-nameservers 61.1.96.69 61.1.96.71 61.1.128.65 61.1.128.5
test1 peer address 192.168.1.1 mac 00:0F:A3:1F:82:AC source 192.168.1.3
test2 peer address 192.168.1.2 mac 00:05:5D:4A:55:FD source 192.168.1.3
iface eth-home-dhcp inet dhcp
dns-nameservers 61.1.96.69 61.1.96.71 61.1.128.65 61.1.128.5
test1 peer address 192.168.1.1 mac 00:0f:A3:1F:82:AC source 192.168.1.3
test2 peer address 192.168.1.2 mac 00:05:5D:4A:55:FD source 192.168.1.3
# Two possible subnets at work (Desktop LAN/Lab LAN) where I have a static IP
iface eth-work-static8 inet static
address 10.72.8.42
netmask 255.255.255.0
gateway 10.72.8.1
dns-search lan.work.com lab.work.com wan.work.com corp.work.com
dns-nameservers 10.72.128.21 10.72.144.21 10.10.20.241 10.72.6.14
test peer address 10.72.8.1 mac 00:00:0C:07:AC:65 source 10.72.8.42
iface eth-work-static11 inet static
address 10.72.11.45
netmask 255.255.255.0
gateway 10.72.11.1
dns-search lan.work.com lab.work.com wan.work.com corp.work.com
dns-nameservers 10.72.128.21 10.72.144.21 10.10.20.241 10.72.6.14
test peer address 10.72.11.1 mac 00:00:0C:07:AC:67 source 10.72.11.45
# DHCP lease in case I am on some other subnet at work
iface eth-work-dhcp inet dhcp
dns-search lan.work.com lab.work.com wan.work.com corp.work.com
dns-nameservers 10.72.128.21 10.72.144.21 10.10.20.241 10.72.6.14
test1 peer address 10.72.9.1 mac 00:00:0C:07:AC:68 source 10.72.9.42
test2 peer address 10.72.10.1 mac 00:00:0C:07:AC:69 source 10.72.10.45
mapping wireless
script guessnet-ifupdown
map wlan-home-static
map wlan-home-dhcp
map wlan-work-dhcp
map default: wlan-dhcp
map timeout: 9
map verbose: true
# Static / DHCP profiles for home wireless network
iface wlan-home-static inet static
address 192.168.1.4
netmask 255.255.255.0
gateway 192.168.1.1
dns-nameservers 61.1.96.69 61.1.96.71 61.1.128.65 61.1.128.5
test wireless essid essidhome
iface wlan-home-dhcp inet dhcp
dns-nameservers 61.1.96.69 61.1.96.71 61.1.128.65 61.1.128.5
test wireless essid essidhome
# Work wireless network doesn't have a public essid to test against
iface wlan-work-dhcp inet dhcp
wireless-essid essidwork
dns-search lan.work.com lab.work.com wan.work.com corp.work.com
dns-nameservers 10.72.128.21 10.72.144.21 10.10.20.241 10.72.6.14
test peer address 10.72.5.1 mac 00:00:0C:07:AC:05 source 10.72.5.3
# When I am at a barista or the airport
iface wlan-dhcp inet dhcp
test wireless
[majuli ~]
[majuli ~]$ cat /usr/sbin/get-mac-address.sh
#!/bin/sh
set -e
export LANG=C
iface="$1"
mac=$(/sbin/ifconfig "$iface" | sed -n -e '/^.*HWaddr \([:[:xdigit:]]*\).*/{s//\1/;y/ABCDEF/abcdef/;p;q;}')
which=""
while read testmac scheme; do
if [ "$which" ]; then continue; fi
if [ "$mac" = "$(echo "$testmac" | sed -e 'y/ABCDEF/abcdef/')" ]; then which="$scheme"; fi
done
if [ "$which" ]; then echo $which; exit 0; fi
exit 1
[majuli ~]
[majuli ~]$ cat /etc/default/ifplugd
# sourced by /etc/init.d/ifplugd and
# the hotplug script /etc/hotplug.d/net/ifplugd.hotplug
INTERFACES="eth0"
HOTPLUG_INTERFACES="eth0"
ARGS="-q -f -u0 -d10 -w -I"
SUSPEND_ACTION="stop"
[majuli ~]
[majuli ~]$ cat /etc/default/waproamd
# sourced by /etc/init.d/waproamd and
# the hotplug script /etc/hotplug.d/net/waproamd.hotplug
INTERFACES="eth1"
HOTPLUG_INTERFACES="eth1"
ARGS="-w"
SUSPEND_ACTION="stop"
More on how I manage my email, NIS, NFS mounts later :-)