Connecting to a wireless network via a terminal in Ubuntu It may seem like a daunting task, especially if you're used to a graphical interface. However, knowing the command line opens up new possibilities: you can configure the network on servers without a GUI, restore connections during failures, or automate connections using scripts. In this article, we'll cover all the current methods—from the simplest nmcli before manual tuning through wpa_supplicant.
Why is this important? Firstly, console tools often perform more reliably than their graphical counterparts, especially on low-end hardware or in minimalist distributions like Ubuntu ServerSecondly, the ability to manage the network via a terminal will be useful when remotely configuring devices SSH or in case the graphical shell GNOME/KDE Failed. We'll cover not only basic commands but also the nuances of working with hidden networks, Enterprise networks (WPA2-Enterprise), and troubleshooting.
Note: All commands in the article were tested on Ubuntu 22.04 LTS And 24.04 LTS, but will also work for other distributions based on Debian (For example, Linux Mint or Pop!_OS). If you're using an older version (before 20.04), some settings may differ—we'll warn you about this separately.
1. Preparation: Checking network interfaces and drivers
Before connecting to Wi-Fi, make sure your wireless adapter is recognized by the system and ready to use. To do this, run two key commands:
ip a
iwconfig
In conclusion ip a look for an interface with the type name wlan0, wlp3s0 or similar (depending on the adapter model). If there is no such interface, the problem may be in the drivers. Ubuntu Most adapters are supported out of the box, but for some models (for example, Broadcom or new ones Realtek) you will need to install proprietary drivers:
sudo apt update
sudo ubuntu-drivers autoinstall
After installing the drivers, reboot the system. If the adapter is still not detected, check its physical connection (for USB adapters) or refer to the manufacturer's documentation.
⚠️ Attention: On dual boot laptops (Windows + Ubuntu) The Wi-Fi adapter can be disabled in the BIOS or via function keys (for example, Fn + F2). Before setting up, make sure that the adapter is enabled at the hardware level.
2. Method 1: connection via nmcli (recommended)
nmcli (NetworkManager Command Line Interface) is the easiest and most versatile way to manage networks in UbuntuThis tool comes standard and supports all modern security protocols, including WPA3.
To see a list of available networks, run:
nmcli dev wifi list
To connect to an open network (without password):
nmcli dev wifi connect "NETWORK_NAME"
For a secure network (WPA/WPA2):
nmcli dev wifi connect "NETWORK_NAME" password "YOUR_PASSWORD"
If the network name contains spaces or special characters, enclose it in quotation marks. After a successful connection, check the status:
nmcli connection show
The network scanner is running (nmcli dev wifi list)
The network name is correct (case sensitive!)
The password was entered without typos.
Connection confirmed (nmcli connection show)
-->
For hidden networks, add the parameter hidden yes:
nmcli dev wifi connect "NETWORK_NAME" password "PASSWORD" hidden yes
⚠️ Attention: If the Internet doesn't work after connecting, check your settings.DNS. Sometimes NetworkManager It doesn't receive them automatically. You can manually set the DNS using the command:nmcli connection modify "NETWORK_NAME" ipv4.dns "8.8.8.8, 8.8.4.4"
3. Method 2: Manual setup via wpa_supplicant
wpa_supplicant — is a low-level tool for managing Wi-Fi connections, which is often used on servers or systems without NetworkManagerIts configuration requires manual editing of the configuration file, but provides more control over security settings.
First, create a backup copy of the default config:
sudo cp /etc/wpa_supplicant/wpa_supplicant.conf /etc/wpa_supplicant/wpa_supplicant.conf.bak
Now edit the file (for example, via nano):
sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
Add a block with your network settings to the end of the file (example for WPA2-PSK):
network={ssid="NETWORK_NAME"
psk="YOUR_PASSWORD"
key_mgmt=WPA-PSK
}
For WPA3 replace key_mgmt on SAE. Save the file (Ctrl+O, then Ctrl+X) and connect:
sudo wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf
sudo dhclient wlan0
The first command starts wpa_supplicant in the background (-B), the second one receives an IP address DHCPIf you need to specify a static IP, use ip addr add instead of dhclient.
Example configuration for an Enterprise network (WPA2-Enterprise)
network={
ssid="CorpWiFi"
key_mgmt=WPA-EAP
eap=PEAP
identity="your_login@domain"
password="your_password"
phase2="auth=MSCHAPV2"
}
4. Connecting to hidden networks and networks without DHCP
Hidden Networks (hidden SSID) do not broadcast their name, so an explicit indication is required to connect SSID. IN nmcli this is done by a parameter hidden yes, as shown above. For wpa_supplicant add a line scan_ssid=1 in the network block:
network={ssid="HIDDEN_NAME"
scan_ssid=1
psk="password"
}
If the network does not distribute IP addresses DHCP (for example, in corporate networks), configure a static address manually. To NetworkManager:
nmcli connection modify "NETWORK_NAME" ipv4.method manual ipv4.addresses 192.168.1.100/24 ipv4.gateway 192.168.1.1 ipv4.dns "8.8.8.8"
For wpa_supplicant After connecting, run:
sudo ip addr add 192.168.1.100/24 dev wlan0
sudo ip route add default via 192.168.1.1
| Parameter | Description | Example of meaning |
|---|---|---|
scan_ssid |
Enables scanning of hidden networks | 1 |
key_mgmt |
Authentication protocol | WPA-PSK, SAE, WPA-EAP |
ipv4.method |
How to obtain IP | auto (DHCP) or manual |
phase2 |
Additional options for Enterprise networks | auth=MSCHAPV2 |
5. Diagnosing connection problems
If the connection fails, start by checking the interface status:
ip link show wlan0
iwconfig wlan0
Make sure the interface is enabled (UP) and not blocked (rfkill). Check the blocking:
rfkill list
If the network is visible, but the connection is lost, check the log wpa_supplicant:
journalctl -u wpa_supplicant -f
Common mistakes and their solutions:
- 🔴 Authentication error: Incorrect password or security type. Check your network settings in your router settings.
- 🔴 "No network with SSID found": Check the case of the network name and the presence of the parameter
scan_ssid=1for hidden networks. - 🔴 No IP address: problem with
DHCPTry setting a static IP or restartingdhclient. - 🔴 Interface is inactive: check your drivers (
dmesg | grep wifi) or physical connection of the adapter.
6. Automate connection at system startup
To connect the network automatically at startup, add it to startup. NetworkManager:
nmcli connection modify "NETWORK_NAME" connection.autoconnect yes
For wpa_supplicant edit the file /etc/network/interfaces:
auto wlan0iface wlan0 inet dhcp
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
If you are using a static IP, replace dhcp on:
iface wlan0 inet staticaddress 192.168.1.100
netmask 255.255.255.0
gateway 192.168.1.1
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
After making changes, reboot the system or restart network services:
sudo systemctl restart networking
⚠️ Attention: On some versions Ubuntu (starting from 22.04) servicenetworkingcan be replaced bysystemd-networkdIn this case, use:sudo systemctl restart systemd-networkd
7. Alternative tools: nmtui And iw
If nmcli seems too complicated, try the text interface nmtui:
sudo nmtui
This is a semi-graphical tool that allows you to manage networks through a menu using the arrow keys. It supports all the same functions as nmcli, but visually easier for beginners.
For advanced users, this tool is useful. iw - a modern replacement iwconfigFor example, to scan networks:
sudo iw dev wlan0 scan | grep SSID
Or connect to the network without NetworkManager:
sudo iw dev wlan0 connect "NETWORK_NAME" key d:0:YOUR_PASSWORD
note that iw does not manage IP addresses - you still need one for that dhclient or manual setting.
FAQ: Answers to frequently asked questions
Is it possible to connect to Wi-Fi without a password via a terminal?
Yes, for open networks use the command:
nmcli dev wifi connect "NETWORK_NAME"
or for wpa_supplicant:
network={ssid="NETWORK_NAME"
key_mgmt=NONE
}
But remember that open networks are not secure—traffic can be intercepted.
How do I save my Wi-Fi password so I don't have to enter it every time?
When connecting via nmcli The password is saved automatically in /etc/NetworkManager/system-connections/. For wpa_supplicant the password is stored in /etc/wpa_supplicant/wpa_supplicant.conf - just don't delete this file.
To see saved networks in NetworkManager:
nmcli connection show
Why doesn't Wi-Fi connect automatically after a reboot?
Possible reasons:
- 🔹 Auto-connection is disabled in the network settings (
nmcli connection modify "NAME" connection.autoconnect yes). - 🔹 Service
NetworkManagernot running (sudo systemctl enable --now NetworkManager). - 🔹 Conflict with other network managers (eg.
systemd-networkd).
Check the logs:
journalctl -u NetworkManager --no-pager | grep -i error
How to connect to Wi-Fi 6 (802.11ax) in Ubuntu?
Ubuntu 22.04 and newer ones are supported Wi-Fi 6 "out of the box," if your adapter is compatible. To check:
iw list | grep -A 10 "Supported interface modes"
Look for lines with HE (High Efficiency) - this is support 802.11axIf the adapter supports it, but the network does not connect, update the kernel:
sudo apt install linux-generic-hwe-22.04
Is it possible to manage Wi-Fi via SSH on a remote server?
Yes, but for this to work the server must have NetworkManager or wpa_supplicantConnect via SSH and use the same commands as locally. Note:
- 🔹 When changing the network connection
SSHif the connection is disconnected, connect via another network (for example, Ethernet). - 🔹 For security, disable automatic connection to untrusted networks.