Saturday, 24 May 2014 15:50

How-To: Raspberry Pi multiple WiFi setup through the command line

Written by 
Rate this item
(1 Vote)

Quickly setup multiple wifi connections on your raspberry pi through the command line

Step by step illustrated guide showing you how to setup your wireless connection if you only have access to the terminal

Setting it up using just the /etc/network/interfaces files can work but you will run into issues when you need multiple connections or if you ever do access the desktop environment.  Setting it up using wpa supplicant will be more reliable in the long run.


Connecting a wifi adapter

You can find compatible WiFi adapters, not all USB adapters will work reliably, and a separate powered USB hub is usually recommended.


Logging into your raspberry pi

Either through an ssh session or locally with a keyboard and mouse, login to the pi

Default Login Credentials

Login: pi

Password: raspberry

If you need assistance logging in remotely through ssh, I step through the processes required in my guide Raspberry Pi setup without a Display


Confirm and edit your current network configuration

Type the following, and you should see your wifi interface (Our example shows wlan0)


Raspberry Pi Wifi Command Line 01


Edit the file /etc/network/interfaces Hit ctrl-x when you are done editing

nano /etc/network/interfaces

Confirm you have the following lines added in that file (you may other interface information iface eth0 for example, listed as well in there, which can be ignored for now

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


Here is my /etc/network/interfaces file

Raspberry Pi Wifi Command Line 02



Edit your wifi credentials

We need to manually enter in the wireless network information.  All information is case sensitive.

Edit the file /etc/wpa_supplicant/wpa_supplicant.conf

sudo nano /etc/wpa_supplicant/wpa_supplicant.conf 


Here is what comes default in /etc/wpa_supplicant/wpa_supplicant.conf running the latest rasbian image 2015-05-05-raspbian-wheezy.img 

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


Here is a sample wpa_supplicant.conf file showing all the various types of wifi configurations.  You choose the type (open, wep, wpa, wpa2) copy and paste that section into your configuration file

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
# Example Open
network = { ssid = "linksys"
scan_ssid=1 key_mgmt = NONE }

# Example WEP network={ ssid="linksys"
scan_ssid=1 key_mgmt=NONE wep_key0="LINKSYSWEPKEY" } # Example WPA network={ ssid="linksys"
scan_ssid=1 key_mgmt=WPA-PSK psk="LINKSYSWPAKEY" } # Example WPA2 network={ ssid="linksys"
scan_ssid=1 proto=RSN key_mgmt=WPA-PSK psk="LINKSYS_RSN_KEY" }


  • ssid - this is the name of the wireless network (what you typically see when you search for wifi connections (ie: linksys, 2WIRE032, My_home234, etc)
  • key_mgmt - this defines if the wifi is either open, wep, wpa, wpa2

  • wep_key0= - If the wifi network is wep encrypted (older, now outdated), this is where you insert the password

  • psk= - If the network is wpa/wpa2 encrypted, you will enter the wifi password here
  • proto=RSN - This line will be added to wpa2 encrypted networks

  • scan_ssid=1 - this tells your wifi adapter to look for the networks automatically and connect when in range.


Here is my current /etc/wpa_supplicant/wpa_supplicant.conf

Raspberry Pi Wifi Command Line 04


Reload the Wifi interface to connect to your network

sudo ifdown wlan0
sudo ifup wlan0


To view that the wifi interface is connected



To view the IP address of the wifi interface



You can add as many networks as you want (network={ }) or delete networks.  The above settings should work for your standard home or public guest networks, there are more advanced items you can add for corporate environments using certificates etc.  You can find more information here or issue the command inside the terminal man wpa_supplicant

Here are some further details on the items that can be included inside of network={}

Fields Definition Example
ssid The name of your wifi network ssid="2WIRE098" or ssid="linksys"
scan_ssid Set to 1 for hidden SSIDs or 0 if they broadcast the SSID. scan_ssid=1
key_mgmt WPA-PSK (Standard WPA for home networks) or NONE for open or WEP networks key_mgmt=WPA-PSK
psk WPA passphrase, leave out for open or WEP networks psk="MyWPAWifiPass"
proto WPA or WPA2 protocal, proto=RSN is needed for WPA2 networks as it defaults to WPA if not included. proto=RSN
wep_key0..3 Static WEP key (ASCII in double quotation, e.g. "abcde" or hex without quotation, e.g., 0102030405) wep_key0="MYWIFIPASS"



Read 161109 times Last modified on Monday, 28 September 2015 20:13
Algis Salys

Creator and owner of  Linux enthusiast, electronics tinkerer, and likes to spend time in the workshop building and creating new projects.