In order to configure
/etc/network/interfaces to work with multiple locations, you have to understand the difference between logical and physical interfaces. Physical interfaces correspond to the hardware devices that you have installed in your system and they are identified by a particular naming scheme (wlan0, wlan1, eth0, ra0, etc).
/etc/network/interfaces, you can specify only one configuration for each physical interface, so this is where logical interfaces come into play. You can have multiple logical interfaces for one physical interface. This is called mapping. To map a logical interface to a physical interface, you add this to
mapping ra0 # map physical interface ra0...
map home work # ...to 'home' and 'work' logical interfaces
Then, you write the configuration for each of this interfaces:
iface home inet dhcp # configuration stanza for 'home' logical interface
iface work inet dhcp # configuration stanza for 'work' logical interface
Of course, this is not going to work because the system doesn't know which interface to use, so we'll use
guessnet to help the system to choose a configuration.
sudo apt-get install guessnet
Then, we use
guessnet in the mapping stanza:
script /usr/sbin/guessnet-ifupdown # <-- We added this
map home work
Guessnet acts by testing the networks according to some criteria (IP, ESSID, MAC addresses) and choosing the configuration that doesn't fail those tests. In the following example, if there is a network with ESSID 'Work' available, the interface
ra0 that we defined earlier, is going to connect to it and apply this configuration:
iface work inet dhcp
test wireless essid Work # We test if the ESSID of the network is 'Work'