I go back and forth from home to school with my Pi. I just got the WiFi working last night at home using wpa.conf instead of wpa_supplicant.conf as the book I was using had the walk thru for that instead. I've noticed lots seem to use wpa_supplicant but I not sure why...

Anyway, I know how to make the WiFi IP static for my home network but how do I set things up for auto-connecting to my school WiFi and use a different static IP for that network?

For the network do I just add another network={} in my wpa.conf file? For the second static IP how do I bind that to the school network?

up vote 94 down vote accepted

Edit /etc/wpa_supplicant/wpa_supplicant.conf and add id_str="school" under the schools wpa info and id_str="home" under your homes wpa info. Your file should now look similar to this:

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
    ssid="SCHOOLS NETWORK NAME"
    psk="SCHOOLS PASSWORD"
    id_str="school"
}

network={
    ssid="HOME NETWORK NAME"
    psk="HOME PASSWORD"
    id_str="home"
}

Then set up /etc/network/interfaces with iface school inet static and iface home inet static in it so it looks like the following:

This applies to Raspbian Wheezy prior to 2015-05-05 for later (and Jessie) See How do I set up networking/WiFi/Static IP

auto lo

iface lo inet loopback
iface eth0 inet dhcp

allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf

iface school inet static
address <school address>
gateway <school gateway>
netmask <school netmask>

iface home inet static
address <home address>
gateway <home gateway>
netmask <home netmask>
  • It might be worth noting: If I understand the documentation correctly, in order to use this approach, you must have and id_str property for EVERY network in your wpa_supplicant.conf file. Otherwise this won't work. Can you confirm? – PICyourBrain Mar 31 '14 at 20:29
  • I don't believe this to be the case. – les Nov 21 '14 at 1:24
  • 3
    This approach works, however, is it possible to switch WiFi without having to restart the Pi? – MetalGodwin Jul 14 '16 at 17:53
  • 1
    If no id_str given, the value will be default. – Raptor Feb 7 '17 at 13:35
  • where can I read about wpa-roam and wpa-config and other wpa_supplicant statements in /etc/network/interfaces? Neither man interfaces nor man wpa_supplicant.conf have anything about those statements – Drew Apr 8 at 18:10

I recently stumbled across a console application that sorts all the wireless configuration hell out. You can also use this tool to configure the LAN interface.

sudo apt-get install wicd-curses

It will install quite a few other packages but it runs its own daemon in the background. This manages the networks and makes sure you connect to the ones you want. Run it with:

sudo wicd-curses

Screenshot of wicd-curses

If you get a message saying no networks detected press P (must be capital so use [SHIFT]p) and type in wlan0 in the wireless interface field and press F10 to save.

  1. R to refresh the list.
  2. Use the cursors on the keyboard to navigate up and down the list
  3. Press right to configure the wireless connection
  4. Press down a few times and check "Automatically connect to this network"
  5. Press down a few times again and type in your password in the key field
  6. Press F10 to save
  7. Start from 1 to do this again for any other networks

enter image description here

You might have to press C to connect to the access point. If you were connected via cable, that will most likely kill the LAN interface and bring up wireless.

It is also manages the connection so it will reconnect to any configured wireless access points if it drops out for whatever reason but it will also try to connect to any available networks, just like in Windows, Macintosh or Linux Desktops.

Hope it helps!

  • 2
    this type of tool is exactly what I was looking for. all of the flexibility offered by the GUI, but terminal instead. Thank you! – FoamyGuy May 24 '14 at 21:16
  • Upvote: After running this I did an Advanced IP Scan of the two subnets and my Rpi3 shows up on both of them. Interestingly, when I went to install this initially, it told me I already had the latest version. – SDsolar Mar 16 '17 at 18:17
  • One minor detail: To get extra range I am using wlan1 with an external antenna, so in curses I had to go into prefs to specify that adapter. There was no need to shut off wlan0 but I did it anyway with sudo ifcongig wlan0 down. – SDsolar Mar 16 '17 at 19:03

With Raspbian Jessie release, you don't have to edit the interface file. Just updating the wpa_supplicant file with multiple networks would suffice. Here's how it looks -

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
    ssid="SCHOOLS NETWORK NAME"
    psk="SCHOOLS PASSWORD"
    id_str="school"
}

network={
    ssid="HOME NETWORK NAME"
    psk="HOME PASSWORD"
    id_str="home"
}

This worked for me and my wifi is always connected to the list of available networks mentioned in the above file. Hope it helps.

Actually you can add the priority option. Like so:

network={
      ssid="open"
      key_mgmt=NONE
      id_str="open"
      priority=3
}

network={
        ssid="secure"
        key_mgmt=WPA-EAP
        proto=WPA2
        group=CCMP
        pairwise=CCMP
        eap=TLS
        ca_cert="/etc/certs/cacert.pem"
        client_cert="/etc/certs/client.pem"
        private_key="/etc/certs/client.key"
        private_key_passwd="somepwd"
        identity="me"
        priority=5
}

network={
        ssid="AndroidAP"
        key_mgmt=WPA-PSK
        proto=WPA2
        pairwise=CCMP
        group=CCMP
        psk="SomeP4ssw0rd"
        priority=4
}


network={
        ssid="Spooky"
        key_mgmt=NONE
        group=WEP104
        psk="A4ABC2FC27412D4D23CAEBCA23"
        priority=2
}

network={
        ssid="another"
        key_mgmt=WPA-PSK
        proto=WPA2
        pairwise=CCMP
        group=CCMP
        psk="A very long and secret passphrase here"
        priority=1
}

priority: when multiple networks are available simultaneously, the one with the highest priority value is selected.

id_str: for each network, you can give this parameter a specific value (a string). If none is provided, "default" is used as text string. This string is used in /etc/network/interfaces as a virtual interface identifier. This allow creating specific configuration blocks for each network. The only requirement is to have the physical interface using the "inet manual" method (this is a MUST).

  • Just double-checking here, priority is enclosed in asterisks? From what I read, they're not supposed to be enclosed in double-asterisks, but I might be wrong here. – ericmjl Jan 13 '16 at 17:17
  • @ericmjl He tried to bold the code, I'll edit it. – Patrick Cook Mar 6 '16 at 5:37
  • Is there a way to make it automatically rescan and see if a higher priority network is available and switch? – Michal Mar 10 '17 at 10:50
  • @Michal Yes, have a background process running that does just that. – les Oct 3 '17 at 22:57
  • @les How would that work, which command? – luckydonald Dec 18 '17 at 13:32

I have this link in my notes, but never tried how it works: http://www.geeked.info/raspberry-pi-add-multiple-wifi-access-points/

  • 5
    To prevent link rot and provide the best answer possible you should at least summarize the linked solution. – Steve Robillard Nov 12 '13 at 10:02
  • That's the goods... thanks. I found another link that showed me how to tag the different networks to different static IPs. I'd post it but I left the Pi at school and can't remember the exact wording of it. I think it was something like inet="net-name" then you listed your IP info but don't quote me on it. – Chef Flambe Nov 13 '13 at 1:58

protected by Community Jan 4 '16 at 7:56

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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