cheatsheet.zwischenspeicher.info

Some tech documentation and snippets, finally organized.
Posts tagged as wifi

CLI Wifi setup with iw

This is a quick overview of the necessary commands and configuration to connect to wireless networks from the command line with iw and wpa_supplicant.

Preparation

Identify available Wifi adapters:

$ iw dev

Check the device status (from now on using device wlan0):

$ ip link show wlan0

Bring up the interface and scan for available networks:

$ ip link set wlan0 up
$ iw wlan0 scan

Now there are several possibilities to actually connect to the targeted wireless network:

Solution 1 - manually with wpa_supplicant and dhclient

Generate the wpa_supplicant configuration file (replace $SSID with the network's SSID, hit return and enter the passphrase):

$ wpa_passphrase $SSID >> /etc/wpa_supplicant.conf

Note: You might want to remove the (commented out) clear text passphrase from the resulting wpa_supplicant.conf file.

Connect to the wireless network and obtain an IP address:

$ wpa_supplicant -B -D wext -i wlan0 -c /etc/wpa_supplicant.conf
$ dhclient wlan0

Solution 2 - using wpa_supplicant with ifup/down

Add the Wifi configuration to your /etc/network/interfaces (of course $SSID and $PASSPHRASE have to be replaced by the actual values):

### File: /etc/network/interfaces

auto wlan0
iface wlan0 inet dhcp 
    wpa-ssid $SSID
    wpa-psk  $PASSPHRASE

To avoid the clear text passphrase in your interfaces file, you can run

$ wpa_passphrase $SSID

As before, you'll have to replace $SSID with the network's real SSID, hit return and enter the passphrase. When done, replace the $PASSPHRASE in the above /etc/network/interfaces file with the resulting 256bit value of psk.

Now bring up the interface, connect to the wireless network and obtain an IP address as usual with

$ ifup wlan0

Note: This solution will (try to) automatically connect to the configured wireless network when the system boots.

Checking the link

Finally, use ip or ifconfig to check the link status and ping a known host to verify connectivity:

$ ip addr show wlan0
$ ifconfig wlan0
$ ping -c 2 devuan.org