How to Configure Wireless Networking in Linux

How to configure wireless network in Linux

While servers are typically wired, laptops, embedded devices, and many workstations rely on Wi-Fi. Configuring wireless networking on Linux involves a few more moving parts than wired Ethernet — the wireless adapter, its driver, the wpa_supplicant authentication daemon, and the network management layer on top. This article explains, from first principles, how Wi-Fi works on Linux and walks through configuring it using both nmcli (NetworkManager) and wpa_supplicant directly.

The Wireless Networking Stack on Linux

flowchart TD
    A[Wireless NIC Hardware] --> B[Kernel Driver]
    B --> C[wpa_supplicant - handles authentication/encryption]
    C --> D[NetworkManager or systemd-networkd]
    D --> E[DHCP Client Assigns IP Address]
    E --> F[Connected, Ready to Use]
  • Kernel driver: talks directly to the wireless chipset hardware
  • wpa_supplicant: handles the actual WPA/WPA2/WPA3 authentication handshake with the access point
  • NetworkManager (or similar): the higher-level service most desktop and many server distributions use to manage connections, including easy switching between networks
  • DHCP client: requests an IP address once authentication succeeds

Checking Your Wireless Hardware

lspci | grep -i wireless        # for PCIe wireless cards
lsusb | grep -i wireless         # for USB wireless adapters
ip link show

Confirm the kernel sees the interface (commonly named wlan0, wlp2s0, etc.):

iw dev

Method 1: Using nmcli (NetworkManager) — The Easy Way

NetworkManager is the default on most desktop distributions and increasingly common on servers too, since it handles both wired and wireless connections through one consistent interface.

Listing Available Wi-Fi Networks

nmcli device wifi list

Example output:

SSID          MODE   CHAN  RATE      SIGNAL  SECURITY
HomeNetwork   Infra  6     130 Mbit/s  85     WPA2
OfficeWiFi    Infra  11    270 Mbit/s  60     WPA2 WPA3

Connecting to a Network

sudo nmcli device wifi connect "HomeNetwork" password "your-wifi-password"

Viewing Current Connection Status

nmcli connection show
nmcli device status

Setting a Static IP for a Wireless Connection

sudo nmcli connection modify "HomeNetwork" ipv4.addresses 192.168.1.100/24<br>sudo nmcli connection modify "HomeNetwork" ipv4.gateway 192.168.1.1<br>sudo nmcli connection modify "HomeNetwork" ipv4.dns "8.8.8.8"<br>sudo nmcli connection modify "HomeNetwork" ipv4.method manual<br>sudo nmcli connection up "HomeNetwork"

Forgetting/Removing a Saved Network

sudo nmcli connection delete "HomeNetwork"

Method 2: Using wpa_supplicant Directly (Lower-Level, Headless Systems)

On minimal or headless systems without NetworkManager (common on some embedded devices, or minimal server installs), you configure wpa_supplicant directly.

Step 1: Generate a Configuration Entry

wpa_passphrase "HomeNetwork" "your-wifi-password"

Output:

network={
    ssid="HomeNetwork"
    #psk="your-wifi-password"
    psk=8f3a9c1e7b2d4f6a8c1e3b5d7f9a2c4e6b8d1f3a5c7e9b2d4f6a8c1e3b5d7f9a
}

Step 2: Add This to the Config File

sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
ctrl_interface=/var/run/wpa_supplicant
update_config=1

network={
    ssid="HomeNetwork"
    psk=8f3a9c1e7b2d4f6a8c1e3b5d7f9a2c4e6b8d1f3a5c7e9b2d4f6a8c1e3b5d7f9a
}

Step 3: Start wpa_supplicant

sudo wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf

Step 4: Request an IP Address via DHCP

sudo dhclient wlan0

Step 5: Enable at Boot (systemd)

sudo systemctl enable wpa_supplicant@wlan0.service

Comparison: nmcli vs. wpa_supplicant

Aspectnmcli (NetworkManager)wpa_supplicant (direct)
Ease of useHigh — simple commandsLower — more manual steps
GUI integrationYesNo
Best forDesktops, laptops, most serversHeadless/embedded systems, minimal installs
Handles DHCP automaticallyYesNo — separate step needed
Network switchingSeamless, automaticManual reconfiguration

