Although the Raspberry Pi Model B comes with built-in 100Mbps wired Ethernet, it can also use WiFi via a USB dongle. The Model A doesn’t come with Ethernet at all, so using a WiFi adapter is a good way to get networking on that model. In both cases, simply plugging in a supported USB dongle and doing a simple bit of configuration will give your Pi access to wireless.
You can get yourself a USB adapter for less than $10 but it is important to buy one which is supported by the Raspberry Pi and Linux. For this tutorial, I will be using a dongle based on the Realtek RTL8188CUS chipset. The Realtek chipset is supported by Raspbian out-of-the-box and no additional configuration is needed for it to be recognized during boot.
The RPi USB Wi-Fi Adapters page has a comprehensive list of supported wireless adapters. If you are considering buying a dongle, you should check that page for compatibility.
Plug in the USB adapter and boot your Raspberry Pi. There are several ways to check if the adapter has been recognized. The easiest is to type:
ifconfig
You should see a listing for eth0
– the built-in wired Ethernet port; for lo
– the loop back device; and wlan0
– the wireless adapter.
Alternatively you can list the current USB devices attached to the Pi using:
sudo lsusb
The list should contain your wireless dongle. On my setup, the list shows a “Realtek Semiconductor Corp. RTL8188CUS 802.11n WLAN Adapter”.
Desktop set up
If you are using the desktop on Raspbian than connecting to a wireless network is quite easy. Double click the “WiFi Config” icon on the desktop to start the wireless configuration program. The “Adapter:” field will show your USB dongle (i.e. wlan0) and the “Network:” field will be empty (unless you have previously configured a wireless network). Click the “Scan” button. Now click “Scan” on the “Scan results” window. A list of the available wireless networks will be shown along with their signal strengths etc. To connect to one of the listed networks, double click on the SSID.
On the connection window, verify the “Authentication” and “Encryption” fields and enter the password in the “PSK” field. Now Click “Add”. Close the “Scan results” window. The configuration program will automatically connect to the newly configured network.
You can add multiple networks by repeating the same steps. You can select the desired network using the “Network:” drop down list. You can also connect and disconnect using the relevant buttons. You can use the “Managed Networks” tab to edit and remove networks.
Command line set up
If you aren’t using the desktop then the WiFi can be configured using the command line. Raspbian should come with all the correct packages pre-installed but if any of the commands or files mentioned below aren’t available, then run this command to install them:
sudo apt-get install wpasupplicant wireless-tools
The general network settings are configured in “/etc/network/interfaces” while the Wi-Fi details are set in the “/etc/wpa_supplicant/wpa_supplicant.conf” file. First edit the “interfaces” file:
sudo nano /etc/network/interfaces
Ensure that the section about wlan0
(typically found at the end of the file) reads as follows:
allow-hotplug wlan0 iface wlan0 inet manual wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf iface default inet dhcp
If there are difference then change them to accordingly. Don’t alter any of the lines about the lo
adapter or the eth0
adapter. Press “CTRL + X” to exit nano (press Y and then press ENTER when prompted).
To get a list of the currently available wireless networks, use the iwlist
command:
sudo iwlist wlan0 scan
If there is too much information, use grep
to find the fields you need. For example to see just the ESSIDs, use:
sudo iwlist wlan0 scan | grep ESSID
Pick a network and add the network authentication information in the “wpa_supplicant.conf” file:
sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
The first two lines should already read:
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev update_config=1
Now add the following:
network={ ssid="YourSSID" psk="password" key_mgmt=WPA-PSK }
If your router is configured using WEP for encryption then the network information will look like this:
network={ ssid="YourSSID" wep_key0="password12345" key_mgmt=NONE }
For those of you familiar with advanced WiFi configurations, the network information can also include the following fields:
- proto – Protocol type can be: RSN (for WP2) and WPA (for WPA1).
- pairwise – CCMP or TKIP (for WPA2 or WPA1).
- auth_alg – authentication algorithm, can be OPEN for both WPA1/WPA2 and less commonly SHARED or LEAP.
Press “CTRL + X” to exit nano and save the file, press Y and then press ENTER when prompted. Finally reboot your Pi:
sudo reboot
You can check the status of the wireless connection using ifconfig
(to see if wlan0
has acquired an IP address) and iwconfig
to check which network the wireless adapter is using.
If you have any questions about wireless on the Raspberry Pi, please ask them in the comments and we will see if we can help.
40 comments
Comments are closed.
I would recommend you to use the command ip(8) instead of ifconfig(8) as the last one are deprecated. Same with arp(8) and route(8). They are also replaced by the ip command.
ip addr show – ifconfig
ip route show – route
ip neigh show – arp(8)
And lots of configuration can be done with /etc/internet/interfaces together with wpa-driver and wpa-roam stansa and use id_str=”key” in wpa_supplicant.conf file network config. Please look into manual page wpa_action(8) for more information.
But this is a greate start.
i can scan my wifi and i see my wlan but ras pi could not get a ip address from my wifi router (dhcp is configured on) when i start the ras pi gui and start wifi network it is empty.
any idea?
cu, Klaus
I take my Pi from place to place and would like to store the SSIDs and passwords of more than one network. Would you just repeat the network={…} code in the wpa_supplicant.conf file for each network?
Andrew, yes that is right, just repeat network={…} section for every network.
I’ll recommend wicd-curses it is painless to change network
Melb, thanks for the tip, yes wicd-curses is a good tool for those who don’t want to get their hands dirty!
why use wpa-roam?
Just block that line and FORGET IT!
Thanks for this tutorial. I have been struggling to setup my wireless until i found this. You rock man
Great tutorial. Can I just omit the psk or key lines for ssid’s that are open (e. g. Not password protected)
Do I also need to say key_mgmt = none?
I was looking for an answer to this as well, and it’s looking like if the network has no authentication/plaintext, you omit the psk key and include key_mgmt=NONE, eg.,
“`
network={
ssid=”whatever”
key_mgmt=NONE
}
“`
Hello
I’m trying to use the desktop setup, but for some reason it isn’t working for me. I have the Edimax 150Mbps Wirelss 802.11b/g/n nano USB adapter. Once I click scan my router does show up, but when I put in the correct password and try to use the internet, it seems to have not gone through.
Also, when I tried the command line steps that didn’t work either. Now, when I go scan to get the list of available wifi routers, nothing shows up.
Great howto, thanks!
Thank you so much. Everything worked exactly as you described it.
Both files where i use ‘nano’ are empty??
Make sure you typed them correctly, else nano will create these files
ensure you use the sudo command. For me, the files came up blank when I had left that out.
i am using a model A right here and and WiFi dongle is TL-WN727N from TP-LINK. cant seem to connect to internet at all. When i start up the pi, (/etc/network/interfaces) failed. Any help would be much appreciated. TIA
Hi,
I haven’t used that Dongle myself but looking here: http://www.raspberrypi.org/forums/viewtopic.php?t=11262&p=272581 there seems to be people who have had trouble getting it to work. That particular forum post is from 2012, so I don’t know if it is still relevant.
Does ifconfig show the wlan0 device???
Gary
@Shawn: Follow instructions on [(UPDATE) Drivers for TL-WN725N V2 – 3.6.11+ -> 3.12.24+]
Link: http://www.raspberrypi.org/forums/viewtopic.php?f=28&t=62371
More than likely because it has a ralink chipset. Try finding a card that has realtek or atheros chips. Chances are they will work out of the box
My network keeps connecting and disconnecting.. What am I doing wrong?
Been struggling to get my wi fi dongle up and running but without success (on Raspbian)
Tried several suggestions from different forums
the following is response to the command
$ sudo iwlist wlan0 scan
wlan0 Interface doesn’t support scanning.
other commands and responses
$ lsusb
Bus 001 Device 002: ID 0424:9512 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp.
Bus 001 Device 004: ID 0bda:8179 Realtek Semiconductor Corp.
Bus 001 Device 005: ID 0e8f:00a5 GreenAsia Inc.
$ iwconfig
lo no wireless extensions.
eth0 no wireless extensions.
However ifconfig does give the following:
pi@raspberrypi ~ $ ifconfig
eth0 Link encap:Ethernet HWaddr b8:27:eb:d4:88:d2
inet addr:192.168.1.36 Bcast:192.168.1.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1703 errors:0 dropped:0 overruns:0 frame:0
TX packets:1880 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1543727 (1.4 MiB) TX bytes:218299 (213.1 KiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:2 errors:0 dropped:0 overruns:0 frame:0
TX packets:2 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:276 (276.0 B) TX bytes:276 (276.0 B)
Please Note: the same dongle works fine on RASPBMC in fetching add ons , you tube videos etc
Thankx in advance for your time and help….
Hi Jadhav,
I have the sample problem. Were you able to solve this issue? If so, please advice.
Thanks,
Mohan
Like many others, I had trouble with both the WiFi Config and following this guide. In the end, used Wicd-curses
http://www.raspyfi.com/wi-fi-on-raspberry-pi-a-simple-guide/
Thanks a lot. After couple of tries I figured how to. Thanks again for the support.
thank you! very clear instructions, it took me just few minutes
I’m using a CanaKit B+ PI with the 150 MBPS USB Wireless Adapter (model CKXW1000). It connects then drops out after 5 seconds, and repeats this process endlessly. Please advise.
It worked. Very nice explanation. The ability to check the work was the best part. I was able to see that the changes I made at first did not work. A bit of trouble shooting and I found the error. Very nice.
I’m using a Netgear N300 wireless adapter. It doesn’t even show up inside of the ifconfig but it shows up in the lsusb.
Any idea? I’ve tried both powered usb hub and directly connected. (works on Windows just fine).
I just bought the Adafruit miniature wifi module. The main reason I bought it is to make my raspberry pi wire-free (except the power cable). I don’t want to use a separate keyboard, mouse and monitor for the pi, and I always use ssh and vpn to control the pi from my mac. Now this is my question. Is it possible to have the raspberry pi connect automatically to the wireless network upon boot? (I have already assigned a static IP to the pi using its mac address). In other words, I do not want to connect the pi to a monitor and run the wi-fi config every time. I want to just connect the pi to the power, and start controlling it using ssh (assuming the wifi module automatically connects the pi to my network). It this possible?? Help much appreciated. Thanks!
i guess first you will have to configure pi in wifi mode as per the instructions in this guide. Then you can install vncserver so that you can work in a headless mode.
Excellent article. Espcially the command to scan the wireless networks using iwlist helped me. I had configured incorrect group-cipher, pairwise cipher and auth-suites. This command helped me get the correct values to be set. Next step is to configure VNC server so that i can work in a headless mode.
when i type-
sudo iwlist wlan0 scan
i get this error-
wlan0 interface doesn’t support scanning
One additional note regarding the WEP configuration in /etc/epa_supplicant/wpa_supplicant.conf
Add the following line to force the use of wep_key0:
wep_tx_keyidx=0
Thanks. This was a great help!
I feel dumb. How do you make this —> | ?
Depends on the keyboard layout, but on mine (UK English) it’s to the left of the ‘Z’ key, as a Hold Shift extension to the ‘\’.
..so yeah, left of ‘Z’ key is ‘\’, hold shift and press it to get ‘|’
Can’t make any of this work. I’m a total beginner. Help please? Got Wi-Fi adapter to find my Wi-Fi network but doesn’t seem to connect to the net.
Help please?
The dialog box with the add button is off my screen and I cannot resize it so that I can see the add button. Any ideas?
Thank you
When I list event history from wpa_gui _it shows 4Way handshake failed, pre-shared key may be incorrect. Under STATUS I get: Could not get staus from WPA_SUPPLICANT
Last message signal 15 received.
I am using a RASPERRY PI B1 and 150 Mbps 802.11N/G/B RALINK TECH. RT5370 Wireless adapter.
ANY HELP WOULD BE APPRECIATED!