How to Connect to Wi-Fi from the Terminal in Ubuntu Using nmcli

Connecting to a wireless network from the terminal is an essential capability when configuring Ubuntu Server, troubleshooting broken desktop display managers, or managing headless single-board computers over serial consoles. Ubuntu utilises NetworkManager as its default network daemon, and its command-line companion, nmcli, provides full control over network adapters, wireless scanning, and secure credential caching.

Verifying Your Wireless Network Interface

Before attempting to scan or connect, ensure your system detects a functioning wireless network card:

nmcli device status

Look for an interface listed with the TYPE wifi (frequently named wlan0, wlp2s0, or wlp3s0). Ensure its status is not set to unmanaged.

If the Wi-Fi radio is currently disabled, turn it on with:

nmcli radio wifi on

Scanning for Available Wireless Networks

To view all wireless networks within range along with their signal strength, channel, and security protocols, execute:

nmcli device wifi list

If you suspect an access point was recently powered on and does not appear immediately, trigger an active rescan:

nmcli device wifi rescan
nmcli device wifi list

Take note of the target network’s SSID (network name) and SECURITY protocol (such as WPA2, WPA3, or Open).

Connecting to a Password-Protected Wi-Fi Network

To connect to a standard WPA2/WPA3 Personal network, run the following command, replacing MyNetworkSSID and MySecretPassword with your actual network credentials:

sudo nmcli device wifi connect "MyNetworkSSID" password "MySecretPassword"

Upon successful authentication, NetworkManager outputs confirmation:

Device 'wlp2s0' successfully activated with '7b4e2f18-d703-45a1-9a73-95cf8282da1f'.

Connecting to a Hidden Wi-Fi Network

If your router does not broadcast its SSID, specify the hidden yes flag during connection:

sudo nmcli device wifi connect "HiddenSSID" password "MySecretPassword" hidden yes

Verifying IP Assignment and Internet Connectivity

Once connected, verify your dynamically assigned IP address and routing table:

ip -4 addr show dev wlp2s0
ping -c 4 1.1.1.1

NetworkManager automatically creates a persistent connection profile in /etc/NetworkManager/system-connections/, ensuring your Ubuntu machine automatically reconnects to the network upon every reboot.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.