Working with Linux operating systems often requires interacting with the terminal, especially when the graphical interface is unavailable or malfunctioning. Knowing how to quickly set up a wireless connection via the command line is a basic skill for any system administrator or advanced user. Unlike graphical shells, CLI tools provide more granular control over the connection process and allow for troubleshooting at a low level.
There are several basic methods for setting up WiFi, depending on the distribution used and the network managers installed. The most common tools are NetworkManager (with nmcli utility) and classic wpa_supplicantThe choice of a specific method depends on your goal: quickly connecting in an existing environment or fine-tuning a server without a graphical interface.
In this article, we'll cover both approaches in detail, focusing on command syntax and potential errors. You'll learn how to scan available networks, save connection profiles, and manage network priorities. This knowledge will help you feel confident in any Linux environment, whether it's Ubuntu, Debian, CentOS, or Arch.
Checking the status of the wireless adapter
The first step before attempting a connection is to diagnose the status of your network equipment. Ensure that the wireless module is physically detected by the system and that the appropriate drivers are installed. Users often forget to enable the module itself in software, and connection attempts in this case are doomed to failure.
First, check the list of network interfaces using the command ip link or more specialized iw devIn the output you should see an interface, usually called wlan0, wlp2s0 or similar, indicating the presence of a wireless device. If the interface is displayed as DOWN, it must be activated.
Use the command ip link set dev wlan0 up to enable the interface, replace wlan0 to the name of your device. After that, check the radio module's lock status using the utility. rfkillThis utility shows whether WiFi is blocked by a hardware switch on the laptop case or by software in the operating system.
⚠️ Note: If the rfkill command shows a "hard blocked" status, software enablement will not help. You will need to find a physical switch on the device or use a key combination (often Fn+F2) to unlock the module.
To control the lock state, use the command sudo rfkill unblock wifiThis will remove software restrictions and allow the network manager to begin scanning the airwaves. Make sure you execute these commands with root privileges, as changing the hardware state requires elevated privileges.
Using NetworkManager and nmcli
Modern Linux distributions such as Fedora, Ubuntu, and CentOS use the default NetworkManagerIt is a powerful tool that has a user-friendly console interface called nmcliIt allows you to manage connections, devices, and the overall status of your network without having to manually edit configuration files.
Start by checking the overall network status and the list of available devices. The command nmcli device status will show all network interfaces and their current status. Find your WiFi adapter in the list and make sure its status is marked as disconnected or connected, but not unavailable.
To search for available access points, run a scan with the command nmcli device wifi listIn the output, you'll see a list of networks with their SSID, signal strength, frequency, and security type. If the network you need isn't listed, try refreshing the data by forcing a scan: nmcli device wifi rescan.
Connecting to the network is accomplished with a single command, specifying the SSID and password. The syntax is as follows:
nmcli device wifi connect "Network_Name" password "Your_Password"
If the connection is successful, NetworkManager will automatically create a connection profile and remember it for future connections. If an error occurs, the system will display an error code that will help diagnose the problem, whether it's an incorrect password or an incompatible encryption type.
⚠️ Important: When entering passwords in the command line, ensure that the characters are case-sensitive. Characters such as the dollar sign ($), exclamation point (!), or backslash (\) may be interpreted by the Bash shell, so it's best to enclose the password in double quotes.
Setting up WiFi via wpa_supplicant
On older systems or minimalist server builds where NetworkManager not installed, the main tool remains wpa_supplicantThis daemon is responsible for negotiating with the access point and encrypting traffic. Working with it requires creating a configuration file and manually starting the process.
The first step is to generate a hashed key for your network so you don't have to store the password in plaintext in the configuration file. Use the utility wpa_passphrase To do this, enter the network name (SSID) and password in the terminal:
wpa_passphrase"MyWiFiNetwork""SuperSecretPassword"
The output will be a configuration block that you need to add to the file /etc/wpa_supplicant/wpa_supplicant.conf. Open the file with a text editor (for example, nano or vim) and paste the resulting data. Make sure the file structure is correct and there are no syntax errors.
☑️ Preparing for manual configuration of wpa_supplicant
Once the configuration is prepared, start the daemon by specifying the interface and path to the settings file:
sudo wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf
Flag -B means running in the background. If the command is successful, the LEDs on the network card should light up, indicating association with the access point. However, at this stage, an IP address has not yet been obtained.
⚠️ Warning: The wpa_supplicant.conf configuration file must have strict permissions (chmod 600) as it contains sensitive information. Incorrect permissions may be considered a threat by the security system, and the daemon will refuse to start.
Obtaining an IP address via DHCP
After successfully associating with an access point (via nmcli or wpa_supplicant), your computer needs to obtain an IP address, subnet mask, and gateway address. This process is handled by the protocol DHCP (Dynamic Host Configuration Protocol). Without this step, connecting to the local network and the internet is impossible, even if a connection to the router is established.
In most modern distributions, NetworkManager automatically asks for an IP address. However, when using wpa_supplicant or in minimalist environments, this step must be performed manually. The standard utility for this is dhclient or dhcpcd, depending on the distribution.
Run the DHCP client for your interface:
sudo dhclient wlan0
Or, if you're using systemd-networkd or another manager, the command may differ. After running the command, check the assigned address using ip addr show wlan0You should see a line inet with an address in the local range (for example, 192.168.xx).
Connectivity check is performed by the command ping. Send several packets to the gateway address or public DNS server, for example, ping -c 4 8.8.8.8A successful response confirms that the physical and data link layers are functioning correctly and that packets are being routed.
Managing saved connection profiles
One of the key features NetworkManager is the ability to store connection profiles. This allows you to automatically connect to familiar networks without re-entering your password. These profiles are managed through the subsection nmcli connection.
To view all saved profiles, use the command nmcli connection showThe list will display connection names (NAME), their UUID, device type, and current status. You can see which profiles are currently active and which are simply saved.
If you want to delete a network profile that you no longer plan to connect to (for example, public WiFi at a cafe), use the command:
nmcli connection delete"Profile_Name"
You can also edit existing profiles. For example, change the IP address acquisition method from dynamic to static or change DNS servers. This is done using the command nmcli connection modify, followed by the profile name and change parameters.
| Parameter | Description | Example of meaning |
|---|---|---|
| ipv4.method | Method of obtaining IP | auto / manual |
| ipv4.addresses | Static IP and mask | 192.168.1.10/24 |
| ipv4.gateway | Default gateway address | 192.168.1.1 |
| ipv4.dns | Domain name servers | 8.8.8.8, 1.1.1.1 |
After making changes to your profile, you must reactivate the connection for the settings to take effect. Use the command nmcli connection up"Profile_Name"This will apply the new configuration without requiring a system or network service reboot.
Diagnostics and problem solving
Even with the correct command syntax, connection problems may occur. System logs are the first place to look when troubleshooting. In systemd systems, use journalctl to view network daemon messages in real time.
Start monitoring NetworkManager logs with the command journalctl -u NetworkManager -f and try connecting. You'll see a detailed handshake process, including scanning, authentication, and IP acquisition. Errors are usually marked as "error" or "fail."
A common issue is incompatibility of security standards. Some older routers use WEP or WPA-TKIP, which may be disabled by default in modern Linux distributions for security reasons. This will show up in the logs as an association refusal.
If you're working on a corporate network or an environment with a large number of access points, you may need to specify a specific frequency or channel. It's also worth checking if a firewall is blocking (iptables or nftables) DHCP requests or DNS traffic.
In complex cases, temporarily disabling network management from NetworkManager for manual debugging via wpa_supplicantThis allows us to isolate the problem: whether it lies in the control daemon or in the device driver/kernel configuration.
How do I find out the name of my wireless interface?
Use the command ip link or iw devWireless interfaces often start with the "w" prefix (wlan0, wlp3s0). You can also use the command nmcli device, where the device type will be specified as "wifi".
What should I do if nmcli reports "Error: NetworkManager is not running"?
This means the NetworkManager service is not running. Try starting it with the command sudo systemctl start NetworkManagerIf the service is not installed, you need to install it through your distribution's package manager (apt, dnf, pacman).
Is it possible to connect to a hidden network (Hidden SSID)?
Yes, this is possible. In nmcli, use the ssid flag: nmcli device wifi connect"SSID" ssid"Network_Name" password"Password" hidden yesFor wpa_supplicant, add the following line to the config scan_ssid=1 inside the network block.
How to save a password in plaintext in the wpa_supplicant config?
Storing passwords in plaintext is technically possible, but not impossible. Instead of the hash obtained via wpa_passphrase, simply enter the plaintext password in quotation marks in the psk field of the configuration file: psk="mypassword".
Why is WiFi speed slower on Linux than on Windows?
There may be various reasons for this: the absence of proprietary drivers (an open driver with limited functionality is used), incorrect power saving settings, or the lack of support for certain standards (for example, Wi-Fi 6) in the current version of the kernel or driver.