Connecting to a wireless network through a GUI seems simple, but in the world of system administration and remote management, there are often situations where the GUI is unavailable or overloaded. Terminal Provides direct access to network utilities, allowing you to diagnose and configure connections even on minimalist server builds. This is an indispensable skill for working with Linux servers, embedded systems, or troubleshooting graphical environments.
Using the command line gives the administrator complete control over the authentication and access point selection process. You can view hidden parameters, manage multiple interfaces simultaneously, and automate the connection process using scripts. In this article, we'll cover Wi-Fi management methods in popular operating systems, focusing on Linux-based distributions. Debian And Red Hat.
It's important to understand that commands may vary depending on the distribution version and the network manager used. Modern systems are increasingly switching to NetworkManager as a standard, displacing older utilities like wpa_supplicant into the background. However, knowledge of the basic principles of using a wireless adapter remains relevant.
Preparing a wireless interface in Linux
The first step before making any connection is to identify the network adapter and check its status. In Linux, devices often have names like wlan0, wlp2s0 or eno1To obtain a list of all network interfaces and their current status, use the utility ip or outdated ifconfigYou need to make sure that the interface is up and ready for use.
The wireless module is often turned off by default to save power. To activate it, you'll need to enter a command. ip link set specifying the interface name and the parameter upIf the interface is locked at the BIOS level or by a hardware switch (RFKill), software methods will not work until the physical lock is removed.
To scan for available networks in your environment, you need to use tools that can work with Wi-Fi drivers. A standard set of utilities iw Provides detailed information about the signal, channel, and encryption type. This is critical for selecting the optimal access point, especially in noisy environments.
- 📡 Use the command
iw dev wlan0 scan | grep SSIDto quickly search for familiar network names. - 🔒 Pay attention to the security type: open networks (
Open) are less safe thanWPA2/WPA3. - 📶 Signal strength is displayed in dBm; values closer to 0 (e.g. -40 dBm) indicate excellent reception.
⚠️ Attention: Network scanning may interrupt the current connection if the interface is already in use by another process. Only perform scanning when absolutely necessary to avoid disrupting service stability.
Using NetworkManager (nmcli) to connect
The most universal and modern way to manage a network in Linux is the utility nmcli (NetworkManager command line interface). It's included in most desktop and server distributions out of the box. This tool not only connects to Wi-Fi but also saves connection profiles, allowing automatic reconnection upon system reboot.
The connection process consists of several steps: network search, connection profile creation, and activation. Unlike manually entering parameters into configuration files, nmcli Immediately checks the password's validity and the correctness of the settings. If the password is incorrect, the system will immediately report an authentication error without creating a broken profile.
To connect to a network with WPA2 encryption, use the command nmcli device wifi connectOnce successfully completed, the system will create a new connection profile, which will appear in the list of saved networks. This is especially convenient for laptops that move between different access points.
nmcli device wifi connect "Network_Name" password "Your_Password"
If the network is hidden (SSID is not broadcast), you must explicitly specify the network name and parameter hidden yesIn this case, scanning won't show the network in the general list, but a connection will occur if the name is specified correctly. You can also specify a specific interface if there are multiple interfaces in the system.
☑️ Checklist for connecting via nmcli
Saved profiles can also be managed through the terminal. You can delete old profiles, change the connection priority, or edit security settings. All changes are applied instantly and persist in the system configuration, surviving reboots.
Using the iwctl utility (for systemd-networkd)
In newer, more minimalist distributions such as Arch Linux or server assemblies Debian, the utility is gaining popularity iwctlShe is part of the project. iwd (iNet wireless daemon) and is designed to replace old, bloated solutions. Interface iwctl can work both interactively and through direct commands.
The interactive mode is convenient for beginners, as it provides hints and autocompletion of commands. By launching iwctl, you'll be taken to a shell where you can perform actions sequentially: devices, network scan, and connect. This reduces the risk of syntax errors when entering long commands.
However, for scripts and quick access, it is better to use direct calls. Syntax iwctl The structure is logical: first, the object (e.g., station) is specified, then the action (connect), and then the argument (SSID). A password is requested automatically if not passed in the arguments, which increases security when working on someone else's screen.
| Team | Description of action | Example of use |
|---|---|---|
station wlan0 scan |
Launching a network scan | Search for available access points |
station wlan0 get-networks |
Displaying a list of networks | View scan results |
station wlan0 connect SSID |
Connecting to the network | Starting the authentication process |
exit |
Exiting interactive mode | Terminating an iwctl session |
⚠️ Attention: Utility iwd may conflict with wpa_supplicant or NetworkManager, if they are running simultaneously. Before using
iwctlMake sure other network managers are stopped to avoid locking the device.
What to do if iwctl does not see the adapter?
If the iwctl command returns the error "No station found," the iwd service may not be running. Check the status with systemctl status iwd and start it with systemctl start iwd. Also, make sure the firmware for your Wi-Fi card is installed in the system.
Connecting to Wi-Fi on macOS via Terminal
Computer users Apple can also manage wireless connections via the command line using the utility networksetupWhile macOS is famous for its graphical interface, knowing terminal commands is useful for automating tasks through Automator or with remote access via SSH.
The first thing you need to do is determine the name of the wireless interface. On macOS, this is usually en0 or en1. Team networksetup -listallhardwareports will list all network ports and their corresponding devices. Find the line containing "Wi-Fi" to find the exact device name.
To connect to a network, use a command specifying the network name and password. A unique feature of macOS is that passwords are often stored in the keychain. If the network is known to the system, the password may not be required. Otherwise, the system will prompt for it or require you to explicitly specify it in the command.
networksetup -setairportnetwork en0"SSID_network""Password"
This command initiates a network search and connection attempt. If successful, the interface will receive an IP address via DHCP. If an error occurs, a message will be displayed to help diagnose the problem: an incorrect password, a weak signal, or a security protocol incompatibility.
Setting up Wi-Fi in Windows (CMD and PowerShell)
In the operating system Windows Network management via the console is carried out using the utility netsh (Network Shell). This powerful tool allows you to configure virtually every aspect of network connections, including wireless profiles, filters, and diagnostics.
Before connecting, it is useful to clear the list of old profiles to avoid priority conflicts. Command netsh wlan show profiles will display all saved networks. To connect to a new network, you can create an XML profile file or use interactive parameter entry, which is less secure but faster for one-time actions.
The standard connection procedure requires knowing the profile name. If the profile is already saved, the connection command is simple. If not, you must first create a profile by specifying the SSID and security key. Windows supports various encryption types, and it's important to select the correct type when manually creating a profile.
netsh wlan connect name="Profile_Name" ssid="Network_Name" interface="Wi-Fi"
PowerShell is often used to automate the process. Scripts can check for a network within range and connect to the one with the best signal. This is especially useful for corporate environments where laptops move between offices with different access points.
- 🖥️ You can use the module in PowerShell
NetAdapterfor more modern management. - 🔑 Passwords in profiles
netshare stored in clear text unless encryption is used. - 📡 Team
netsh wlan show interfaceswill show the current speed and signal quality.
⚠️ Attention: When exporting Wi-Fi profiles in Windows (netsh wlan export profile command), the password is saved in plaintext in an XML file. Never transfer such files over unsecured channels and delete them immediately after use.
Diagnosing and resolving connection problems
Even if you enter the commands correctly, the connection may fail. Diagnostics In the terminal, you can see details hidden in the graphical interface. First, check whether you've received an IP address. A lack of an address indicates problems with the router's DHCP server or incompatible settings.
A common problem is the wrong security type. If the router is configured to WPA3, and the client device or driver only supports WPA2, the connection will not be established. In the system logs (for example, journalctl in Linux or dmesg) there will be records of association refusal.
It's also worth checking the drivers. In Linux, the command lspci -k will show which driver is used for the network controller. There are no proprietary drivers (for example, for cards) Broadcom) may lead to unstable operation or complete absence of the wireless module.
If the problem persists, try resetting the network stack. In Linux, this is done by restarting the NetworkManager service; in Windows, by using TCP/IP reset commands. This often resolves stuck connections.
FAQ: Frequently Asked Questions
How can I find out the Wi-Fi password if I'm already connected via a terminal?
On Linux with NetworkManager use the command: nmcli -s -g 802-11-wireless-security.psk connection show "Network_Name"In Windows: netsh wlan show profile name="Network_Name" key=clearOn macOS, the password can be found in Keychain Access.
Why does the terminal write "Error: Connection activation failed"?
This error most often indicates an incorrect password or an incompatible encryption method. Check your keyboard layout when entering the password. Also, make sure MAC address filtering isn't enabled on your router, blocking your device.
Is it possible to connect to Wi-Fi without a GUI on a fresh server?
Yes, this is a standard situation. Use nmtui (NetworkManager text interface) for easy data entry or nmcli for the command line. If nothing is available, you will need to edit the configuration files in /etc/netplan/ or /etc/network/interfaces.
How to disconnect from Wi-Fi via terminal?
In Linux: nmcli connection down "Network_Name" or nmcli device disconnect wlan0In Windows: netsh wlan disconnectOn macOS: networksetup -setairportpower en0 off.