A step-by-step guide on how to connect your Raspberry Pi to a wireless network

Learn how to set up wifi connection on your Raspberry Pi using the command line interface and a text editor. This guide will help you connect your Pi to a WiFi network quickly and easily. …


Updated September 3, 2023

Need help with your Raspberry Pi?
Contact Me!

Do you love silly Raspberry Pi Projects?
Check out my this YouTube Channel!


Learn how to set up wifi connection on your Raspberry Pi using the command line interface and a text editor. This guide will help you connect your Pi to a WiFi network quickly and easily. To connect your Raspberry Pi to a wireless network, follow these simple steps:

  1. Enable SSH

    • Before we begin, ensure that your Raspberry Pi has already been set up and you have access to the command line interface either through an HDMI monitor, TV or using SSH (if you have another computer).
    • To enable SSH, open the terminal and type: sudo raspi-config, then navigate to Interfacing Options > SSH > Enable SSH. Exit the program by typing exit and selecting yes when prompted to reboot.
  2. Find your WiFi network’s SSID

    • You will need the name (SSID) of the WiFi network you want to connect to. Open a web browser on another device that is already connected to this network, go to www.routerlogin.com or www.mywifi.com and note down the network name.
  3. Create a wpa_supplicant file

    • Open a text editor (e.g., nano) in the terminal by typing sudo nano /etc/wpa_supplicant/wpa_supplicant.conf. Add the following lines to the end of the file:
      network={
          ssid="YOUR_NETWORK_SSID"
          psk="YOUR_NETWORK_PASSWORD"
          key_mgmt=WPA-PSK
      }
      
    • Replace YOUR_NETWORK_SSID and YOUR_NETWORK_PASSWORD with the actual SSID and password for your network. Save the file by pressing Ctrl+O, then Enter to confirm the filename, and Ctrl+X to exit the editor.
  4. Edit thedhcpcd.conf

    • Open another text editor in the terminal using sudo nano /etc/dhcpcd.conf. Add the following lines at the bottom of the file:
      interface wlan0
      static ip_address=192.168.1.100/24
      static routers=192.168.1.1
      static domain_name_servers=8.8.8.8.8 8.8.4.4
      
    • Replace 192.168.1.100 with an unused IP address on your network (e.g., if the DHCP server assigns addresses from .50 to .99, you could use .10). Save and exit the file as before.
  5. Connect to WiFi

    • Reboot your Raspberry Pi by typing sudo reboot. Wait for it to restart, then run iwconfig in the terminal to verify that it has connected successfully. You should see a wireless connection under wlan0, with an IP address assigned from your router.
    • If you encounter any issues, check the dmesg | grep wlan0 command for error messages and try again.
  6. Test your connection

    • Once connected, you can test your internet access by pinging a website (e.g., ping google.com). You should receive responses with no packet loss.

That’s it! Your Raspberry Pi is now connected to the WiFi network. Remember that these settings are stored on the SD card and will persist across reboots, so you only need to perform steps 2-4 once. However, if you ever change your network password or want to connect to a different network, repeat steps 3-5 with the new information.

Please note: This guide assumes that you are using a 2.4GHz wireless network. If your network operates on the 5GHz band, you will need to modify the /etc/wpa_supplicant/wpa_supplicant.conf file to specify band=5ghz.