How to configure Wi-Fi on Raspberry Pi

How to configure Wi-Fi on Raspberry Pi

This post is a quick how-to article for configuring Wi-Fi on Raspberry Pi.

The method of configuring a Wi-Fi on Raspberry Pi has changed with the release of Raspbian Jessie. Wi-Fi configuration settings are no longer made through the /etc/network/interfaces file, but are instead made through the /etc/wpa_supplicant/wpa_supplicant.conf file.

Preparation

  1. Begin by connecting the Wi-Fi device to one of the USB ports on your Raspberry Pi.
  2. Check whether the Wi-Fi device is natively supported by Raspbian, using the following command:
    ifconfig wlan0

    If the command produces the following output, it means Raspbian does not natively include drivers for the Wi-Fi device, or the Wi-Fi device chipset firmware requires updating.

    wlan0: error fetching interface information: Device not found

Drivers

  1. To resolve driver and/or firmware issues for your Wi-Fi device, use the following sections as a guide:
    Sagem XG-760A
  2. Once drivers and/or firmware issues have been resolved, recheck the Wi-Fi device’s status in Raspbian using the following command:
    ifconfig wlan0

    The command should now produce output similar to the following:

    wlan0               Link encap:Ethernet  HWaddr 00:60:b3:56:7e:75
                        inet6 addr: fe80::f026:26e6:e5dd:65ab/64 Scope:Link
                        UP BROADCAST MULTICAST  MTU:1500  Metric:1
                        RX packets:0 errors:0 dropped:0 overruns:0 frame:0
                        TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
                        collisions:0 txqueuelen:1000
                        RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

Configuration

  1. To scan for visible access points, use the following command:
    sudo iwlist wlan0 scan | grep "ESSID:"

    The command will produce output similar to the following:

                        ESSID:"Internet"
                        ESSID:"TPG 42A8"
                        ESSID:"wlan-ap"
                        ESSID:"TelstraAF8526"
  2. Use the nano text editor to modify the /etc/wpa_supplicant/wpa_supplicant.conf file with the following command:
    sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

    The nano text editor will open and display the contents of the /etc/wpa_supplicant/wpa_supplicant.conf file.

  3. Press Alt + / to move to the last line of the file.
  4. Add the following lines to the end of the file:
    network={
        ssid="<ESSID>"
        psk="<password>"
    }

    Adjust the values to suit your desired Wi-Fi network environment.

    Value Description
    ssid="<ESSID>" Specifies the name of the Wi-Fi network. Use the desired ESSID value from the previous step.
    psk="<password>" Specifies the Wi-Fi password. For most home routers, this password can be found on a sticker on the back of the router.
  5. Press Ctrl + X to exit nano, press Y to save changes, and press Enter to confirm the existing filename.
  6. Restart the Wi-Fi interface, using the following command:
    sudo ifdown wlan0 && sudo ifup wlan0
  7. Show the interface configuration, using the following commands:
    ifconfig wlan0

    The command produces output similar to the following:

    wlan0     Link encap:Ethernet HWaddr 00:60:b3:56:7e:75
              inet addr:192.168.0.100  Bcast:192.168.0.255  Mask:255.255.255.0
              inet6 addr: fe80::980e:5e53:a722:256b/64 Scope:Link
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              RX packets:25 errors:0 dropped:0 overruns:0 frame:0
              TX packets:41 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1000
              RX bytes:3338 (3.2 KiB)  TX bytes:8492 (8.2 KiB)

    The Raspberry Pi is now configured to use Wi-Fi networking.

Raspberry Pi is a trademark of the Raspberry Pi Foundation.

Disclaimer: No liability is accepted (whether under the law of contract, the law of torts or otherwise) in relation to the contents of, or use of, or otherwise in connection with, this website to the extent that the website is provided free-of-charge, for any direct loss; for any indirect, special or consequential loss; or for any business losses, loss of revenue, income, profits or anticipated savings, loss of contracts or business relationships, loss of reputation or goodwill, or loss or corruption of information or data. These limitations of liability apply even when expressly advised of the potential loss.

Leave a Reply