IW is a configuration utility for wireless devices and supports most if not all drivers implemented officially in the Linux kernel. It can be used to setup and connect to wifi networks as well as configure access points/hotspots on supported modems. It replaces the older iwconfig utility which is not recommended for use.
The IP utility is a routing tool that is used to configure network interfaces on your linux host and to configure bridges between devices.
To list all wireless devices the command iw dev or /sbin/iw dev can be used and the response could look something like this:
phy#0
Interface wlp1s0
ifindex 4
wdev 0x1
addr 04:f0:21:3f:0a:a3
type managed
txpower 23.00 dBm
multicast TXQ:
qsz-byt qsz-pkt flows drops marks overlmt hashcol tx-bytes tx-packets
0 0 0 0 0 0 0 0 0
To make sure that the device is up and running issue:
ip link show wlp1s0
In this case, the wireless device is wlp1s0 and for which command return the following:
4: wlp1s0: UP> mtu 1500 qdisc noqueue state DOWN mode DORMANT group default qlen 1000
link/ether 04:f2:24:3d:2b:d9 brd ff:ff:ff:ff:ff:ff
If the device is not active and ‘UP’ it can be set active using:
sudo ip link set wlp1s0 up
To see if the device is connected to a network or not, issue:
iw wlp1s0 link
Connected to b3:fa:d4:32:64:12 (on wlp1s0)
SSID: 524wifi-5G
freq: 5200
RX: 4602636 bytes (28600 packets)
TX: 17664 bytes (150 packets)
signal: -53 dBm
rx bitrate: 360.0 MBit/s VHT-MCS 8 40MHz short GI VHT-NSS 2
tx bitrate: 6.0 MBit/s
bss flags: short-slot-time
dtim period: 3
beacon int: 100
If not, it simply returns ‘Not connected’
To see available wifi networks in range use the scan function of the modem:
iw wlp1s0 scan
********************SNIPPET*******************
BSS d0:21:f9:32:64:bb(on wlp1s0)
last seen: 7092.798s [boottime]
TSF: 1755910453320 usec (20d, 07:45:10)
freq: 5220
beacon interval: 100 TUs
capability: ESS Privacy SpectrumMgmt ShortSlotTime RadioMeasure (0x1511)
signal: -71.00 dBm
last seen: 1704 ms ago
Information elements from Probe Response frame:
SSID: Techship
Supported rates: 6.0* 9.0 12.0* 18.0 24.0* 36.0 48.0 54.0
DS Parameter set: channel 44
Country: SE Environment: Indoor/Outdoor
Channels [36 – 36] @ 23 dBm
Channels [40 – 40] @ 23 dBm
Channels [44 – 44] @ 23 dBm
Channels [48 – 48] @ 23 dBm
Channels [52 – 52] @ 23 dBm
Channels [56 – 56] @ 23 dBm
Channels [60 – 60] @ 23 dBm
Channels [64 – 64] @ 23 dBm
Channels [100 – 100] @ 30 dBm
Channels [104 – 104] @ 30 dBm
Channels [108 – 108] @ 30 dBm
Channels [112 – 112] @ 30 dBm
Channels [116 – 116] @ 30 dBm
Channels [120 – 120] @ 30 dBm
Channels [124 – 124] @ 30 dBm
Channels [128 – 128] @ 30 dBm
Channels [132 – 132] @ 30 dBm
Channels [136 – 136] @ 30 dBm
Channels [140 – 140] @ 30 dBm
RSN: * Version: 1
* Group cipher: CCMP
* Pairwise ciphers: CCMP
* Authentication suites: PSK
* Capabilities: 1-PTKSA-RC 1-GTKSA-RC (0x0000)
BSS Load:
* station count: 4
* channel utilisation: 19/255
available admission capacity: 31250 [32us]
********************SNIPPET*******************
Make sure that the country parameter is correct, if not you can set the country code with the following:
sudo iw reg set SE
This ensures that the modem follows country-specific frequency regulations!
To connect to a password protected network (e.g. WPA version 1,2 or 3) a configuration file called wpa_supplicant.conf that handles the security protocol is needed:
wpa_passphrase SSID >> /etc/wpa_supplicant.conf
enter wifi password and hit enter
The generated output would look something like this:
network={
ssid=”524wifi-5G”
#psk=”password”
psk=5abc7d89f8e9d8c7aa6b8c7d223e520d26a13e932bf0acb1d4580461d6d2ba8d
}
If sudo privileges aren’t enough; login as root with: sudo -s and issue the above again.
When the file has been created it can be run in the background using:
sudo wpa_supplicant -B -D wext -i wlan0 -c /etc/wpa_supplicant.conf
Then check once more if the connection was successful with:
iw wlp1s0 link
The last step is to request an IP adress from the host server via DHCP client:
dhclient wlp1s0
Issue ip addr show wlp1s0 to check assigned ip address and
if you have recieved one you are ready to surf!
For further information and features see:
en:users:documentation:iw [Linux Wireless] (kernel.org)
wpa_supplicant – ArchWiki (archlinux.org)
networking:iproute2 [Wiki] (linuxfoundation.org)
Note: Tested on Ubuntu 22.04 kernel 5.19