3 ways to connect a Raspberry Pi 3 to a network using Wi-Fi

Raspberry Pi Wi-Fi
Published: by
Categories
Raspberry Pi

The latest Raspberry Pi comes equipped with onboard Wi-Fi and an Ethernet port. Establishing a network connection using Wi-Fi can be done in a couple of ways.

Introduction

From a hardware point of view, using Wi-Fi connectivity offers more freedom, but is a little more complicated to configure when compared with a wired connection. Using an Ethernet cable will need no configuration and will allow network connection with an automatic assigned dynamic IP address.

Using Wi-Fi will also assign a dynamic IP, but will need the network name (SSID) and the password (also called the passphrase or pre-shared key) of the wireless network.

This post will show how to configure a wireless network connection using the Raspi-config tool (Raspbian Stretch only), the Raspbain GUI (Raspbian Jessie and Raspbian Stretch) and the terminal. It will also show how to remove the settings again.

To get Wi-Fi connectivity on older Raspberry Pis, a USB Wi-Fi dongle can be used:

TP-Link TL-WN725N USB Wi-Fi Adapter
TP-Link TL-WN725N USB Wi-Fi Adapter

RoHS complient. Compact (0.73 x 0.58 x 0.27 inches). IEEE 802.11b, USB, IEEE 802.11n. 2.4 GHz TP-Link Wi-Fi adapter dongle. Up to 150 Mbps. Perfect for PC, Mac and Raspberry Pi.
Available from Amazon.com
USB 2.0 Wireless Wi-Fi Adapter Dongle
USB 2.0 Wireless Wi-Fi Adapter Dongle

Compact (2 x 1.5 x 0.6cm), generic, IEEE 802.11n, 2.4 GHz Wi-Fi adapter dongle. Up to 150 Mbps. Perfect for PC and Raspberry Pi.
Available from BangGood
TP-Link Nano AC600 USB Wi-Fi Adapter
TP-Link Nano AC600 USB Wi-Fi Adapter

RoHS complient. Compact (0.59 x 0.28 x 0.73 inches). 2. 4G/5G GHz TP-Link Wi-Fi adapter dongle. Up to 433 Mbps. Perfect for PC and Raspberry Pi.
Available from Amazon.com

Testing the network connection

Before or after the chosen method, an IP address will indicate that the Raspberry Pi is connected to a local network. To get the IP address, use the following command in the terminal:

hostname -I

The simplest way to test whether the Raspberry Pi is connected to the internet is by using the ping command from the terminal:

ping -c 5 google.com

Configuring the Wi-Fi settings using the terminal

Using the terminal to configure the Raspberry Pi 3’s Wi-Fi settings is the most accessible way, but also the most complicated. It offers a few more options when compared with the other options.

The terminal is accessible on all the versions of Raspbian, either from the boot sequence or from the terminal icon at the top of the GUI.

Raspbian Stretch GUI terminal
To access the terminal from the Raspbian Stretch’s GUI, use the terminal icon on the top right of the screen. Raspbian Jessie is the same.

The configuration settings for wireless connectivity is stored in the wpa_supplicant.conf file. To make a backup of the original file use:

sudo cp -p /etc/wpa_supplicant/wpa_supplicant /etc/wpa_supplicant/wpa_supplicant.original

To open and modify the wpa_supplicant.conf file:

sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

and add the following lines at the end (there might already be other lines added by Raspi-config – don’t remove them):

network={
 ssid="NETWORK_NAME" # required, keep the quotation marks
 psk="NETWORK_PASSWORD" # required, keep the quotation marks
 key_mgmt=WPA-PSK # required, WPA-PSK or WPA-EAP
 proto=RSN # optional, RSN for WPA2 or WPA for WPA1
 pairwise=CCMP # optional, CCMP for AES or TKIP for TKIP
 auth_alg=OPEN # optional, OPEN for WPA1/2 or SHARED or LEAP
}

The default optional settings will work in most cases, but read the # comments for custom settings. Comment out (using #) or remove the line to use the default setting. Press Ctrl + X to exit and save the changes.

To remove the wireless network settings, simply remove all the network lines again and reboot the Raspberry Pi using:

sudo reboot

Configuring the Wi-Fi settings using the Raspbian GUI

As from Raspbian Jessie, the GUI offers a very easy way to configure the Wi-Fi settings.

Raspbian GUI network settings
The network configuration icon for Raspbain Jessie. This icon looks a bit different in Raspbain Stretch.

The network configuration icon is situated on the top right section of the GUI (next to the sound icon). By clicking on it, the available wireless networks will be selectable, after which the password (Pre Shared Key) will be prompted.

Raspbian GUI Wi-Fi configuration
The Raspbian Stretch GUI’s network settings icon is situated on the top right of the screen.

The configuration settings for wireless connectivity is stored in the wpa_supplicant.conf file. To remove the wireless network settings, see using the terminal commands mentioned earlier.

Configuring the Wi-Fi settings using the Raspi-config tool

As from Raspbian Stretch, the Wi-Wi settings can be configured using Raspi-config, the GUI and the terminal. Using the Raspi-config tool is an easy way (when compared with using the terminal) to configure the wireless settings using Raspbian Stretch Lite. The Raspi-config tool can be accessed using the following terminal command:

sudo raspi-config

To use Raspi-config from the terminal, the keyboard arrow buttons are used to move to the desired menu item and it is selected with the Enter key. The Escape key can also be used to cancel certain options and to exit Raspi-config.

Raspbian Stretch Raspi-config Network Options
The Raspi-config tool.

To change the Wi-Fi settings, go to Network Options -> Wi-Fi. From the menu, select your country, enter the SSID (network name) and password. Once this is complete, Raspi-config will restart.

The configuration settings for wireless connectivity is stored in the wpa_supplicant.conf file. To remove the wireless network settings, see using the terminal commands mentioned earlier.

Raspberry Pi accessories

To get started with the Raspberry Pi, you might need some of the following accessories:

Please support us by using these links - they come at no additional cost to you, but we get a little commission each time they are used. These and others are available from Amazon.com and BangGood.

We have tested most of these products ourselves. Other selection criteria include affordability, quality, availability and average user rating and popularity by other buyers.

Links will open in a new window.
(Dead or old links can be reported in the comments section below.)

Behind the Scenes is a free, informative website. If you find value in any of our content, please consider making a donation to our cause.
Donate via PayPal

Save, share & discuss

Your comment is important, but don't be a knob. Keep it constructive and polite.

Leave a Reply

Your email address will not be published. Required fields are marked *

More Raspberry Pi related posts