Raspberry Pi WiFi

Looking to learn how to set up the Raspberry Pi WiFi then this is the guide to check out. I go into several topics in this guide that will help anyone grasp an understanding of how the WiFi is set up on the Raspberry Pi.

In this guide, I will show you how to set up the Raspberry Pi WiFi via command line and also how to do it via the GUI within Raspbian. I also touch on setting up the WiFi country and predictable network interface names. It’s pretty straightforward, but for anyone who is entirely new to the Pi, these are vital steps that you will need to undertake to be able to setup your Raspberry Pi correctly.

Ultimate Books of Pi

If you want to see how to do this visually then check out the video I have prepared below. As always if you like what you see, then please subscribe so you can stay up to date with all the latest and greatest Raspberry Pi projects, guides and much more.

Equipment

I used the following equipment for this guide on the Raspberry Pi setup Wifi.

Required

Raspberry Pi

Micro SD Card if you’re using a Raspberry Pi 2, 3 or B+ or SD Card (8GB+ Recommended)

Wifi dongle (Raspberry Pi 3 has WiFi has inbuilt)

Optional

USB Keyboard

USB Mouse

Raspberry Pi Case

In this guide, I use the default operating system for the Pi. This operating system (OS) is known as Raspbian, and if you haven’t got it installed, then you can follow my guide on how to install Raspberry Pi NOOBS (Raspbian).

Setting up Raspberry Pi WiFi Command Line

If you don’t have the option of setting up the WiFi connection up through the graphical user interface (GUI), then the command line interface (CLI) is the next best thing. It’s a little harder but still relatively easy to set up.

1. While in the terminal on the Raspberry Pi enter the following command.

sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

2. At the bottom of this file, add the following lines.

network={
ssid="The SSID of your network (eg. Network name)"
psk="Your Wifi Password"
}

3. Exit nano by typing ctrl+x and then y to save.

4. The Raspberry Pi should in most cases notice the changes to the wpa_supplicant file and automatically make a connection to the Raspberry Pi.

If it doesn’t, you can force it to check by doing the following commands.

4a. This command takes the network interface down, meaning we can restart it to reload the wpa_supplicant file.

sudo ifdown wlan0

4b. This command brings the network interface up, upon it loading up, it will load the wpa_supplicant file back in.

sudo ifup wlan0

5. You can check if it has successfully connected by using ifconfig wlan0. The inet addr field should have an IP address in it.

If you’re on Raspbian Stretch the ifup command will likely not work, you will get an error that says something like the following “ifdown: unknown interface wlan0“. As a workaround to this issue, you can use either of the following commands sudo ifconfig wlan0 up or sudo ifconfig wlan0 down

Also, on Stretch, wlan0 may no longer be correct, use ifconfig to see the new name. For more information check out the predictive network names section further down this page.

If you’re having trouble connecting, then be sure to make sure that the Pi supports the WiFi dongle. It is also possible you have the SSID wrong, to scan and check, use sudo iwlist wlan0 scan and check the essid field. This field should be the same as what you entered in the ssid field.

Setting up Raspberry Pi Static IP via Command Line

1. Setting up a static IP address for your Wi-Fi connection is a simple task that involves just modifying a single file.

While your WLAN connection should be identified as wlan0 you can verify this by utilizing the following command on your Raspberry Pi. Any Wi-Fi interfaces will be prefixed with wl.

ifconfig

2. Once you have verified your Wi-Fi connections interface name we can go ahead and modify the dhcpd config file. Begin modifying this file by running the command shown below.

DHCPD is the daemon that provides the Dynamic Host Configuration Protocol service to the network. Basically, it helps things like negotiating the IP address that the device should be using.

sudo nano /etc/dhcpcd.conf

3. Within this file, you need to add the following lines to the end of the file making changes where applicable. We will describe what each of these lines do below.

interface wlan0
static ip_address=192.168.1.115/24
static routers=192.168.1.1
static domain_name_servers=192.168.1.1

interface wlan0 – This line defines the interface that we are wanting to modify the configuration for. If your wireless connection is not running on wlan0 make sure you change the interface name here.

static ip_address=192.168.1.115/24 – This is the IP address and size (/24) that you want DHPCD to acquire from the network. Make sure this is an unused address otherwise there will be conflict issues.

static routers=192.168.1.1 – This line defines the IP address of your router (or gateway). Make sure this matches the IP address of your router so DHPCD knows where to connect.

