- How to get Wi-Fi to connect on boot?
- 3 Answers 3
- Raspberry Pi WiFi Setup: Here are 5 Methods for Raspbian
- Raspberry Pi WiFi Setup in Headless Mode
- Method 1: Using wpa_supplicant File
- Set up WiFi on Raspbian Desktop
- Method 2: Configure WiFi using Welcome Wizard
- Method 3: Connecting from the Taskbar
- Set up WiFi on Raspbian Lite
- Method 4: Using raspi-config Tool
- Method 5: Manual Configuration
- Final Words
- About the Author: Vishnu Mohan
- Setup WiFi on a Pi Manually using wpa_supplicant.conf
- Step 1 – Create a fresh SD card using Raspbian image
- Step 2 – Create a blank text file
- Step 3 – Copy to SD Card
- Step 4 – Eject, Insert and Boot
- Additional Thoughts
- Troubleshooting
How to get Wi-Fi to connect on boot?
Raspberry Pi Model B
OS: Raspbian I am running my Pi headless (currently through a direct Ethernet connection). I have a USB WiFi dongle. I would like to have the WiFi start up at boot and connect by DHCP. http://rpi.tnet.com/project/faqs/headlessportablewifi suggests that I don’t need to actually change /etc/network/interfaces from the default:
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 default inet dhcp
I have configured /etc/wpa_supplicant/wpa_supplicant.conf for my network. When I boot the Pi, WiFi does not immediately connect. But if I SSH in and run sudo ifup wlan0 , the Pi connects fine. Isn’t this something the Pi should do in its own boot process? I could presumably write tell some dotfile to run this command, but I would like to do it the proper way (and learn how my system works). I know I can also set a static IP address for each WiFi network I want to use: How to setup multiple WiFi networks?. But I would prefer to have a simple solution where I only have to enter a couple lines on /etc/wpa_supplicant/wpa_supplicant.conf to add a new WiFi network. What is the piece I am missing here?
3 Answers 3
The default Raspbian /etc/network/interfaces configuration does not connect to WiFi on boot. The key lines of the interfaces man-page are:
Lines beginning with the word «auto» are used to identify the physical interfaces to be brought up when ifup is run with the -a option. (This option is used by the system boot scripts.)
.
Lines beginning with the word «auto» are used to identify the physical interfaces to be brought up when ifup is run with the -a option. (This option is used by the system boot scripts.)
The first missing piece was the line auto wlan0 . As far as I know, it can go anywhere in the file.
That works until you try booting without the ethernet cable plugged in. Then, WiFi doesn’t connect on boot and has to be manually triggered by running sudo ifup wlan0 or unplugging and reinserting the Wi-Fi dongle.
The problem is caused by the ifplugd daemon, which turns network devices on and off when you plug them in or remove them. You can reconfigure it, or you can simply remove it with sudo apt-get purge ifplugd .
If you have removed ifplugd, you should add the following lines to /etc/network/interfaces so that the ethernet connection will also connect when plugged in:
auto eth0 allow-hotplug eth0
I’m not sure if the auto lines are strictly necessary or if hotplug handles booting correctly in the absence of ifplugd, but this worked for me.
auto lo iface lo inet loopback auto eth0 allow-hotplug eth0 iface eth0 inet dhcp auto wlan0 allow-hotplug wlan0 iface wlan0 inet manual wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf iface default inet dhcp
Raspberry Pi WiFi Setup: Here are 5 Methods for Raspbian
Setting up a proper WiFi connection on Raspberry Pi is somewhat tricky for beginners. They often face some issues while trying to connect Raspberry Pi to WiFi. One of the main questions I’m receiving from the newbies is Raspberry Pi is not connecting to WiFi, what should I do?
And some others are asking to give a proper Raspberry Pi WiFi setup that they can follow easily. Since I’m getting questions like this regularly, I decided to write a detailed guide to set up a WiFi connection on the Raspberry Pi.
Here I’m gonna hold your hands and walk you through 5 different ways by which you can set up a WiFi connection on Raspberry Pi OS or Raspbian. Note that this is not for any specific Raspberry Pi models (but for Raspbian only) so this will work on all models that support WiFi connectivity.
Raspberry Pi WiFi Setup in Headless Mode
Method 1: Using wpa_supplicant File
Here we going headless mode means we are not gonna use or need a monitor/ display connected to your Pi. This method is applicable if you have just flashed your SD card and want to connect it with WiFi in its first boot. However, it also works with an older sd card that you used on any other wireless network.
All you need to do here is to create a raspberry pi wifi setup wpa_supplicant file and copy it to your SD card. Nothing else. This file will hold the WiFi credentials and tell the Pi to connect automatically at the next booting.
- First, you need to open a text editor (like Notepad) on your computer and copy the following code into it.
country=IN ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev update_config=1 network=
- Now replace YOURSSID and YOURPASSWORD with your WiFi network name and password respectively. The SSID is nothing but Service Set IDentifier and is your network’s name. Also, change the country code if needed.
- Save the file with the name: wpa_supplicant.conf (the file name should be exactly like this).
- Insert your SD card into your computer and copy the wpa_supplicant.conf file into the boot partition.
In case if you want to enable SSH automatically, then you need to create and copy another file named ssh into the same boot partition. You don’t actually need any content in that file. Just create an empty file and you’re done.
Set up WiFi on Raspbian Desktop
Method 2: Configure WiFi using Welcome Wizard
For this method of WiFi configuration on your Pi, we need a desktop connection so that we can directly set it up from the welcome wizard.
If this is your first boot after flashing the SD card, then you will surely come across a welcome wizard with a message like “Welcome to Raspberry Pi”. Subsequently, it will ask for setting up your system.
After booting, once you choose your language and country, you will be taken to a window like this:
Here select your WiFi network name (SSID) from the list and enter the password. That’s all. Wait for a few moments and you’ll be connected to the network.
Method 3: Connecting from the Taskbar
Just in case you missed the welcome wizard or this is not your first boot, you can configure and connect at any time from the taskbar. For this:
- Click on the network symbol at the top of the main panel near the clock.
- You will now see a list of WiFi networks available.
- Choose your preferred network, enter the password.
Set up WiFi on Raspbian Lite
If you are running on the Raspbian Lite version, then you may need some additional help you find out and configure the WiFi properly. On Raspbian Lite, there are 2 methods by which you can do the same. Let’s check it out.
Method 4: Using raspi-config Tool
The raspi-config is a great tool available on Raspbian by default. This will help you configure your wireless network with ease.
- Navigate to the Network Options > Wi-Fi
- Then type your SSID and password.
- Exit the tool.
Your Pi will now connect to the WiFi network and you can proceed with that.
Method 5: Manual Configuration
This method is a bit difficult but may be useful for connecting to big networks that need secure authentication or other complexities.
For manual configuration, the first part is the same as we did in method 1 that is editing the wpa_supplicant.conf file with your desired configuration. The file will be available at /etc/wpa_supplicant/ and you can edit it using the Nano editor. For this, you can use this command:
sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
This will open the file and you can see the same content as we have seen in method 1. That’s actually a basic configuration.
If you are interested, you can refer to some more examples here to adapt the configurations to your network for security options like WEP, EAP, etc.
Now, when coming to the network configuration, if you wish to set a static IP on your network, the configuration can be performed in dhcpcd.conf file. Type this command to open the file:
Now scroll down and find the “Example static IP configuration” line and uncomment every line of code that you need. This may include routers, DNS, IP address, etc. Modify the values and save them.
To reflect the changes, just reboot your Pi using the below command.
Final Words
Hopefully, by now you have familiarised all the 5 methods that can be used for Raspberry Pi WiFi setup. Now you can try this yourself and configure your WiFi according to your needs.
Wherever possible, try to use the desktop methods which will be the easiest ones for beginners. For advanced users, they can use any of the methods at any time. But before proceeding with complicated experimentation or modification, consider creating a backup of your sd card. This will be useful at times when you mess up with something.
If you have any comments, drop them in the comment section below.
Found an issue with this article? Report it here, so that I can resolve it.
About the Author: Vishnu Mohan
Vishnu Mohan is an ardent hobbyist of Raspberry Pi projects, who hails from God’s Own Country. He is kind of a minimalist person who believes in keeping things simple & elegant in life. Apart from the techy things, he is passionate about music and cricket. In his free time, he likes to read books and spend quality time with his family and friends.
Setup WiFi on a Pi Manually using wpa_supplicant.conf
This article explains how to setup WiFi on a Raspberry Pi without needing to connect a monitor or keyboard to the Pi. Although you can configure WiFi using the graphical utility within the Raspbian Desktop this requires that you connect a keyboard, mouse and monitor to your Pi. It is sometimes useful to be able to do it before you’ve booted the Pi. This is especially useful when using the Pi Zero W or A+ models where attaching a keyboard and mouse requires a USB hub.
The following technique will allow you to take a fresh SD card, setup WiFi and boot a Pi without any other wires than a power cable. It should work for all Pi models but it’s easier on the devices with on-board Wi-Fi as you don’t need to worry about a WiFi dongle.
Step 1 – Create a fresh SD card using Raspbian image
NOTE: This method to setup WiFi must be completed before you boot this card for the first time. This is the point at which the system checks for the wpa_supplicant.conf file. If you have already booted the card you will need to re-write with a fresh image and continue.
Step 2 – Create a blank text file
Create a blank text file named “wpa_supplicant.conf”. Use a plain text editor rather than a Word Processor.
If using Windows you need to make sure the text file uses Linux/Unix style line breaks. I use Notepad++ (it’s free!) and this is easy to do using “Edit” > “EOL Conversion” > “UNIX/OSX Format”. “UNIX” is then shown in the status bar.
Insert the following content into the text file :
country=us update_config=1 ctrl_interface=/var/run/wpa_supplicant network=
Double check the SSID and password. Both the SSID and password should be surrounded by quotes.
The Country Code should be set the ISO/IEC alpha2 code for the country in which you are using your Pi. Common codes include :
- gb (United Kingdom)
- fr (France)
- de (Germany)
- us (United States)
- se (Sweden)
Step 3 – Copy to SD Card
Copy the file to the boot partition on your SD card. In Windows this is the only partition you will be able to see. It will already contain some of the following files :
Step 4 – Eject, Insert and Boot
Safely remove the SD card from your PC and insert into the Pi. Power up the Pi and once it has booted you should be connected to your WiFi network.
You may be able to use your Router admin interface to list connected devices. Your Pi should appear in the list with an assigned IP address.
Additional Thoughts
As Sebastian Bjurbom points out in the comments below you might want to take this opportunity to enable SSH as well. It is disabled by default but it is easy to enable by copying a blank text file named “ssh” to the boot partition. This can be done at the same time “wpa_supplicant.conf” is copied across.
If you save a copy of the wpa_supplicant.conf file (in a secure location) you can quickly copy it to all your SD cards when they have a fresh image written to them.
Troubleshooting
If after waiting a few minutes your Pi is not connected to your WiFi consider the following points :
- Did you complete this method before booting this SD card for the very first time? If not start again from Step 1
- Check wpa_supplicant.conf exists in the boot partition and the filename is correctly spelt
- Check the file contains the text listed above
- Double check every character in the SSID
- Double check every character the password
- Check the SSID and password are correctly surrounded with double quotes “….”
- Ensure your text editor is using Linux style line breaks