iw – A Modern nl80211-Based CLI Tool for Wireless Device Configuration
If you’ve ever used Linux to manage wireless networks, you’ve probably encountered iwconfig—the legacy CLI tool for WiFi setup. But as WiFi standards evolve (think 802.11ac, ax, and WPA3), iwconfig has become obsolete, unable to support modern features like mesh networks, management frame protection, or dynamic channel widths.
Enter iw: the official, feature-rich CLI utility developed by the Linux Wireless Team that uses the nl80211 netlink protocol to communicate with the kernel. nl80211 is designed to keep pace with the latest 802.11 standards, providing a flexible, extensible interface between user-space tools and the Linux kernel.
In this blog, we’ll dive deep into iw, covering installation, core commands, advanced configurations, best practices, and how it compares to iwconfig. Whether you’re a system administrator or a power user, this guide will help you master modern WiFi management on Linux.
Table of Contents#
- Introduction to iw and nl80211
- Prerequisites: Installing iw
- Core Concepts & Key Differences from iwconfig
- Essential iw Commands: A Practical Guide 4.1. Scanning for Wireless Networks 4.2. Managing Wireless Interfaces 4.3. Connecting to a Wireless Network 4.4. Configuring Advanced WiFi Features 4.5. Monitoring & Troubleshooting
- Best Practices for Using iw
- Integrating iw with Network Management Tools
- Conclusion
- References
1. Introduction to iw and nl80211#
What is nl80211?#
nl80211 is a netlink-based protocol that facilitates communication between user-space applications and the Linux kernel for wireless networking. Unlike the legacy Wireless Extensions (used by iwconfig), which are static and limited to hardcoded features, nl80211 is dynamic and extensible. It supports:
- Modern 802.11 standards (802.11n/ac/ax/WPA3)
- Mesh networks and access point (AP) mode
- Regulatory domain management
- Management Frame Protection (802.11w)
- Multi-interface configurations (station, monitor, AP on one device)
What is iw?#
iw is the reference CLI tool for nl80211, maintained by the Linux Wireless Team. It provides direct access to all nl80211 features, making it the go-to tool for advanced wireless configuration and troubleshooting on Linux.
2. Prerequisites: Installing iw#
Before using iw, ensure it’s installed on your system. Most modern Linux distributions include iw by default, but if not, install it using your package manager:
Debian/Ubuntu-based Distros#
sudo apt update && sudo apt install iwFedora/RHEL/CentOS#
sudo dnf install iwArch Linux#
sudo pacman -S iwBuilding from Source#
For the latest features, build iw from the official repository:
git clone https://git.kernel.org/pub/scm/linux/kernel/git/jberg/iw.git
cd iw
make
sudo make installVerify Installation#
Check if iw is installed correctly:
iw --version3. Core Concepts & Key Differences from iwconfig#
To use iw effectively, it’s critical to understand its core concepts and how it differs from iwconfig:
| Feature | iw (nl80211) | iwconfig (Wireless Extensions) |
|---|---|---|
| Protocol | Dynamic netlink-based communication | Static ioctl-based interface |
| Supported Standards | 802.11n/ac/ax, WPA3, mesh, AP mode | Limited to legacy 802.11b/g, WPA2 |
| Interface Management | Supports multiple virtual interfaces | Struggles with virtual interfaces |
| Regulatory Support | Dynamic regulatory domain updates | Static, hardcoded regulatory rules |
| Troubleshooting | Detailed stats (MCS index, retries) | Basic signal strength only |
Key iw Concepts#
- Phy: The physical wireless adapter (e.g.,
phy0). A single phy can host multiple virtual interfaces. - Interface: A virtual instance of a phy (e.g.,
wlan0for station mode,ap0for access point mode). - Mode: The operational state of an interface (station, AP, monitor, mesh, or ad-hoc).
- Regulatory Domain: A set of rules defining allowed channels and power levels for your region (e.g.,
USfor the United States).
4. Essential iw Commands: A Practical Guide#
Let’s explore the most common iw commands for daily WiFi management. All commands require root privileges (use sudo or run as root).
4.1. Scanning for Wireless Networks#
Scan for nearby WiFi networks using your primary interface:
sudo iw dev wlan0 scanThis outputs raw, detailed data for each network. To filter for key info (SSID, signal strength, frequency):
sudo iw dev wlan0 scan | grep -E 'SSID|signal:|freq:'Scan in Monitor Mode#
For more comprehensive scanning (e.g., detecting hidden networks), create a dedicated monitor interface:
# Create a monitor interface
sudo iw phy phy0 interface add mon0 type monitor
# Bring the interface up
sudo ip link set mon0 up
# Scan
sudo iw dev mon0 scan | grep -E 'SSID|signal:|freq:'
# Cleanup
sudo iw dev mon0 del4.2. Managing Wireless Interfaces#
View Interface Information#
Get detailed stats for a specific interface:
sudo iw dev wlan0 infoThis shows the interface mode, MAC address, supported channels, and firmware version.
List All Physical Adapters#
View all wireless adapters (phys) on your system:
iw phyChange Interface Mode#
Switch an interface to access point mode:
sudo ip link set wlan0 down
sudo iw dev wlan0 set type ap
sudo ip link set wlan0 upCreate a Virtual Interface#
Add a new station-mode interface to phy0:
sudo iw phy phy0 interface add wlan1 type station
sudo ip link set wlan1 upDelete an Interface#
Remove a virtual interface:
sudo iw dev wlan1 del4.3. Connecting to a Wireless Network#
iw does not handle encryption negotiation directly. For encrypted networks, use wpa_supplicant with iw under the hood.
Connect to an Open Network#
# Bring the interface up
sudo ip link set wlan0 up
# Connect to the open network
sudo iw dev wlan0 connect "OpenNetworkSSID"
# Assign an IP address
sudo dhclient wlan0Connect to a WPA2/WPA3 Network#
-
Create a
wpa_supplicantconfiguration file:wpa_passphrase "MyWPA3Network" "StrongPassword123" > /etc/wpa_supplicant/wpa.confFor WPA3, edit the file to add:
network={ ssid="MyWPA3Network" psk="StrongPassword123" proto=RSN key_mgmt=SAE pairwise=CCMP group=CCMP } -
Start
wpa_supplicant:sudo wpa_supplicant -i wlan0 -c /etc/wpa_supplicant/wpa.conf -B -
Assign an IP address:
sudo dhclient wlan0
4.4. Configuring Advanced WiFi Features#
Set Regulatory Domain#
Ensure your device uses allowed channels and power levels for your region:
# View current regulatory domain
iw reg get
# Set to United States (replace with your region code)
sudo iw reg set USNote: You need the crda package installed for this to work (sudo apt install crda on Debian/Ubuntu).
Configure Channel Width#
Set a 20MHz channel width for better range:
sudo iw dev wlan0 set channel 1 HT20For 802.11ac (VHT), use:
sudo iw dev wlan0 set channel 36 VHT40Enable Management Frame Protection (802.11w)#
Protect against deauthentication attacks:
sudo iw dev wlan0 set mfp requiredThis requires the network you’re connecting to also support 802.11w.
Create a Mesh Network#
-
Switch to mesh mode:
sudo ip link set wlan0 down sudo iw dev wlan0 set type mesh sudo ip link set wlan0 up -
Join a mesh network:
sudo iw dev wlan0 mesh join "MyMeshSSID" -
Assign an IP address:
sudo ip addr add 192.168.50.1/24 dev wlan0
4.5. Monitoring & Troubleshooting#
Check Connection Status#
View real-time stats for a connected interface:
sudo iw dev wlan0 linkThis shows signal strength, bitrate, encryption type, and retransmission counts.
View Station Statistics#
Get detailed performance metrics:
sudo iw dev wlan0 station dumpUse this to troubleshoot packet loss, retries, or low signal issues.
Check Firmware Version#
Verify your wireless adapter’s firmware:
iw phy phy0 info | grep firmware5. Best Practices for Using iw#
- Use Sudo: Most
iwcommands require root privileges to modify system settings. - Avoid Legacy Commands: Replace
iwconfig,iwlist, andiwprivwithiwfor all new configurations. - Update Regularly: Keep your kernel,
iw, and wireless firmware up to date to access the latest features and bug fixes. - Respect Regulatory Rules: Only set regulatory domains allowed in your region to comply with local laws.
- Use Monitor Mode Sparingly: Monitor mode can interfere with normal WiFi operation—use dedicated virtual interfaces for scanning.
- Leverage
wpa_supplicant: For encrypted networks, always usewpa_supplicantinstead of directiwcommands, asiwdoesn’t handle encryption negotiation.
6. Integrating iw with Network Management Tools#
While iw is powerful for manual configuration, most users rely on network managers like NetworkManager or systemd-networkd for daily use. iw is used under the hood by these tools to communicate with the kernel.
Using iw with NetworkManager#
To override NetworkManager’s settings for a specific interface:
- Disable NetworkManager for the interface:
sudo nmcli dev set wlan0 managed no - Use
iwto configure the interface manually. - Re-enable NetworkManager when done:
sudo nmcli dev set wlan0 managed yes
7. Conclusion#
iw is the future of Linux wireless management, replacing the deprecated iwconfig with support for modern WiFi standards and advanced features. Whether you’re scanning for networks, configuring mesh setups, or troubleshooting connection issues, iw provides the flexibility and control you need.
By mastering iw and the nl80211 protocol, you’ll be able to manage wireless networks efficiently and take advantage of the latest WiFi technologies on Linux.
8. References#
- Linux Wireless Wiki: iw Documentation
- nl80211 Protocol Specification
- iw Official Repository
iwMan Page:man iwwpa_supplicantDocumentation: https://w1.fi/wpa_supplicant/