~~NOTOC~~ ====== Automatic Network selection ====== The following article explains how to use the linux network configuration scripts to automatically select the correct network/settings according to the location (i.e. avilable essid). ===== Procedure ===== This is the /etc/network/interfaces file : auto ath1 iface jaist inet dhcp wireless-essid JAISTALL iface home inet dhcp wireless-essid MyPlace pre-up /sbin/wpa_supplicant_5.4 -Bw -dd -Dwext -iath1 -c/etc/fonera.conf post-down killall -q wpa_supplicant_5.4 # For temporary locations using wep # iface temp inet dhcp # wireless-essid TMP # wireless-key1 s:password # wireless-defaultkey 1 # wireless-keymode open mapping ath1 script /mapper map MyPlace ,, home map JAISTALL 00:0F:23:A4:A4:00,, jaist map TMP ,, temp # Add MAC addresses after the SSID, if the wireless network does not broadcast # essid, at least one MAC address of one accesspoint must be defined. On # networks that boradcast the essid, there is no need to configure MAC # addresses. iface ath0 inet dhcp wireless-essid MyPlace pre-up /sbin/wpa_supplicant_5.4 -Bw -dd -Dwext -iath1 -c/etc/fonera.conf post-down killall -q wpa_supplicant_5.4 The "MyPlace" is the essid that I use at home and "JAISTALL" is the essid at school. At home I use WPA (wpa_supplicant) while in JAIST its MAC based access control. The mapper file selects the virtual interface according to which essid is available #! /bin/bash ifname=$1 ifconfig $ifname up function log { time=$(date +%d%m%y-%H:%M:%S) echo $time $@ >> /tmp/res } function TestMac { ifname=$1 vifname=$2 mac=$3 if [ "$mac" != "" ] then log "Looking for MAC address $mac using $ifname" res=$(iwlist $1 ap | grep $mac) if [ "$res" != "" ] then log "MAC address found, mapping $ifname to $vifname" echo $vifname else log "Not found" fi fi } while read ssid mac vifname do log "Mapping $ifname to $vifname {$ssid}" if [ "$(iwlist $ifname scanning | grep $ssid)" != "" ] then log "$ssid found mapping $ifname to $vifname !" echo $vifname exit fi # process mac addresses if they exist MAC1=$(echo $mac | cut -d"," -f1) MAC2=$(echo $mac | cut -d"," -f2) MAC3=$(echo $mac | cut -d"," -f3) TestMac $ifname $vifname $MAC1 TestMac $ifname $vifname $MAC2 TestMac $ifname $vifname $MAC3 done ===== Usage ===== When your laptop boots, the interface ath1 will be configured according to your location. At anytime, you can run "ifup ath1" to setup your interface by hand. You can enforce some location for example by issuing "ifup ath1=jaist" in order to connect to essid JAISTALL when both essids (JAISTALL and MyPlace) are available ... ===== Note ===== If you are planning to use these files, be sure to change the following items accorsing to your own setup. * ath1 : the wireless interface name * MyPlace : The essid at your home, or location 1 * JAISTALL : The essid of your second location * /sbin/wpa_supplicant_5.4 : Path to the wpa_supplicant program * /etc/fonera.conf : path to the configuration file for the wpa_supplicant program {{tag>howto wireless unix}}