Using the operating system Linux Often involves working with the command line, especially when the graphical interface is unresponsive or absent, as in server builds. Connecting to a wireless network via the terminal may seem complicated to a beginner, but in reality, it gives much greater control over the connection process and allows for troubleshooting at a low level.
In this article, we'll explore several proven methods for network authorization using standard utilities built into most distributions. You'll learn how to manage connections, save profiles, and troubleshoot common errors that aren't visible in graphical environments.
Before you begin, make sure you have physical access to a keyboard or an open console, as the network interface may temporarily lose connection during the setup process. You will also need to know your network name (SSID) and password.
Checking the status of the wireless adapter
The first step is always to diagnose your hardware. You need to make sure the system sees your Wi-Fi module and that it's enabled. A utility like ip, which replaced the outdated one ifconfig.
Enter the command ip link in the terminal. In the list of interfaces, look for names like wlan0, wlp2s0 or wifi0If the interface is displayed as DOWN, it needs to be raised by the command sudo ip link set dev wlan0 up, replacing the name with yours.
The utility will provide more detailed information about the state of wireless interfaces. iw. Team iw dev will display a list of devices and their current status. If a device is not found, the drivers may not be installed or the kernel module may be blocked.
⚠️ Attention: If the team
iwnot found, install package iw via your distribution's package manager (for example,apt install iwordnf install iw).
It is also useful to check whether the wireless module is blocked by software or hardware. Utility rfkill will show the status of the blocks. Run rfkill listto see the list of devices.
- 📡 Hard Block: A physical switch on the laptop case turns off the power to the module.
- 🔒 Soft Block: Software lock that can be removed with the command
sudo rfkill unblock wifi. - ✅ Unblocked: The device is ready for use.
Search for available networks and select an SSID
After confirming the adapter's operation, you need to find the target access point. Scanning the surrounding airwaves is performed with the command sudo iw dev wlan0 scanHowever, the output of this command may be too long and difficult to read.
For a more convenient display of the list of networks sorted by signal strength, it is better to use the utility nmcli (NetworkManager command line interface), if installed. The command nmcli dev wifi list will display a table with network names, signal quality, and security status.
It is important to pay attention to the column SECURITY. If it is indicated there WPA2 or WPA3, you will need a password. Open access networks (Open) connect without a key, but are unsafe for transmitting confidential data.
If you use clean wpa_supplicant Without NetworkManager, scanning can be done through sudo wpa_cli scan and see the results through sudo wpa_cli scan_resultsThis is a lower-level method that requires pre-configuring the daemon.
Connecting via NetworkManager (nmcli)
The most modern and convenient way to connect to desktop distributions is to use NetworkManagerThis tool manages connections, saving profiles and automatically reconnecting when the connection is lost.
To connect to the network, run the command, substituting your data. The syntax requires a connection name, network SSID, and password. An example command looks like this:
nmcli dev wifi connect "Network_Name" password "Your_Password"
If the connection is successful, the system will display a message stating the device has been activated. NetworkManager will automatically create a configuration file and save the credentials for future sessions.
On corporate networks or when using hidden SSIDs (which do not broadcast their name), you will need to specify additional parameters. For example, for a hidden network, add the flag hidden yes.
☑️ Checklist for connecting via nmcli
Configuration via wpa_supplicant
In minimalist Linux distributions such as Alpine or server versions Debian, there may not be NetworkManager. In this case, the daemon is used. wpa_supplicant, which is responsible for negotiations with the access point and encryption.
The process consists of several steps: creating a configuration file, starting the daemon, and obtaining an IP address. First, create the configuration file. /etc/wpa_supplicant/wpa_supplicant.conf with contents:
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdevupdate_config=1
network={
ssid="Network_Name"
psk="WiFi_Password"
key_mgmt=WPA-PSK
}
To generate a hashed password (so as not to store it in clear text), you can use the utility wpa_passphrase. Team wpa_passphrase "SSID" "PASSWORD" will produce a ready-made block for insertion into the config.
⚠️ Attention: When setting manually
wpa_supplicantThe access rights to the configuration file must be strictly limited (chmod 600), otherwise other users of the system will be able to read your password.
After creating the config, start the daemon by specifying the interface and path to the file: sudo wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf. Flag -B runs the process in the background.
Obtaining an IP address and setting up DNS
Simply connecting to an access point (association) does not provide internet access. Your interface requires an IP address, subnet mask, gateway, and DNS servers. A protocol is used to automatically obtain this information. DHCP.
Most distributions use a client by default. dhclient or dhcpcdAfter successfully associating with the router (via nmcli or wpa_supplicant), run the command:
sudo dhclient wlan0
If you use systemd-networkd, then this daemon takes over address management, and manually starting dhclient may lead to conflicts. In such cases, it is sufficient to create a file .network in the folder /etc/systemd/network/.
The success of the setup is checked by the command ip addr show wlan0You should see the assigned address on the local network (usually starting with 192.168.xx or 10.xxx).
What to do if IP address is not received?
If the address doesn't appear after running dhclient, check the logs: journalctl -u dhclient or dmesg | grep wlan0 . A common cause is an incorrect password or MAC address filtering on the router.
Comparison of methods and command table
The choice of tool depends on your goals. For everyday use on a laptop, it's best NetworkManagerFor servers and embedded systems, a combination of wpa_supplicant + systemd-networkd or iwd (new standard from Intel).
Below is a table comparing the basic commands for different approaches to network management in Linux.
| Action | NetworkManager (nmcli) | wpa_supplicant | iwd (iwdctl) |
|---|---|---|---|
| Network scanning | nmcli dev wifi list |
wpa_cli scan_results |
scan |
| Connection | nmcli dev wifi connect |
Starting the dhclient daemon | connect SSID |
| Saving profile | Automatically | Manually in the config | Automatically |
| Disconnection | nmcli dev disconnect |
killall wpa_supplicant |
disconnect |
New tool iwd It is gaining popularity due to its lightweight nature and lack of dependencies, but it may not be installed by default on older distributions.
Diagnosing connection problems
Even with the correct command syntax, a connection may not be established. A common cause is an incorrect driver or a conflicting version of security protocols. If the router only operates in wireless mode, WPA3, and your card is old, the connection will not take place.
For in-depth diagnostics, use kernel logs. The command dmesg | grep firmware This will show whether the firmware for the wireless module has loaded successfully. Missing firmware is a common cause of Wi-Fi not working immediately after installing the OS.
It's also worth checking the status of the network management service. On systems with systemd, use systemctl status NetworkManager or systemctl status wpa_supplicantIf the service has failed, try restarting it.
⚠️ Note: Command interfaces and available options may vary depending on the distribution version and the specific network manager. Always consult the man pages (
man nmcli) for your software version.
Don't forget about power efficiency. Some Wi-Fi drivers can enter power-saving mode, which can lead to connection drops. You can disable this through kernel module settings or commands. iwconfig wlan0 power off.
Frequently Asked Questions (FAQ)
How to save a password in plaintext in the wpa_supplicant config?
When using wpa_passphrase The password is hashed. If you need to see the password plainly, just write down the string psk="password" inside the network block, but be aware of the security risks.
Why is the sudo command not required for nmcli?
A standard user is allowed to manage connections through PolicyKit. However, superuser privileges may still be required to change system settings or work with some drivers.
How to connect Linux to a hidden network (Hidden SSID)?
In nmcli add the parameter: nmcli con add type wifi ifname wlan0 con-name "MyHidden" ssid "SecretNet" wifi-sec.key-mgmt wpa-psk wifi-sec.psk "password" wifi.hidden yes.
Where are Wi-Fi connection logs stored?
In most modern distributions, NetworkManager logs are located in /var/log/NetworkManager/ or available through journalctl -u NetworkManager.