Working in the operating system Linux Often requires administrators or advanced users to be able to manage network interfaces without a graphical shell. This may be necessary when setting up servers, restoring the system after a graphical interface failure, or simply to speed up the configuration process. Command line provides the most flexible and reliable tool for such tasks, allowing you to control every aspect of the connection.
There are several basic methods for connecting to a wireless network, and the choice of a specific one depends on the distribution and installed utilities. The most popular tools are nmcli (NetworkManager Command Line Interface), wpa_supplicant And iwctlEach has its own unique syntax and logic, but they all achieve the desired result—stable internet access.
In this article, we'll cover a detailed step-by-step procedure for various scenarios. You'll learn how to scan available networks, enter security passwords, check connection status, and troubleshoot common errors. Mastering these skills will significantly increase your efficiency when working with Debian, Ubuntu, CentOS or Arch Linux.
Checking the status of network interfaces and equipment
Before attempting to connect to Wi-Fi, ensure that the wireless adapter is physically present in the system, the drivers are loaded, and the interface itself is active. The first step should always be to diagnose the current hardware status. This will help avoid situations where you're attempting to configure something that's disabled at the hardware level.
To get general information about network devices, use the command ip link or more detailed iw devThe first will show a list of all interfaces, including Ethernet and virtual adapters, while the second focuses specifically on wireless devices. If you see an interface with a name like wlan0, wlp2s0 or wifi0, which means the system sees your adapter.
It often happens that the interface is in a state DOWN Or it's blocked by software. In this case, you'll need to unlock it. It's also worth checking whether airplane mode or RF-kill is enabled, as this can disable the radio module to save power. Activating the interface - a critical step before scanning begins.
⚠️ Attention: If the team
iw devIf the list is empty or the "command not found" error appears, you may not have wireless utilities or drivers installed. In this case, you'll need to connect via cable or USB modem to install packages.iwAndwireless-tools.
To control the interface state, use the command ip link setFor example, to enable the interface wlan0, enter sudo ip link set wlan0 upIf the interface is blocked by the power saving system, unlock it through rfkill. Make sure that the command output rfkill list Opposite to Wireless LAN there is a status "unblocked".
Using NetworkManager (nmcli) to connect
In most modern distributions, such as Ubuntu, Fedora And Linux Mint, the default service is NetworkManagerIt provides a convenient and powerful tool. nmcli, which allows you to manage connections via text commands. This is the preferred method for desktop systems, as it retains settings even after a reboot.
The first thing you need to do is find the name of your wireless device and available networks. Command nmcli dev wifi list will display a table with all visible access points, their signal, channel, and security status. Find the desired network (SSID) in the list and remember its exact name, as it is case-sensitive.
To connect to a network with a password, use the command nmcli dev wifi connectThe syntax requires the SSID and password. If the network is hidden, you will need to add the stealth flag. After successfully entering the data, the system will attempt to obtain an IP address via DHCP and configure routing.
sudo nmcli dev wifi connect "Network_Name" password "Your_Password"
If the connection is successful, you will see the message "Successfully activated". Otherwise, nmcli will return an error indicating the cause: incorrect password, no network in range, or driver problems. Saving profile occurs automatically, which allows the system to reconnect the next time you enter the router's coverage area.
☑️ Checklist for a successful connection via nmcli
Setting up a connection via wpa_supplicant
On minimalist systems or on servers that do not run NetworkManager, the primary tool remains wpa_supplicantThis is a daemon that manages wireless connections and provides WPA/WPA2 security. Working with it requires creating a configuration file, which makes the process slightly more complex, but gives you complete control over the settings.
The first step is generating a hashed password. For security reasons, it is not recommended to store cleartext passwords in configuration files. Use the utility wpa_passphrase, passing it the network name and password. The output will be a block of text that needs to be added to the configuration file.
wpa_passphrase"MyWiFi""SecretPassword123"
The resulting output must be saved to a file. /etc/wpa_supplicant/wpa_supplicant.conf (The path may vary depending on the distribution.) This file also specifies drivers and control interfaces. After editing the file, you need to start the daemon, specifying the interface and the path to the configuration.
| Parameter | Meaning | Description |
|---|---|---|
| ctrl_interface | /var/run/wpa_supplicant | Path for control socket |
| driver | wext / nl80211 | Driver type (usually detected automatically) |
| ssid | "HomeNetwork" | Wireless network name (SSID) |
| psk | Password hash | Encrypted security key |
The launch is carried out by the command sudo wpa_supplicant -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf -B. Flag -B sends the process to the background. After that, you need to obtain an IP address by running a DHCP client, for example, sudo dhclient wlan0Without this step, the connection will be established at the link level, but there will be no network access.
What to do if wpa_supplicant doesn't see the network?
If the network is hidden (hidden SSID), add the line scan_ssid=1 to the network block of the configuration file. Also, make sure the region is set correctly using the iw reg set command, as channels may be restricted in some countries.
Working with iwctl in Arch and systemd-based distributions
Modern distributions based on systemd, such as Arch Linux or new versions Fedora, often offer a tool iwd (iNet wireless daemon) and its client part iwctlThis tool was developed by Intel and is designed to replace older, cumbersome solutions, providing a simpler and more intuitive interface for Wi-Fi management.
iwctl It works interactively, making it easy for beginners to navigate. By running the command iwctl, you will be taken to a shell with a prompt [iwd]#Here, commands are executed sequentially: first, a device is selected, then networks are scanned, and only then a connection is made.
Inside the shell iwctl the process looks like this:
device wlan0 scan — start scanning.
station wlan0 get-networks — getting a list of networks.
station wlan0 connect"SSID" — connection attempt.
The system will automatically prompt for a password if the network is secure. This eliminates the need to enter complex commands with escaped special characters.
⚠️ Attention: Interface
iwctlis case-sensitive to commands and device names. If you use key completionTab, the setup process will be much faster and free of typos. Don't forget to exit interactive mode with the commandquitorexit.
To automatically connect at boot on systems with iwd the service needs to be configured systemd-networkd or use the plugin for NetworkManager if it is installed in parallel. Configuration files for iwd usually located in /etc/iwd/, where you can specify preferences for specific networks.
Obtaining an IP address and setting up DNS
Successfully associating with an access point is only half the battle. To enable data exchange, your computer needs an IP address. In most cases, the router's DHCP server handles this task, but in Linux, you may need to launch a client or configure a static address if the automatic DHCP server fails.
The standard tool for obtaining the address dynamically is dhclient or dhcpcd. Team sudo dhclient wlan0 sends a broadcast request to the network. If the DHCP server responds, the interface receives the IP address, subnet mask, gateway, and DNS servers. You can check the result with the command ip addr show wlan0.
If automatic address acquisition doesn't work or a fixed IP is required (for example, for a server), the settings are entered manually. This is done through the network configuration file (depending on the distribution, this may be /etc/network/interfaces, Netplan or configs NetworkManager). Static IP requires precise knowledge of your local network addressing.
DNS servers deserve special attention. Even if you have an IP address, without DNS, you won't be able to access websites by name. Check the file /etc/resolv.confIn modern systems, it's often a symlink to a managed file, so editing it directly may be useless. It's better to specify the DNS in the specific connection settings via nmcli or config wpa_supplicant.
Troubleshooting and Frequently Asked Questions
Even with proper setup, connection issues may still occur. Low signal strength, incorrect encryption type, or driver conflicts are the main causes of failures. To diagnose the issue, use the command dmesg | grep firmware or journalctl -u NetworkManagerto see kernel and network service logs in real time.
If the connection is constantly dropping, try changing the channel on your router, as neighboring networks may be interfering. It's also worth checking if power saving is enabled on your wireless adapter, which could be turning off the card when idle. You can disable this through the kernel module settings or configuration file. NetworkManager.
Below are answers to frequently asked questions to help resolve common issues:
How can I find the password for a saved Wi-Fi network?
If you are using NetworkManager, passwords are stored in configuration files in the directory /etc/NetworkManager/system-connections/The files are protected by root permissions, so you will need to be root to view them. sudo cat. Look for the line psk-flags or password inside the section [wifi-security].
Why does the nmcli command return the error "Secrets were required, but not provided"?
This means the network is password protected, but you didn't pass one in the command. Make sure you use the syntax password"your_password" after the network name. If the password contains special characters, be sure to enclose it in double quotation marks.
Is it possible to share Wi-Fi from a laptop using the command line?
Yes, it's possible. NetworkManager has a feature for creating an access point. The command looks like this: nmcli dev wifi hotspot ssid"MyHotspot" password"12345678"This will create a virtual interface and start the DHCP server for clients.
How to switch between several well-known networks?
NetworkManager automatically connects to a known network with the best signal. To force a switch, use the command nmcli connection up id"Profile_Name"Profiles are created upon the first successful connection and saved in the system.
What to do if the wlan0 interface disappeared after the update?
Most likely, the kernel was updated, and the proprietary driver is no longer compatible. Try reinstalling the driver packages or using DKMS to automatically build the module for the new kernel. Also, check if the device is being bricked. rfkill.