KB: raspberry pi wifi setup from command line

From Yombo
Jump to: navigation, search

KB Articles

KB Article
Keywords Raspberry Pi, Networking

See also

Details

With any stock Raspian (Raspberry Pi Stretch) image, which includes the Yombo images, the wireless configuration file is located in /etc/wpa_supplicant/wpa_supplicant.conf.

Scanning for networks

To scan for WiFi networks, use the command: sudo iwlist wlan0 This will list all available WiFi networks, along with other useful information. Look for:

  1. 'ESSID:"testing"' is the name of the WiFi network.
  2. 'IE: IEEE 802.11i/WPA2 Version 1' is the authentication used. In this case it's WPA2, the newer and more secure wireless standard which replaces WPA. This guide should work for WPA or WPA2, but may not work for WPA2 enterprise.

Setup WiFi

First, become Superman (sudo).

sudo su -

Now, lets change into the correct directory.

cd /etc/wpa_supplicant/

Lets use a tool to help use create the required items (change the SSID and Password). This tool requires a password between 8 and 63 characters. If your password is too short, we suggest using a stronger password. Otherwise, you can just add the section directly to the configuration file.

wpa_passphrase "SSID_NETWORK_NAME" "MYSECRETPASSWORD" >> wpa_supplicant.conf

Besure to review the file and set the country code:

pico wpa_supplicant.conf

Example Configuration

Here's what a sample configuration file will look, notice the country code has been set to US. file will look something like this:

country=US
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
        ssid="YomboNetwork"
        #psk="GTe5qjtffwxGHh3D"
        psk=279cf2f37f7a0bedfd638fc7c61e2b2489b9b7f2435b07a905174aab01537c16
}

You can add multiple network blocks to support multiple WiFi networks:

country=US
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
        ssid="YomboNetwork"
        #psk="GTe5qjtffwxGHh3D"
        psk=279cf2f37f7a0bedfd638fc7c61e2b2489b9b7f2435b07a905174aab01537c16
}
network={
        ssid="Shed"
        #psk="GTe5qjtffwxGHh3D"
        psk=279cf2f37f7a0bedfd638fc7c61e2b2489b9b7f2435b07a905174aab01537c16
}

Once you have validated the country code everything looks fine, simply reboot the Raspberry Pi (RPi).

reboot

Unsecured Networks

If the network you are connecting to does not use a password, use the following configuration example:

network={
    ssid="guest"
    key_mgmt=NONE
}

Hidden Networks

If you are using a hidden network, an extra option in the wpa_supplicant file, scan_ssid, may help connection:

network={

   ssid="HiddenNetwork"
   scan_ssid=1
   psk="Your_wifi_password"

}

Find your IP address(es)

After the system reboots, login and use the ifconfig command to find the ip addresses. On this RPI, there is both a wired and wireless connection. The wired connection is "eth0" (10.155.100.179), while the wireless connection is "wlan0" (10.155.100.30):

pi@raspberrypi:~ $ ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.155.100.179  netmask 255.255.255.0  broadcast 10.155.100.255
        inet6 fe80::a5db:f050:2dfa:9d72  prefixlen 64  scopeid 0x20<link>
        ether b8:27:eb:30:39:aa  txqueuelen 1000  (Ethernet)
        RX packets 168  bytes 20904 (20.4 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 86  bytes 12716 (12.4 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1  (Local Loopback)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.155.100.30  netmask 255.255.255.0  broadcast 10.155.100.255
        inet6 fe80::61e6:9a1f:41ee:f4e5  prefixlen 64  scopeid 0x20<link>
        ether b8:27:eb:65:6c:ff  txqueuelen 1000  (Ethernet)
        RX packets 125  bytes 16848 (16.4 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 43  bytes 6858 (6.6 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

Final Thoughts

We highly suggest leaving the IP address as DHCP, but using your cable modem's router configuration the set a static ip address. Check your router manual for details.

On this RPi, the wlan0 is set on the router to always assign this device 10.155.100.30 as this RPi is typically headless without a wired ethernet connection.

This page was last edited on 24 August 2018.