static domain_name_servers=192.168.1.1 – This line defines the DNS addresses that the DHCP Daemon will utilize for this interface. Typically this can just be set to the routers IP address.

4. You can now save the file by pressing CTRL + X then Y and finally pressing ENTER.

5. Now to make sure these changes are properly loaded in you should reboot your Raspberry Pi by running the following command in the terminal.

sudo reboot

6. You Raspberry Pi once rebooted should now stick to using the static IP address that you defined. You can verify your Raspberry Pi’s local IP address by running the following command.

hostname -I

It is also recommended that you also set a static IP address in your router itself for the device. This will ensure that there is no chance that another device will be handed the local IP address.

Setting up Raspberry Pi WiFi via GUI

Using the GUI (Graphical User Interface) is the easiest way to set up WiFi for the Raspberry Pi as everything can be done quickly within the interface.

1. You will need to have your Raspberry Pi connected to a monitor with a mouse and keyboard.

2. On the Raspbian desktop locate the WiFi icon in the upper right-hand corner of the desktop.

Raspbian WiFi Icon Location

3. It will now scan for WiFi networks and display any that it can find. Click on the network that you wish to connect to.

Raspbian WiFi Networks

4. If your network is password protected, then you will be prompted to enter a password. Enter the relevant password to connect to the WiFi network.

Raspbian WiFi Password Field

5. The Pi should now connect to the WiFi network, and the icon should have now changed to a blue WiFi logo.

Raspbian WiFi Signal

Updating WiFi Country

It is also a good idea to set the country for your WiFi signal. Selecting the country in the GUI is pretty easy to do.

1. Go to the menu icon, then preferences then select Raspberry Pi configuration.

Raspbian Configuration Menu

2. In this menu, go to the localization tab and select “Set WiFi Country

Raspbian Set WiFi Country

3. Select your country and hit save.

Raspbian Select WiFi Country

4. Your WiFi country should now be updated.

Predictable Network Names

Predictable network names caused quite a bit of confusion when it was first introduced to Raspbian in the Stretch update. Since then, it’s been rolled back and can be activated manually.

You will find that predictable network names are useful when a device has multiple network connections. Instead of naming the interfaces wlan0 or eth0, it instead names them en (ethernet) or wl (wlan) followed by an x. It is lastly followed by a mac address (without any colons). For example, a wlan connection with a predictable network name would be called wlx6c198f049e5c

The naming was rolled back because most Raspberry Pi setups will only use a single Ethernet and WiFi connection. Also, a lot of tutorials rely on the naming of wlan0 or eth0. A lot of these tutorials weren’t updated to reflect the new naming which led to a lot of headaches.

The predictable naming comes in handy if you have three or more network interfaces. For example, on reboot, wlan0 might become wlan1 and vice versa. This switch of interface names may cause a lot of issues for people who rely on the interface names in their programs.

Predictable network names provide a naming convention that makes sense and is easy for a developer to predict.

If you wish to turn predictable network names on for use with the Raspberry Pi WiFi or ethernet, then do the following steps.

1. In the terminal, enter the following command.

sudo raspi-config

2. Go to network options, then select network interface names. In here, select yes to turn on predictable network interface names.

3. Now exit raspi-config. You can test to see if predictable network names are working by entering the following command after you have plugged in a new network device. Devices that are currently connected might still have the old name, and a restart will fix this issue.

sudo ifconfig

Raspbian Network Predictable Names

It is important to note that the onboard WiFi for the Raspberry Pi 3, and zero will continue to use wlan0. Despite whether predictable naming is turned on or off.

Now that you have your WiFi setup you might be interested in doing a bit more with it. For example, setting up a Raspberry Pi WiFi access point is a great way to help extend WiFi coverage throughout your house. You will need to have ethernet connected to the Pi as a WiFi to WiFi setup isn’t great for speed.

If you’re having trouble getting the WiFi to connect, then be sure to check that the Pi supports the dongle. This issue is one of the most common problems when setting up the Raspberry Pi WiFi.

I hope that this guide has been able to show you all the steps to set up WiFi and you haven’t run into any issues. If you require further assistance, I highly recommend that you head over to our forums.

Ultimate Books of Pi Bottom
Pi My Life Up's Crash Course
to the Raspberry Pi

Pi My Life Up's Crash Course

to the Raspberry Pi

Subscribe to our email list to get the

Crash Course delivered straight to your inbox

Please check your inbox for a confirmation email!