Set up Wi-Fi on your Raspberry Pi

Greetings! This tutorial has worked for me many times and I hope it will work for you, but obviously YMMV. I’m going to show you how to set up your Raspberry Pi so that it will connect to your home Wi-Fi network every time it starts up by editing just a couple of files. It’s really simple and will be done in a few minutes.

The Dongle

Obviously as this is a tutorial about connecting your Raspberry Pi to a Wi-Fi network, you’re going to need the correct equipment to create a Wi-Fi link. The new Raspberry Pi 3 Model B comes with on-board Wi-Fi negating the need for a Wi-Fi dongle as with previous versions of the Raspberry Pi, but whether you use a dongle or not the instructions are the same pretty much.

I have more Raspberry Pis than I’m going to admit to, but whenever I need a Wi-Fi connection for them I always use this dongle as they are incredibly reliable. Obviously if the project you are working on needs extended Wi-Fi range, you’ll need a more powerful Wi-Fi antenna.

By the way, I get most of my Raspberry Pi bits and bobs from Mod My Pi and they are brilliant. I receive no sponsorship money from them, they just have great customer service and everything I normally need.

Let’s Get Started

Firstly we need to backup and edit your WPA Supplicant configuration file:

sudo cp /etc/wpa_supplicant/wpa_supplicant.conf{,.backup}

Next we are going to use the nano text to edit the file wpa_supplicant.conf:

sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

When you open the file, it will already be populated with the following two lines. We are going to add our own configuration underneath these lines:

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev  
update_config=1

The entire file should end up looking like this, but obviously you’re going to need to change the values ssid= and psk= to reflect your network setup:

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev  
update_config=1

network={
        ssid="MyAmusingAccessPointName"
        psk="not a lame password at all really"
        proto=RSN
        key_mgmt=WPA-PSK
        pairwise=CCMP
        auth_alg=OPEN
}

Exit out of the nano text editor by holding down the Control key and tapping the letter X, when prompted select the letter Y and then finally press Enter. You will then be back at your normal command prompt.

Editing Network Interfaces

Just to be careful, we are going to backup your /etc/network/interfaces file with:

sudo cp /etc/network/interfaces{,.backup}

Then open your file in nano with:

sudo nano /etc/network/interfaces

After much trial and error, this is what my network interfaces file looks like:

# interfaces(5) file used by ifup(8) and ifdown(8)

# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'

# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d

auto lo
iface lo inet loopback

iface eth0 inet dhcp

allow-hotplug wlan0
iface wlan0 inet dhcp
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

Restart your Raspberry Pi

With all that done, restart your Raspberry Pi with the following command:

sudo reboot

Once your Raspberry Pi has rebooted you need to log back in, then run the following command:

iwconfig

If everything has been successful, you should hopefully see something like this:

wlan0     IEEE 802.11bgn  ESSID:"MyAmusingAccessPointName"
          Mode:Managed  Frequency:2.452 GHz  Access Point: 00:C0:CA:6C:99:29
          Bit Rate=54 Mb/s   Tx-Power=31 dBm
          Retry short limit:7   RTS thr:off   Fragment thr:off
          Power Management:on
          Link Quality=70/70  Signal level=-32 dBm
          Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0
          Tx excessive retries:0  Invalid misc:0   Missed beacon:0

lo        no wireless extensions.

eth0      no wireless extensions.

Conclusion

All done, you now have a fully wireless Raspberry Pi. Have fun and get in touch if you need any help.