Configuring Wi-Fi via Netplan (Ubuntu Server)

For Ubuntu systems using Netplan, wireless configuration also fits into the same YAML system covered in our boot-time networking article:

network:
  version: 2
  wifis:
    wlan0:
      access-points:
        "HomeNetwork":
          password: "your-wifi-password"
      dhcp4: true

Apply with:

sudo netplan apply

A Practical Walkthrough: Connecting a Headless Raspberry Pi to Wi-Fi

Step 1: Identify the interface

ip link show

Step 2: Edit the wpa_supplicant config directly (useful before first boot too)

sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
country=US
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
    ssid="HomeNetwork"
    psk="your-wifi-password"
}

Step 3: Restart networking

sudo systemctl restart wpa_supplicant
sudo systemctl restart dhcpcd

Step 4: Verify

iw wlan0 link
ip addr show wlan0

Real-World Use Case: Connecting to an Enterprise WPA2-Enterprise Network

Enterprise networks (common in offices, universities) typically use 802.1X authentication instead of a simple shared password, requiring a username and certificate/password combination:

sudo nmcli connection add type wifi ifname wlan0 con-name "CorpWiFi" ssid "CorpWiFi"
sudo nmcli connection modify "CorpWiFi" wifi-sec.key-mgmt wpa-eap
sudo nmcli connection modify "CorpWiFi" 802-1x.eap peap
sudo nmcli connection modify "CorpWiFi" 802-1x.identity "yourusername"
sudo nmcli connection modify "CorpWiFi" 802-1x.password "yourpassword"
sudo nmcli connection up "CorpWiFi"

Best Practices

  • Prefer WPA2 or WPA3 over older WEP or WPA — WEP in particular is fundamentally broken and should never be used (see our dedicated WEP article for details).
  • Use NetworkManager (nmcli) wherever possible for its simplicity and robust handling of DHCP, roaming, and reconnection.
  • Store Wi-Fi credentials securely. Configuration files containing PSKs should have restrictive permissions:
sudo chmod 600 /etc/wpa_supplicant/wpa_supplicant.conf
  • Set the correct regulatory domain (country= in wpa_supplicant.conf) to ensure legal channel/power compliance for your region.
  • Monitor signal strength for problematic connections rather than assuming hardware failure:
iw dev wlan0 link
  • Document enterprise (802.1X) connection profiles carefully, since they involve more configuration than a simple pre-shared key network.

Troubleshooting

Problem: Wireless interface doesn’t appear at all

Check for missing drivers or firmware:

dmesg | grep -i wlan
lspci -k | grep -A 3 -i network

Problem: Can see networks but authentication fails

Double-check the password, and confirm the security type matches (WPA2-Personal vs. WPA2-Enterprise are configured very differently):

nmcli device wifi list

Problem: Connects but gets no IP address

Check the DHCP client:

sudo dhclient -v wlan0

Problem: Connection drops frequently

Check signal strength and interference; also check for power-saving mode issues, a common cause of unstable Wi-Fi on Linux laptops:

iw dev wlan0 get power_save
sudo iw dev wlan0 set power_save off

Problem: wpa_supplicant fails to start

Check for a syntax error in the config file, and confirm no other process is already controlling the interface:

sudo wpa_supplicant -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf -d

The -d flag enables debug output for detailed diagnostics.

Conclusion

Wireless networking on Linux involves a coordinated stack of components — kernel drivers, wpa_supplicant for authentication, and a management layer like NetworkManager or Netplan for day-to-day usability. While nmcli provides a fast, user-friendly path for most desktop and many server scenarios, understanding wpa_supplicant directly gives you the power to configure Wi-Fi on minimal, headless, or embedded systems where a full desktop network manager isn’t available. With the right tool for your environment and a solid understanding of the authentication flow, connecting any Linux system to a wireless network becomes a fast, reliable process.

Further Reading

Total
1
Shares

Leave a Reply

Previous Post
how to configure the wireless access point

How to Configure a Wireless Access Point

Next Post
the TCPIP network configuration files

TCP/IP Network Configuration Files

Related Posts