I want to configure my /etc/network/interfaces to detect different access points and connect to them accordingly. This is the current state of this file:

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
allow-hotplug eth0
iface eth0 inet dhcp

auto ra0
iface ra0 inet dhcp
 wpa-ssid MyNet
 wpa-psk 00d8f778e1e86be0961aa767564d7364ee44fcbd704e4e31ee6c4af0f855c32f

This successfully detects an ethernet connection and connects to MyNet when it is available. How do I configure it so it can detect multiple access points?

Here seems to be the answer, but I wasn't able to understand the instructions.

I have tried multiple GUIs (nm, wicd, etc.), but none of them seems to work on my laptop. Anyway, I prefer to do it via command line.

  • It is more simple than that link. I added an answer. – Rui F Ribeiro May 25 '17 at 19:23
  • @RuiFRibeiro Sorry, I didn't mentioned it in my question but I already tried wpa_supplicant and it's not working in my laptop. Also, I am really puzzled by this configuration file and would like to know how to edit it :-) – Federico May 25 '17 at 23:17
  • 1
    wpa_supplicant is definitely working on your laptop, because it's the only Linux software that deals with encrypted WLAN. It's possible that you are running network manager (which uses wpa_supplicant), so you need to either disable network manager, or configure it instead of wpa_supplicant (because configuring for both won't work). – dirkt May 26 '17 at 5:54

To address multiple wifi configs/ssids, you would better work at the wpa_supplicant level.

Just leave your interface as:

auto ra0
iface ra0 inet dhcp

Install wpa_supplicant with:

apt get install wpasupplicant

You can define several locations in wpa_supplicant.conf, where the SSID determines which configuration will be used. As in:

    psk="ssid2 PASSWORD"

    psk="ssid1 PASSWORD"

Restart the service each time you add a configuration for a new SSID.

When connection to an AP, depending on the SSID name, wpa_supplicant with automagically select the corresponding configuration.

| improve this answer | |

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).

In your /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 /etc/network/interfaces

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
 wpa-ssid Home
 wpa-psk 00d8f778e1e86be0961aa767564d7364ee44fcbd704e4e31ee6c4af0f855c32f

iface work inet dhcp # configuration stanza for 'work' logical interface
 wpa-ssid Work
 wpa-psk 00d8f778e1e86be0961aa767564d7364ee44fcbd704e4e31ee6c4af0f855c32f

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:

mapping ra0
        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'
 wpa-ssid Work
 wpa-psk 00d8f778e1e86be0961aa767564d7364ee44fcbd704e4e31ee6c4af0f855c32f
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.