17.4. Configuring Wireless Networking
Wireless configuration adds three layers to everything this chapter has done so far: the radio needs firmware and a regulatory domain before it transmits, association and authentication are a multi-step handshake rather than a cable, and the credentials live in profiles that must be treated as secrets. The same backend split applies - on Debian, wireless is overwhelmingly a NetworkManager affair, because roaming, re-association, and passphrase handling are what it was built for.
The example machine has no physical wireless adapter, so this section
exercises the software path end to end with the kernel's mac80211_hwsim
module: it creates two software radios, one used as the client (wlan0)
and one running hostapd as a practice access point (wlan1). Every
scan, association, WPA handshake, and DHCP exchange below runs through
the real NetworkManager and wpa_supplicant code - the commands are the
ones a physical adapter uses. What this setup cannot exercise is vendor
firmware loading and physical radio behavior; the firmware paragraphs
describe those from the documentation they come from. On hardware, the
same commands run unchanged once the driver and firmware are in place.
17.4.1. Firmware, Radio State, and Wireless Device Discovery
A wireless chipset is two devices in one: a PCIe or USB radio, and
firmware that must be loaded before the radio does anything. Linux
drivers for common chipsets ship in the kernel, but much of the firmware
is distributed separately, in the non-free-firmware archive component
that the installer offers to enable (Chapter 2 and
Chapter 7 cover the component itself). The packages
are organized by vendor: firmware-iwlwifi for Intel, firmware-realtek
for Realtek, firmware-atheros for Atheros and Qualcomm, and
firmware-brcm80211 for Broadcom. When a wireless interface exists as a
link but never carries traffic, the kernel ring buffer is the first place
to look - sudo dmesg | grep -iE 'wlan|wifi|firmware' shows both
successful firmware loads and the "failed to load" messages that name
the missing file; iw list then shows the radio's real capabilities.
Regulatory limits - which channels may be used and at what power in which
country - come from the wireless-regdb package and can be checked with
iw reg get.
With the hardware accounted for, the discovery sequence is short. Load the practice radios, in a root shell:
# modprobe mac80211_hwsim radios=2
modprobe prints nothing on success. Two radios now exist; check that
neither is blocked. rfkill lists every radio's kill state:
# rfkill list
0: phy0: Wireless LAN
Soft blocked: no
Hard blocked: no
1: phy1: Wireless LAN
Soft blocked: no
Hard blocked: no
rfkill command |
Description |
|---|---|
list |
Show each radio's soft and hard block state. |
block TYPE |
Software-block the radios of one type (wifi, bluetooth, ...). |
unblock TYPE |
Clear a software block. |
A soft block is an operating-system switch - toggled by rfkill itself,
by a desktop's airplane mode, or by nmcli radio wifi off. A hard
block is a physical switch or a firmware setting, and no amount of
software clears it: flip the switch. A wireless link that exists but
stays silent is very often just blocked, which is why this check comes
before any configuration. Both radios are clear here. Now find the
interfaces the kernel gave them:
$ ip -br link show wlan0
wlan0 DOWN e6:da:76:f6:d8:11 <NO-CARRIER,BROADCAST,MULTICAST,UP>
wlan0 exists as a link but is DOWN with no carrier - an unconnected
wireless interface, exactly what an unused radio looks like. The
wireless-specific view comes from iw, which organizes by physical
radio (phy) and the interfaces on it, run as root:
# iw dev
phy#1
Unnamed/non-netdev interface
wdev 0x100000002
addr 02:00:00:00:01:00
type P2P-device
txpower 20.00 dBm
Interface wlan1
ifindex 5
wdev 0x100000001
addr 4a:40:bb:21:10:57
type managed
txpower 20.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
phy#0
Interface wlan0
ifindex 4
wdev 0x1
addr e6:da:76:f6:d8:11
type managed
txpower 20.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
iw command |
Description |
|---|---|
dev |
List radios and their interfaces, with type and transmit power. |
dev IF link |
Show the current association: BSSID, SSID, signal, bitrates. |
dev IF info |
Show one interface's radio, channel, and mode. |
dev IF station dump |
Show the associated station's counters and state. |
list |
Show each radio's full capabilities (bands, channels, cipher suites). |
Each phy is a radio; each Interface line is a device name with a
type. managed is the ordinary client mode. The unnamed P2P-device
interface on phy#1 is the Wi-Fi Direct virtual interface that
wpa_supplicant registers when it claims a radio; NetworkManager's
device list below shows the same capability as its p2p-dev-* entries.
NetworkManager's own radio and device views confirm the same facts from
the management side:
$ nmcli radio wifi
enabled
$ nmcli device status
DEVICE TYPE STATE CONNECTION
eth1 ethernet connected lab-dhcp
lo loopback connected (externally) lo
wlan0 wifi disconnected --
wlan1 wifi disconnected --
p2p-dev-wlan0 wifi-p2p disconnected --
p2p-dev-wlan1 wifi-p2p disconnected --
eth0 ethernet unmanaged --
hwsim0 unknown unmanaged --
eth1 is back under its saved profile, as Section 17.3.4 predicted. The
two wlan devices are visible but unconnected; the p2p-dev-* rows are
the Wi-Fi Direct pseudo-devices, and hwsim0 belongs to the software
radio module itself - none of these needs configuration. A machine with
a physical adapter shows the same rows minus hwsim0, and with a
predictable name like wlp2s0 instead of wlan0 when renaming is
enabled.
The practice access point runs on netlab1's second radio, so one machine
plays both roles. hostapd turns a managed interface into an AP; its
configuration names the interface, the SSID, and the WPA settings:
# /etc/hostapd/ch17.conf
interface=wlan1
driver=nl80211
ssid=LabWifi
hw_mode=g
channel=6
wpa=2
wpa_passphrase=handbookpass
wpa_key_mgmt=WPA-PSK
rsn_pairwise=CCMP
| hostapd directive | Description |
|---|---|
interface |
The interface to run as an access point. |
driver=nl80211 |
Use the kernel's standard wireless configuration API. |
ssid |
The network name clients see. |
hw_mode / channel |
The band and channel; g is 2.4 GHz. |
wpa=2 |
WPA2/RSN only (WPA3 selects SAE in wpa_key_mgmt instead of WPA-PSK). |
wpa_passphrase |
The WPA pre-shared key, 8–63 characters. |
wpa_key_mgmt=WPA-PSK |
Personal authentication: one shared passphrase. |
rsn_pairwise=CCMP |
AES encryption for the data frames. |
The AP interface needs to be up and to carry the segment's gateway address. Both commands are silent:
# ip link set wlan1 up
# ip addr add 10.17.0.1/24 dev wlan1
Start hostapd, which runs in the background with -B:
# hostapd -B -P /run/hostapd-ch17.pid /etc/hostapd/ch17.conf
wlan1: interface state UNINITIALIZED->ENABLED
wlan1: AP-ENABLED
hostapd took the radio into AP mode and reported the state transition. DHCP for the wireless segment comes from dnsmasq on the same machine, with a second config file:
# /etc/dnsmasq.d/ch17-wifi.conf
interface=wlan1
bind-interfaces
dhcp-range=10.17.0.100,10.17.0.150,255.255.255.0,1h
dhcp-option=option:router,10.17.0.1
dhcp-option=option:dns-server,10.17.0.1
dhcp-authoritative
domain=wifi.example
local=/wifi.example/
host-record=ap.wifi.example,10.17.0.1
Then restart dnsmasq to pick up the new file; the command is silent:
# systemctl restart dnsmasq
The AP's own view of its radio confirms the configuration took:
# iw dev wlan1 info
Interface wlan1
ifindex 5
wdev 0x100000001
addr 4a:40:bb:21:10:57
ssid LabWifi
type AP
wiphy 1
channel 6 (2437 MHz), width: 20 MHz (no HT), center1: 2437 MHz
txpower 20.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
type AP, SSID LabWifi, channel 6: the practice network is on the air,
offering WPA2 with the passphrase handbookpass.
17.4.2. Connecting to WPA Personal Networks with NetworkManager
On a desktop this procedure is graphical: the Wi-Fi indicator lists
available networks, choosing LabWifi opens a passphrase dialog, and the
desktop writes the same profile nmcli reads. The steps below are the
command-line equivalent, which works identically on headless machines -
and produces captures a desktop panel does not.
First bring the client radio up so it can scan:
# ip link set wlan0 up
The command is silent. Scan for networks, forcing a fresh sweep with
--rescan yes rather than relying on cached results:
# nmcli device wifi list --rescan yes ifname wlan0
IN-USE BSSID SSID MODE CHAN RATE SIGNAL BARS SECURITY
4A:40:BB:21:10:57 LabWifi Infra 6 54 Mbit/s 100 ▂▄▆█ WPA2
One network: the practice AP, on channel 6, WPA2, at full signal (it is
the same machine). The BSSID is the AP's radio address, SECURITY
names the authentication it offers, and SIGNAL is a percentage derived
from the received signal strength. Now create the profile. type wifi
plus ssid selects the wireless method; wifi-sec.key-mgmt wpa-psk
with wifi-sec.psk carries the passphrase; ipv4.method auto asks for
DHCP. One caution: nmcli arguments typed like this put the passphrase
in the shell history - see the note after the block:
# nmcli connection add type wifi ifname wlan0 con-name LabWifi ssid LabWifi wifi-sec.key-mgmt wpa-psk wifi-sec.psk handbookpass ipv4.method auto ipv6.method ignore
Connection 'LabWifi' (024d5195-681d-46b6-96ad-9b2b621678d2) successfully added.
wifi-sec is the accepted short alias of the full property prefix
802-11-wireless-security. The profile is a keyfile under
/etc/NetworkManager/system-connections/, root-owned, mode 0600 - the
passphrase is stored there, readable only by root. A passphrase typed
on a command line also lands in ~/.bash_history for the account that
ran it and possibly in the process list for a moment; for a real
passphrase, prefer --ask, which prompts without echoing, or set it
once and rely on the stored profile afterwards. nmcli connection up
LabWifi --ask prompts for anything missing.
Activate the profile:
# nmcli connection up LabWifi
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/4)
Between connection up and that line, NetworkManager scanned, chose the
AP, and drove wpa_supplicant through the WPA2 handshake: open-system
association, then the four-way handshake that proves both sides know the
passphrase without sending it. The kernel's wireless link state shows
the result:
# iw dev wlan0 link
Connected to 4a:40:bb:21:10:57 (on wlan0)
SSID: LabWifi
freq: 2437.0
RX: 12292 bytes (172 packets)
TX: 3169 bytes (29 packets)
signal: -30 dBm
rx bitrate: 6.0 MBit/s
tx bitrate: 54.0 MBit/s
bss flags: short-slot-time
dtim period: 2
beacon int: 100
Connected with a BSSID is the association; the handshake completed
because iw reports traffic counters - a connected-but-unauthenticated
link shows zeros. The address came from the AP's DHCP pool:
$ ip -br addr show wlan0
wlan0 UP 10.17.0.144/24 fe80::ff:fe00:0/64
The link-local address implies a MAC of 02:00:00:00:00:00 - not the
e6:da:76:f6:d8:11 the radio reported when it first appeared.
NetworkManager randomizes Wi-Fi MAC addresses during scans
(wifi.scan-rand-mac-address defaults to yes), so the address visible
on an associated client can differ from the one the driver showed
before; the AP's BSSID, by contrast, is its stable radio address.
$ nmcli -t -f IP4.ADDRESS,IP4.GATEWAY,IP4.DNS connection show LabWifi
IP4.ADDRESS[1]:10.17.0.144/24
IP4.GATEWAY:10.17.0.1
IP4.DNS[1]:10.17.0.1
This profile sets no never-default, so the DHCP gateway option
installed a default route over wlan0. It carries metric 600 -
NetworkManager's default for wireless links, versus 100 for wired ones -
which keeps a wired default route preferred whenever both are up; the
full routing table in Section 17.7.1 shows the result. Prove the path:
$ ping -c 3 -W 1 10.17.0.1
PING 10.17.0.1 (10.17.0.1) 56(84) bytes of data.
64 bytes from 10.17.0.1: icmp_seq=1 ttl=64 time=0.038 ms
64 bytes from 10.17.0.1: icmp_seq=2 ttl=64 time=0.025 ms
64 bytes from 10.17.0.1: icmp_seq=3 ttl=64 time=0.042 ms
--- 10.17.0.1 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2037ms
rtt min/avg/max/mdev = 0.025/0.035/0.042/0.007 ms
The radio-side detail of an established connection, from the client's point of view:
# iw dev wlan0 station dump
Station 4a:40:bb:21:10:57 (on wlan0)
inactive time: 664 ms
rx bytes: 17759
rx packets: 270
tx bytes: 3353
tx packets: 34
tx retries: 0
tx failed: 0
beacon loss: 4
beacon rx: 115
rx drop misc: 26
signal: -30 dBm
signal avg: -30 dBm
beacon signal avg: -30 dBm
tx bitrate: 1.0 MBit/s
tx duration: 0 us
rx bitrate: 48.0 MBit/s
rx duration: 0 us
expected throughput: 19.133Mbps
authorized: yes
authenticated: yes
associated: yes
preamble: long
WMM/WME: no
MFP: no
TDLS peer: no
DTIM period: 2
beacon interval:100
short slot time:yes
connected time: 16 seconds
associated at [boottime]: 612.295s
associated at: 1795256721806 ms
current time: 1795256738052 ms
The three yes flags on authorized, authenticated, and associated
are the handshake's receipt in order - associated first, authenticated
by the four-way handshake, authorized to send data frames. tx retries
and tx failed are the quality counters that grow on a marginal link,
and signal avg is the number Section 17.4.4 uses for diagnosis. The
profile stays saved; the machine will re-associate automatically whenever
the network reappears in range.
17.4.3. Enterprise Authentication and Certificate Validation
WPA Personal authenticates anyone who knows the passphrase. Enterprise networks - universities, offices - instead authenticate users, with 802.1X: the access point demands authentication before the link carries traffic, and forwards the credentials exchange to a RADIUS server. The profile must name an EAP method, an identity, and - critically - how to validate the server's certificate. The method used here is PEAP with MSCHAPv2 inside, the most common combination on campus and corporate networks:
# nmcli connection add type wifi ifname wlan0 con-name LabEnterprise ssid LabEnterprise 802-11-wireless-security.key-mgmt wpa-eap 802-1x.eap peap 802-1x.identity student 802-1x.password classpass 802-1x.phase2-auth mschapv2 802-1x.system-ca-certs yes 802-1x.domain-suffix-match lab.example
Connection 'LabEnterprise' (d2280e03-3ae8-4583-a4f7-2444fad43e11) successfully added.
The properties, read back from the saved profile:
$ nmcli -f 802-1x.eap,802-1x.identity,802-1x.phase2-auth,802-1x.system-ca-certs,802-1x.domain-suffix-match connection show LabEnterprise
802-1x.eap: peap
802-1x.identity: student
802-1x.phase2-auth: mschapv2
802-1x.system-ca-certs: yes
802-1x.domain-suffix-match: lab.example
key-mgmt wpa-eap is the switch that makes the profile enterprise rather
than personal. eap peap wraps an inner authentication in a TLS tunnel;
phase2-auth mschapv2 is that inner exchange. identity and password
are the RADIUS credentials. The two validation properties are the ones
that matter most: system-ca-certs yes means the server certificate
must chain to a certificate authority in the system trust store - for a
private network whose CA is not public, the alternative is installing
the CA into the system store (Chapter 26 covers that
procedure) or naming the CA file with 802-1x.ca-cert; and
domain-suffix-match lab.example requires the certificate's
SubjectAltName to end in lab.example, so a certificate for some other
system will not be accepted even if its chain is valid. Without those
two checks, a rogue access point using any certificate could harvest
the MSCHAPv2 response - the classic evil-twin attack on open networks.
EAP-TLS, the certificate-per-user alternative, replaces the password
entirely with 802-1x.client-cert and 802-1x.private-key properties.
This profile targets a network with a RADIUS backend serving
lab.example credentials, and the practice lab does not run one, so
what is exercised here is the profile: creating it, reading it back, and
the properties that govern certificate validation. Activation on a real
network is nmcli connection up LabEnterprise with the same
secret-handling behavior as the personal profile. The practice profile
is not needed again; delete it, as root:
# nmcli connection delete LabEnterprise
Connection 'LabEnterprise' (d2280e03-3ae8-4583-a4f7-2444fad43e11) successfully deleted.
17.4.4. Diagnosing Association, Authentication, and Signal Problems
Wireless failures split cleanly into three kinds: the radio cannot see the network (discovery), it sees it but the handshake fails (authentication), or it associates and then performs badly (signal). The working path from Section 17.4.2 is the reference for all three, and the first diagnosis tool is the deliberate failure.
Create a second profile for the same SSID with a wrong passphrase - the kind of mistake every wireless user makes once:
# nmcli connection add type wifi ifname wlan0 con-name LabWifiWrong ssid LabWifi wifi-sec.key-mgmt wpa-psk wifi-sec.psk wrongpass ipv4.method auto ipv6.method ignore
Connection 'LabWifiWrong' (8c32d9e8-4900-476e-9867-dc28139151e7) successfully added.
Try to activate it:
# nmcli connection up LabWifiWrong
Passwords or encryption keys are required to access the wireless network 'LabWifi'.
Warning: password for '802-11-wireless-security.psk' not given in 'passwd-file' and nmcli cannot ask without '--ask' option.
Error: Connection activation failed: Secrets were required, but not provided
Hint: use 'journalctl -xe NM_CONNECTION=8c32d9e8-4900-476e-9867-dc28139151e7 + NM_DEVICE=wlan0' to get more details.
The activation fails with exit status 4. The passphrase is wrong by
construction: a WPA2-PSK network completes association but cannot
finish the four-way handshake with key material derived from
wrongpass, so the authentication fails. NetworkManager's response to
a rejected secret is to ask for a new one: the first line says the
network requires credentials, the warning explains that this
non-interactive run cannot prompt (nmcli connection up LabWifiWrong
--ask would prompt with the passphrase hidden), and the error records
that no secret was supplied. An interactive desktop behaves the same
way: it re-opens the passphrase dialog. The hint line names the journal
filters that show the underlying wpa_supplicant messages - four-way
handshake timeouts - from a session where the profile's own output is
not enough.
Clean up and restore the working profile:
# nmcli connection delete LabWifiWrong
Connection 'LabWifiWrong' (8c32d9e8-4900-476e-9867-dc28139151e7) successfully deleted.
# nmcli connection up LabWifi
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/6)
The failure signature generalizes. A network that never appears in
nmcli device wifi list is a discovery problem: rfkill block, missing
firmware, a wrong regulatory domain with the channel disallowed, or an
out-of-range AP. A network that appears but activation fails at
association is usually a radio or driver problem. A failure at the
secret stage - the behavior just demonstrated - is authentication:
wrong passphrase, wrong EAP method, or certificate validation refusing
the server. The journal always names the stage; the messages above are
the summary NetworkManager derived from it.
Signal quality is a range, not a single threshold. Approximate
guidelines for the signal field in iw dev IF link and the
station dump counters:
| Signal | Quality | Typical symptom |
|---|---|---|
| -30 to -50 dBm | excellent | full rates, no complaints |
| -50 to -60 dBm | very good | full rates |
| -60 to -67 dBm | good | voice and video remain reliable |
| -70 to -75 dBm | moderate | reduced rates, occasional retries |
| -80 dBm and below | poor | frequent retries, dropped associations |
The connection from Section 17.4.2 showed -30 dBm - adjacent radios.
On real hardware, a link that "works but is slow" almost always shows
tx retries and tx failed growing in station dump while signal
avg sits in the poor range: the rate adaptation has dropped to keep
frames arriving at all, and throughput falls with the rate. beacon
loss counting up means the client missed expected beacons - a link that
drops in and out even at acceptable average signal. The remedies are
physical: distance, obstacles, interference from neighboring networks
(check with a scan and pick a quieter channel), or a better antenna
position; no profile setting fixes a bad link budget.
Two more failure classes close the loop with Section 17.4.1. A soft
block reproduces discovery failure instantly - nmcli radio wifi off
silences the radio, nmcli radio wifi on restores it, and rfkill
list shows which layer is responsible at any moment. And a driver
that loaded without its firmware produces a wlan link that associates
with nothing, ever: the dmesg check from Section 17.4.1 names the
missing file, and installing the matching firmware-* package - with a
reboot or module reload to reprobe - is the fix. When the AP is yours,
hostapd's own log (journalctl -u hostapd or the daemon's foreground
output) shows the same failures from the other side, including
rejections it cannot explain without the RADIUS server's logs.