Posted by Scott Campbell | Raspberry Pi | 43
Note: This tutorial is for the Raspberry Pi 2 and earlier versions that need a USB WiFi adapter. To set up WiFi on the Raspberry Pi 3, please see this tutorial.
In a previous tutorial, I explained how to establish an SSH connection to your Raspberry Pi over ethernet without using an external keyboard or monitor. Connecting with an ethernet cable, is greatif you want to leave it connected to your router with a physical cable. ButI prefer to use WiFi, which gives me a lot more flexibility with whereI can keepmy Pi while it’s running.
Be careful when choosing a WiFi adapterfor the Raspberry Pi though, because not all of themwill work out of the box. I found that this one on Amazonworks great without any driver installations needed.
Still, there are a couplethings that need to be set up for any WiFi adapter to work properly with your Raspberry Pi. I’ll go through them step by step in this article. You should already have set up the SSH connection over ethernet, as describedin this post.
BONUS: I made a quick start guide for this tutorial that you can download and go back to later if you can’t set this up right now. It covers all of the steps and commands you need to get started.
This video will walk you through the steps, but see below for more details:
Edit the Network Interfaces File
With your USB WiFi adapter plugged into the Pi, power up thePi and connect it to your internet router with an ethernet cable just like we did in the last tutorial. Now SSH intoyour Pi with PuTTY, and get to the command prompt:
We’ll need to change a few thingsin the/etc/network/interfaces file.
To edit this file, we’ll use the Raspbian text editor Nano. Enter this at the command prompt to edit the file:
sudo nano/etc/network/interfaces
Pro Tip: If you ever want to copy something from your laptop/desktop and paste it into PuTTY, just copy it, then right click with your mouse where you want to paste it into PuTTY.
Replace the code in the file with this code:
auto loiface lo inet loopbackiface eth0 inet dhcpauto wlan0iface wlan0 inet dhcpwpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
Afterwards, the file should look like this:
Then type Ctrl-X to exit, and Yto save the changes.
Edit the wpa_supplicant.conf File
Now we need to make some changes to the /etc/wpa_supplicant/wpa_supplicant.conf file. Open the file in Nano by entering this at the command prompt:
sudo nano/etc/wpa_supplicant/wpa_supplicant.conf
Replace the code in the file with this code:
ctrl_interface=/var/run/wpa_supplicantctrl_interface_group=0update_config=1network={ ssid="YOUR WIFI NETWORK NAME" psk="YOUR WIFI PASSWORD" proto=WPA key_mgmt=WPA-PSK pairwise=TKIP group=TKIP id_str="YOUR WIFI NETWORK NAME"}
The file should look like this:
The entry for ssid="YOUR WIFI NETWORK NAME"
is the name of your wireless network, typed exactly as it appearswhen you connect to your WiFi from another computer. The letters are case sensitive, and the ” ” marks should be left in.
The entry forpsk="YOUR WIFI PASSWORD"
is the password you normally use to login to the network.
Re-enter your network name in theid_str="YOUR WIFI NETWORK NAME"
line.
Now press Ctrl-X and Yto exit and save changes to the file.
Now shutdown the Pi byenteringsudo poweroff
at the command prompt. Unplug the Pi from power, and disconnect the ethernet cable from your internet router. Now restart the Pi.
Find the New Local IP Address
Up to this point we were SSHing to the Pi with the local IP address on the ethernet port. The IP will be different on WiFi, so you’ll need to use Advanced IP Scannerto find the new one. Once you get that, SSHwith PuTTY using the IP address for the WiFi port.
Test the WiFi Connection
After you log back into the Pi,check the statusof your WiFi connection by typingiwconfig
at the command prompt. Your WiFi network name should appear under ESSID: "YOUR WIFI NETWORK NAME"
, in my case it’s "Siamese"
. If your WiFi connection is successful, you’ll see a message like this:
If you see something like Link Quality=0/100
or Signal Level=0/100
in the wlan0
section, it means the Pi isn’t connected to WiFi. Go back and make sure that you have entered everything exactly as it’s shown in the images.
Another way to test your Pi’s WiFi connection to the internet is by pinging Google. Do this by entering sudo ping www.google.com
:
PuTTY is great if all you need to do is access your Raspberry Pi from the command line. However, many features are only available through the Raspbian desktop. In order to access the desktop remotely, we need to install and configure a Remote Desktop Connection. Read How to Access the Raspberry Pi Desktop With a Remote Desktop Connectionfor a tutorial on how to do that.
Thanks for reading!Feel free to leave a comment if you’re having trouble setting this up and I’ll do my best to help you out. And be sure to subscribe to get an email when we publish new tutorials!
Related Posts
How to Control an Arduino from a Raspberry Pi
December 17, 2020
Raspberry Pi Touchscreen Calibration and Screen Rotation
February 4, 2015
How to Write and Run a Shell Script on the Raspberry Pi
August 11, 2015
How to Use DC Motors on the Raspberry Pi
June 10, 2021
43 Comments
DocPuneeton October 3, 2015 at 5:31 pm
Wonderful articles! I am waiting for the courier of my new Raspberry Pi 2. And…I have ordered a new dongle called as EDUP EP-N8553. I know that time will answer that..but do you think it will work with the above method?
I am a Doctor and excited to tinker and create some wifi medical gadgets with my Pi.
Thanks in advance!Reply
Circuit Basicson November 19, 2015 at 3:04 am
Great! Hard to say if it will work or not, but I imagine it will. Have fun with your new Pi!
Reply
Baidyon November 28, 2015 at 4:27 pm
See AlsoWiFi Keeps Disconnecting All The Time? Here’s How To Fix ItHow to Check Your Wi-Fi Signal StrengthHow to Add a Wi-Fi Network to Any DeviceHow to Get Home Internet on Your Wi-Fi DevicesThank you for the tutorials. You are awesome
Reply
rowinon December 6, 2015 at 8:20 pm
it doesnt show wlan0 on iwconfig and if i type sudo iwlist etc…… it says :”Interface doesnt support scanning”
Reply
Vinícius Silvaon January 2, 2017 at 12:09 pm
The same thing happened with me
Reply
azzon December 9, 2015 at 2:43 pm
pi@raspberrypi:~ $ sudo iwlist wlan0 scan | grep ESSID
pi@raspberrypi:~ $ sudo iwlist wlan0 scan
wlan0 No scan resultspi@raspberrypi:~ $ iwconfig
wlan0 unassociated Nickname:””
Mode:Managed Frequency=2.412 GHz Access Point: Not-Associated
Sensitivity:0/0
Retry:off RTS thr:off Fragment thr:off
Power Management:off
Link Quality:0 Signal level:0 Noise level:0
Rx invalid nwid:0 Rx invalid crypt:0 Rx invalid frag:0
Tx excessive retries:0 Invalid misc:0 Missed beacon:0lo no wireless extensions.
eth0 no wireless extensions.
Reply
SKon January 21, 2016 at 1:35 am
This is awesome, simple and clear, good job!
Reply
Andreion January 24, 2016 at 10:09 pm
Why this page goes down it was a great help,
It happen 1 hour after I put this link in this forum
These tutorials are the best.
ThanksReply
Aon January 24, 2016 at 10:15 pm
Where is the problem that someone placing links here? your page raspberry-pi-basics-setup-without-monitor-keyboard-headless-mode have disappeared. put it working again for more peopple see your great tutorials
Reply
Circuit Basicson May 7, 2016 at 4:05 am
I’m not sure, it may have been an issue with my server. But by all means feel free to share any of our tutorials! Thanks!
Reply
Meekoon February 4, 2016 at 3:41 pm
Wireless networks don’t always show up as wlan[x]. Sometimes they show up as eth[x]. A dongle should never shift from one to the other, but if yours appears to be unrecognized, see if it’s eth[x] instead. If that happened, set up your configuration using eth2 (or whatever) instead of wlan0.
If you don’t plan on taking your Pi on the road, give it a static IP address. No more having to discover its IP every time it powers up or reboots. You can always do this in the Pi’s network configuration, but you might be able to have the router reserve an IP for a given MAC. If you do the former, it would be a good idea to set the router’s DHCP configuration to not assign some IPs so they can be used for static IP devices.
Reply
Franceson March 8, 2016 at 11:32 am
Very grateful for this article. However I ran into a problem with the scan command (got the message that the device could not be scanned) and eventually followed some advice just to make a couple of lines change to the wpa_supplicant.conf file (adding the network name and password to the end of that file and leaving the other file alone). This worked immediately with my Raspberry Pi wifi dongle. I am using the latest version of Raspian. Maybe the OS has been updated since your article, so I am just writing this here in case it’s useful to others.
Your articles here and subsequently are extremely useful – thank you.Reply
Jack Torcelloon March 11, 2016 at 6:40 pm
I trust that I leave the quote marks on the “ssid” and “password”?
Mine shows Interface Doesn’t Support Scanning (RPi B Model) with
a StarTech USB2.0 to IEEE 802.11N adapter (150WN1X1)After IWCONFIG, it says No Wireless Extensions…?
Reply
Arthur Sagyon March 31, 2016 at 6:28 pm
Kindly elaborate how to “cut & paste” from your article into the Raspbian text editor, Nano please
Reply
Circuit Basicson May 7, 2016 at 4:07 am
You can copy anything from your desktop by using the usual Ctrl-C or right click and “copy”. Then to paste it into nano, all you need to do is right click your mouse and the text will be pasted in.
Reply
Karl Vosson June 25, 2016 at 5:16 pm
You LITERALLY highlight the code you want and COPY it (ie hit Control-C). You then place the mouse into the PUTTY window and right-click. Presto
Reply
Arthur Sagyon March 31, 2016 at 8:13 pm
Thank you for the very detailed tutorial(s) I just started w/the Raspberry Pi 3 – and am wondering if the configuring the WIFI of this unit would be different – as it has an internal dongle – which I assume is active all the time…
I followed yr instructions and even though I have a NIC connection, after rebooting – no WIFI is found.
When I type iwconfig, this is what I get:
wlan0 IEEE 802.11bgn ESSID:off/any
Mode:Managed Access Point: Not Associated Tx-Power=1496 dBM
Retry short limit:7 RTS thr:off Fragment thr:off
Power Management:on
lo no wireless extensions.
eth0 no wireless extensions.Reply
Circuit Basicson March 16, 2017 at 5:36 pm
Yep, the set up for the RPi 3 is different, and a bit easier too. I’ve just posted a new tutorial on how to set up WiFi on the Pi 3: https://www.circuitbasics.com/how-to-set-up-wifi-on-the-raspberry-pi-3/
Reply
drowenon April 1, 2016 at 3:20 pm
Trying to hook up wireless to pi2. Have copied and pasted your instructions to my terminal. When I remove the eth cable and try to use wireless, this is what I get. The $ iwconfig was completed with the eth cable hooked up. Then powered off, removed power cord and eth cable, inserted wifi dongle (Edimax) and tried to ssh back into pi with no luck. Any suggestions? Tried to scan ip and could not locate. Used the ip and worked with the eth cable attached. Thank you for your help and tutorials. Don
st login: Fri Apr 1 14:55:59 2016
pi@raspberrypi:~ $ iwconfig
wlan0 unassociated Nickname:””
Mode:Auto Frequency=2.412 GHz Access Point: Not-Associated
Sensitivity:0/0
Retry:off RTS thr:off Fragment thr:off
Power Management:off
Link Quality:0 Signal level:0 Noise level:0
Rx invalid nwid:0 Rx invalid crypt:0 Rx invalid frag:0
Tx excessive retries:0 Invalid misc:0 Missed beacon:0lo no wireless extensions.
eth0 no wireless extensions.
pi@raspberrypi:~ $ sudo poweroff
Connection to 207.88.171.245 closed by remote host.
Connection to 207.88.171.245 closed.
207:~ donrowen$ ssh pi@207.88.171.245
ssh: connect to host 207.88.171.245 port 22: Operation timed out
207:~ donrowen$Reply
William Schmidton May 11, 2016 at 1:11 am
What if our wifi network doesn’t need a password?
Reply
Arun Kumar Balachandranon June 2, 2016 at 5:12 am
Excellent article . Just as the first article on headless installation of raspbian OS . This one too rocks.!!
Reply
Steven Limon June 11, 2016 at 4:24 pm
thk u for this fantastic video
I wanted to send image from IPad3 or iPad pro using HDMI OPTION VIA WIRELESS TO MANY LCD MONTORS
CAN THE Pi2 support?
pls advicethks & regards
StevenReply
Karl Vosson June 25, 2016 at 5:15 pm
I can FIND all my networks, but I consistently get a “wlan0 not associated” – I wonder if my router is not handing out credentials? Could that have to do with my WiFi location? (it persistently wants to be in the UK, not the US). I have this problem for the Pi1, Pi2 and Pi3 with two different dongles. Note that nothing else has ever had problems connecting to my network…
Any ideas?Reply
Rubenon October 4, 2016 at 7:41 am
your networks are WEP or WPA-PSK? I think that if you have a modem with WEP security, you going to have problems with the WIFI, I have a modem with WEP and i cant connect even if I change the configuration to WPA-PSK, I have the theory that the raspberry cant recognize that the password is other, becasuse it works with the default password even you change the configuration to WPA-PSK, tryed with a modem that the default configuration be WPA-PSK
Reply
Circuit Basicson March 17, 2017 at 3:28 am
Check out this blog, the author got his WiFi working with WEP encryption: https://jeffskinnerbox.wordpress.com/2012/11/05/wifi-support-on-raspberry-pi/comment-page-1/#comment-1959
They also offer some other ideas in this thread on the RPi Forums: https://www.raspberrypi.org/forums/viewtopic.php?f=91&t=9612
Reply
badmadon July 12, 2016 at 8:51 am
Thanks for the tutorial. It definitely helps. Can you please tell if this wifi dongle can be set in monitor mode to sniff all the packets? The broadcom wifi chip on Pi3 doesn’t allow to be set in monitor mode. I am looking for an economical alternative.
Reply
vivek borseon July 24, 2016 at 7:13 am
how to connect wifi on raspberry pi 3 model B?
give me procedure in detailReply
Johnon August 12, 2016 at 1:15 pm
Another easy to follow tutorial, many thanks ( again) :-)
Reply
Josh Greeneon August 15, 2016 at 11:46 pm
I can’t get mine to work, I’ve tried about 10 different tutorials…I can see the wifi ESSID that I need, I tried this back and forth and I can’t figure it out.
Reply
Mike Mushovicon October 21, 2016 at 2:36 pm
I am having the same issue; i.e. I can see our network but never get a connection with the latest version of Debian –> Jennie. I did try the older version (Wheezy) and that worked right out of the gate. My conclusion: there are changes to the way it all works that the majority of tutorials do not address as they were written for the older versions of Debian. I’ve read and tried many of them. I’m going to put my notes here as this forum/thread shows more recent activity and isn’t hard to post in.
MikeReply
Mike Mushovicon October 21, 2016 at 2:37 pm
First attempt: follow advise above and change the security on our wireless router
Reply
Circuit Basicson March 17, 2017 at 2:59 am
The steps above do still work for Raspbian Jessie released 3-2-17. I just set it up on my Pi 2 to check. Were you able to find a solution to your connection problem?
Reply
Rubenon October 4, 2016 at 7:35 am
And what happend if the internet is a WEP instead a WPA-PSK, in WEP doesnt have TKIP,, Well i tryed to change the configuration from WEP to WPA-PSK and i do all the process in the tutorial, could you help me please
Reply
Circuit Basicson March 17, 2017 at 3:23 am
Try going through the steps in this tutorial: https://jeffskinnerbox.wordpress.com/2012/11/05/wifi-support-on-raspberry-pi/comment-page-1/#comment-1959
He seems to have gotten WiFi set up with WEP encryption. There’s also this thread from the Raspberry Pi Forums:
https://www.raspberrypi.org/forums/viewtopic.php?f=91&t=9612Reply
akshayon October 30, 2016 at 6:12 am
how to connect raspberry pi to android mobile hotspot
Reply
Alexandre Marcoon November 4, 2016 at 9:14 pm
tks a lot great help
Reply
Keith Wilkeon December 25, 2016 at 10:23 am
This is NOT appropriate for RP 3 which has the built in WiFi. With the RP3, you need to use the desk top to set up the network (rop, right hand corner for WiFi icon).
Reply
Circuit Basicson March 16, 2017 at 5:42 pm
The set up is different for the RPi 3, so I’ve just written a new guide on how to set it up. You can set it up with the desktop, but if you’re Pi is headless you can also use the command line: https://www.circuitbasics.com/how-to-set-up-wifi-on-the-raspberry-pi-3/
Reply
Jhashankon February 2, 2017 at 3:02 pm
I wanted to setup WiFi on my pi and followed ur steps.Now it is not working with the dongle after changing those files . Plz tell what to do asap I worrying that how it will be corrected.
Reply
Swathi kon June 29, 2017 at 6:00 am
if i set my pi to my house wifi can it access other wifi also (provided i set it to access it in the same way) or once it is set will it wirelessly access only one wifi?
Reply
MiteshMAHERAon April 8, 2019 at 9:33 am
After doing this process my putty not accepting any address for wlan0 or wifi id’s
And also not login my wifi id’s. why??Reply
hardware networking training instituteon May 16, 2019 at 9:53 am
USB WiFi adapter into one of the free USB ports on the Raspberry Pi. Power up the Raspberry Pi – remember at this point the WiFi adapter does not work yet. You are still going to need some other means of being able to control the Raspberry Pi either via a keyboard or remotely using a wired network connection.
Reply
Gerald Brownon April 23, 2021 at 10:25 am
I would suggest that you include a publish DATE on your articles. It is now April 23, 2021 and everything in this article seems to be very out of date.
Even better would be to update this article with all of the most recent data available and with a publish date.
Thanks.
Reply