Working with the Linux operating system often requires interacting with the command line, especially when the graphical interface is unavailable or not functioning properly. Connecting to a wireless network via the terminal is a basic skill for system administrators and advanced users, allowing them to restore internet access for installing drivers or configuring a server. Unlike graphical utilities, the terminal provides full control over network interfaces and allows for automating the connection process using scripts.
There are several basic tools for managing network connections in Linux distributions, each with its own features. The most common are NetworkManager (nmcli and nmtui utilities), wpa_supplicant (wpa_cli) and iwd (iwctl). The specific tool you choose depends on your distribution and personal preferences, but the principles of working with Wi-Fi remain similar: scanning networks, authenticating, and obtaining an IP address.
In this guide, we'll walk you through step-by-step instructions for various connection methods, highlighting common errors and security nuances. Whether you're using a minimalist window manager or working on a remote server without a GUI, this knowledge will help you stay online. Just be sure to enter commands carefully and check interface names, as they may vary on different devices.
Preparing and defining the network interface
Before attempting a connection to an access point, you must ensure that the wireless adapter is active and recognized correctly by the system. The first step is always identifying the name of your network interface, as all subsequent commands will require this parameter. In modern systems, interface names often have a format different from the familiar wlan0, for example, wlp2s0 or wlo1.
To get a list of all network devices, use the command ip link or iw dev. In the command output iw dev You'll see a list of interfaces; the one labeled "Interface" is your Wi-Fi adapter. If the list is empty, the drivers may not be installed or the kernel module may be blocked, which requires a separate driver troubleshooting.
Once an interface is detected, it's important to check its status. It must be UP to allow scanning. If the interface is DOWN, it must be activated using the command ip link set dev <interface_name> upWithout this step, any attempts to scan networks will return an error.
Using NetworkManager (nmcli) to connect
The most universal and widespread tool in desktop distributions is NetworkManager, which is controlled through a command line utility nmcliThis method is preferred because it automatically handles reconnections, saves profiles, and integrates with system services. To get started, make sure the NetworkManager service is running.
The connection process consists of several steps: turning on Wi-Fi, scanning for available networks, and connecting directly. First, activate the radio module and scan using the command nmcli radio wifi on And nmcli dev wifi rescanThis will refresh the list of available access points in the network manager cache.
To view a list of networks with signal strength and security, use the command:
nmcli dev wifi list
In the resulting list, find your network's SSID (Wi-Fi name). Note the SIGNAL column, which indicates the reception quality. To connect, enter the command, specifying the network name and password. The syntax is as follows:
nmcli dev wifi connect "Network_Name" password "Your_Password"
☑️ Check before connecting via nmcli
If the connection is successful, the system will automatically obtain an IP address via DHCP and configure DNS. If you have an error, check the spelling of the SSID, especially if the name contains special characters or spaces. In these cases, it's best to enclose the network name in quotation marks. nmcli Allows you to create permanent profiles, which is convenient for frequently visited places.
Working with wpa_supplicant and wpa_cli
In lighter environments or server builds that do not use NetworkManager, the de facto standard is the wpa_supplicant And wpa_cliThis method requires a more manual approach, but provides a deeper understanding of the access point association process. The main difference is the need to create a configuration file or use interactive mode.
To begin, start the wpa_supplicant daemon in the background, specifying your interface and driver. The command typically looks like this: wpa_supplicant -B -i <interface_name> -c /etc/wpa_supplicant/wpa_supplicant.confAfter starting the daemon, you can interact with it through the utility wpa_cli.
In wpa_cli's interactive mode, you can scan for and connect to networks without manually editing configuration files. Enter wpa_cli in the terminal, then run the command scan and wait a few seconds. To view the results, use scan_results.
Generating a password hash
To increase security, you can generate a hash using the wpa_passphrase"SSID""password" command instead of storing the password in plain text and copy the resulting block into the config.
To connect, use the command add_network, which will return the network number (usually 0). Then configure the parameters: set_network 0 ssid"Network_Name" And set_network 0 psk"Password"After setting up, activate the connection with the command enable_network 0 and save the configuration with the command save_config.
A modern approach via iwd (iwctl)
Project iwd (iNet Wireless Daemon) from Intel developers is gradually replacing older solutions in many distributions, offering a faster and lighter daemon. It is managed via a utility. iwctl, which features a user-friendly, interactive interface reminiscent of menu navigation. It's an excellent choice for modern systems like Arch Linux or Fedora.
Start interactive mode with the command iwctlInside the shell you will see a tooltip like this [iwd]#First of all, you need to use the device command device listto make sure the adapter is visible. Then proceed to scan the networks with the command station <device_name> scan.
After scanning, you will get a list of networks:
station <device_name> get-networks
To connect, enter the command station <device_name> connect"Network_Name"The system will ask for a password (passphrase). Unlike other methods, iwd automatically creates a configuration and saves it for future connections. This makes the process as simple and straightforward as possible, even for beginners.
It is important to note that iwd stores configuration files in a directory /var/lib/iwd/If you're experiencing connection issues, checking the logs in this folder or clearing old profiles may help resolve the issue. This tool is known for its high reconnection speed when the connection is lost.
Setting up a static IP and diagnostics
In some cases, automatically obtaining an address via DHCP may not work, or a fixed IP address may be required for server tasks. After successfully connecting to Wi-Fi, you can manually assign a static address using the command ip addr. For example: ip addr add 192.168.1.50/24 dev <interface_name>.
Don't forget to also specify the default gateway if it wasn't obtained automatically. The command ip route add default via 192.168.1.1 This will tell the system where to send traffic outside the local network. Without the correct gateway, the internet won't work, even if the connection to the router is established.
Use utilities to diagnose problems ping And journalctlFirst, check the gateway's availability: ping -c 4 192.168.1.1If the packets are coming through, check the external address, for example, ping -c 4 8.8.8.8If there's a ping to the gateway, but not to the outside world, the problem is with the DNS or the gateway.
| Team | Description of action | Example of use |
|---|---|---|
ip link |
Show interface status | ip link show |
nmcli dev wifi |
List of Wi-Fi networks | nmcli dev wifi list |
iwctl |
Interactive client iwd | iwctl station wlan0 connect Home |
dhclient |
Request IP address | dhclient wlan0 |
Typical errors and methods for eliminating them
One of the most common problems is an incorrectly entered password or the wrong encryption type. If the system displays "Authentication failed," double-check your keyboard layout and capitalization. In Linux, case is important, and "Password" is different from "password."
Another common error is trying to connect to a 5 GHz network on an adapter that only supports 2.4 GHz, or vice versa. Make sure your driver Supports the router's frequency range. Issues may also arise due to WPA3 security mode on older devices; in such cases, adjusting the router's settings may be necessary.
⚠️ Caution: When using public Wi-Fi networks, avoid transmitting sensitive data without additional encryption (VPN), as traffic on open networks can be intercepted by attackers.
If the interface is frozen and unresponsive, try restarting the network module. This can be done by removing and adding the kernel module: rmmod <module> And modprobe <module>Be careful though: if you are connected remotely, this will break the connection.
Problem with MAC addressing
Some providers bind access to the MAC address. If you've changed your router, you may need to clone the old device's MAC address in the interface settings.
Automated connection at system startup
For servers and workstations, it's critical that Wi-Fi is automatically enabled after a reboot. In the case of NetworkManager, if you used the command nmcli With the correct parameters, the profile is saved automatically and marked as "autoconnect." You can check this with the command nmcli connection show.
If you use wpa_supplicant Without NetworkManager, you need to configure a system service. In systemd systems, this is done by creating or editing a service unit that will start wpa_supplicant and dhcpcd at boot. This requires creating a file in /etc/systemd/system/.
For iwd Automation is built in by default: if auto-connection is specified in the configuration, the daemon will automatically attempt to connect to a known network upon startup. Make sure the service iwd.service included in startup by command systemctl enable iwd.
⚠️ Warning: Network configuration files may contain cleartext passwords. Set permissions to 600 on configuration files (e.g., wpa_supplicant.conf) so that only root can read them.
Frequently Asked Questions (FAQ)
How do I find out the name of my Wi-Fi adapter in the terminal?
Use the command ip link or iw devLook for a device that is not lo (loopback) and usually has a name starting with w (wireless), for example, wlan0 or wlp3s0.
Why does the nmcli command say "Error: No network found"?
This may mean that the Wi-Fi module is disabled by software or hardware. Check the switch on your laptop or run the command nmcli radio wifi onAlso, make sure you are within range of the network.
Is it possible to connect to a hidden network (Hidden SSID)?
Yes, it is possible. In nmcli use the flag hidden yes: nmcli dev wifi connect"SSID" password"pass" hidden yes. IN wpa_supplicant you need to add a line scan_ssid=1 into the network configuration.
How can I save my password in the configuration so I don't have to enter it every time?
All the methods considered (NetworkManager, wpa_supplicant, iwd) save connection profiles automatically after successful authorization. Reconnection will occur automatically when a network appears within range.