Connecting to WiFi via the Terminal in Linux: A Step-by-Step Guide

Working with the command line in operating systems of the family Linux opens up opportunities for the user to fine-tune the network stack, which are not available in standard graphical interfaces. Connecting to WiFi via a terminal This is often necessary when working with servers, remotely accessing via SSH, or simply when the desktop's graphical shell crashes. Understanding low-level authentication processes allows administrators to effectively diagnose connection problems.

There are several basic tools for managing wireless interfaces, each with its own features and applications. The most common utilities are NetworkManager (through nmcli), iwd (through iwctl) and classic wpa_supplicantThe choice of a specific method depends on the distribution, kernel version, and the preferences of the system administrator.

In this article, we'll examine the algorithms for each of these tools in detail, focusing on connection security and stability. You'll learn how to scan the air, save network profiles, and automatically reconnect when the connection is lost. This knowledge is fundamental for any specialist working with Linux systems.

Wireless interface identification and status check

The first step before attempting a connection is to detect the physical or virtual wireless adapter in the system. Network cards can often be blocked either software- or physically, requiring prior intervention. For initial diagnostics, use the following utility: ip or more specialized iw.

Enter the command ip link to view a list of all network interfaces. Wireless adapters usually have names starting with wl, For example, wlan0, wlp2s0 or wlo1If the interface is displayed as DOWN, it must be raised by the command sudo ip link set dev interface_name up.

More detailed information about the status of the wireless module, including supported frequencies and operating modes, can be obtained through the utility iw. Team iw dev will show active interfaces, and iw list Displays full hardware specifications. This is especially useful when configuring specific operating modes, such as an access point or monitor.

  • 🔍 ip link — a basic command for viewing the link status and MAC address.
  • 📡 iw dev — displays only wireless interfaces and their current status.
  • 🛑 rfkill list — shows the status of radio module locks (Wi-Fi and Bluetooth).
⚠️ Attention: If the team iw If an error or empty result is returned, the driver for your network card may not be installed or the kernel module may not be loaded. Check for firmware packages for your hardware.

It is important to ensure that the interface is not in a locked state. Utility rfkill Allows you to control the switches of wireless devices. If the status shows Soft blocked: yes, you can unlock the adapter with the command sudo rfkill unblock wifiPhysical blocking (Hard blocked) requires turning on a switch on the laptop case or in the BIOS.

Using NetworkManager (nmcli) for quick connection

Most modern distributions such as Ubuntu, Fedora, Debian and CentOS have it installed by default. NetworkManagerIt is a powerful network connection management daemon that has an excellent console interface. nmcliThis tool is ideal for desktop and server environments where saving connection profiles is required.

To get started, you need to scan for available networks within range of your adapter. Command nmcli dev wifi list will display a table with the SSID, security mode, signal strength, and channel. If the list is empty, try refreshing it by adding the flag --rescan yes, although scanning usually occurs automatically.

nmcli dev wifi list

Once the desired network is found, you can initiate a connection. You'll need the network name (SSID) and password. The command syntax allows you to create a new connection or activate an existing profile. The system will automatically generate a configuration file that will be used on subsequent startups.

nmcli dev wifi connect "Network_Name" password "Your_Password"

NetworkManager Automatically handles WPA2 and WPA3 authentication processes. If successful, the interface will be assigned an IP address via DHCP, and DNS servers will be specified. The connection status can be checked with the command nmcli connection show --active.

📊 Which WiFi tool do you use most often?
NetworkManager (nmcli)
iwd (iwctl)
wpa_supplicant
Graphical interface
Other

If the connection is successful but the internet isn't working, the problem may be with DNS. You can manually specify DNS servers for a specific connection using the command nmcli con mod "ConnectionName" ipv4.dns "8.8.8.8 1.1.1.1"After changing the settings, the connection must be restarted.

Working with the iwctl utility (iwd interface)

Utility iwd (iNet Wireless Daemon) is a modern alternative to classic solutions from wpa_supplicant. Developed by Intel, it is becoming the standard in many distributions due to its lightweight and fast interface. iwctl Provides an interactive shell that makes it easy to navigate commands.

To start interactive mode, enter iwctl in the terminal. Inside the shell, the commands become simpler and more understandable. First, you need to make sure the device is turned on with the command device wlan0 set property Powered on (replace wlan0 to the name of your interface). Then perform a scan: station wlan0 scan.

After scanning, list the networks with the command station wlan0 get-networksTo connect, use the command station wlan0 connect "SSID"The system will ask for a password (Passphrase) if the network is secured. For security reasons, the characters you enter will not be displayed.

iwctl command Description of action Necessary rights
device list Show list of wireless devices User
station wlan0 scan Start scanning the airwaves Root/Sudo
station wlan0 connect SSID Connect to the network Root/Sudo
exit Exit the interactive shell User

One of the strengths iwd is automatic reconnection when the connection is lost or when returning to the network coverage area. The configuration is stored in /var/lib/iwd/To exit interactive mode, use the command quit or exit.

Classic method via wpa_supplicant

For minimalistic systems that don't use heavy daemons like NetworkManager, or for writing your own init scripts, it's ideal wpa_supplicantThis is a cross-platform daemon that implements the WPA and WPA2 protocols. Working with it requires manually creating a configuration file.

The first step is to generate a hashed key for your network so you don't have to store the password in plaintext (although this isn't strictly necessary). Use the utility wpa_passphraseEnter the SSID and password, and the program will display a ready-made configuration block.

wpa_passphrase "MyHomeWiFi" "ComplexPassword123"

The resulting output must be saved to a configuration file, usually located at /etc/wpa_supplicant/wpa_supp.conf. The file must contain a block network with parameters ssid And pskAfter creating the file, you can start the daemon by specifying the interface and path to the configuration.

sudo wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant/wpa_supp.conf

Flag -B means running in the background. After the daemon starts, the interface still doesn't have an IP address. To obtain an address, you need to run a DHCP client, for example, dhcpcd or dhclient.

  • 📄 Configuration — requires manual editing of a text file.
  • 🚀 Autonomy - does not depend on heavy network managers.
  • ⚙️ Flexibility — allows you to specify complex authentication parameters.
⚠️ Caution: When using wpa_supplicant in the background, ensure that other network managers (such as NetworkManager) are not attempting to manage the same interface simultaneously. This will cause conflicts and connection failure.

To automatically connect when the system boots in minimalistic distributions (for example, Arch Linux or Gentoo), you need to configure the appropriate systemd service or init script that will run wpa_supplicant And dhcpcd in the correct sequence.

Setting up static IP and DNS

In server environments, it's often necessary to replace dynamic address allocation (DHCP) with static IP addresses. This ensures addressing predictability and simplifies firewall rule configuration. Setting up a static address depends on the network management tool chosen above.

If you use NetworkManager, you can change the settings without editing text files. Command nmcli con mod Allows you to set the IP address, gateway, and DNS. For example: nmcli con mod "Wired connection 1" ipv4.addresses 192.168.1.50/24. Don't forget to specify the method as manual.

When working with wpa_supplicant and manual launch of the DHCP client, static configuration is often performed through the configuration of the DHCP daemon itself or through systemd-networkd. Configuration file /etc/systemd/network/20-wired.network (name may differ) allows you to specify all the necessary parameters in INI format.

[Network]

Address=192.168.1.50/24

Gateway=192.168.1.1

DNS=8.8.8.8

DNS=1.1.1.1

Proper DNS configuration is critical for internet performance. If web pages don't open via domain names, but IP addresses can be pinged, the problem lies with DNS resolution. resolv.conf The current addresses of name servers must be specified.

Diagnostics and troubleshooting

Even if you enter the commands correctly, the connection may not be established. Problem diagnosis Wi-Fi troubleshooting in Linux starts with log analysis. System logs contain detailed information about the authentication and association processes with the access point.

Use the command journalctl -u NetworkManager or dmesg | grep wlan to troubleshoot errors. Common issues include incorrect passwords, incompatible encryption protocols, or weak signal strength. It's also worth checking whether a firewall is blocking the connection.

If the signal is too weak, you can try changing your Wi-Fi region, as different countries allow different channels and power levels. sudo iw reg set US (or another country code) may improve reception. However, changing the region must be done in accordance with local laws.

  • 📉 Weak signal — check the antennas and the distance to the router.
  • 🔑 Key error — double-check your keyboard layout and character case.
  • 🚫 Blocking - Make sure that the MAC address is not blocked on the router.

To analyze connection quality in real time, use the command watch -n 1 'iw dev wlan0 link'It will update information about the current connection speed, signal strength (RSSI), and noise level every second. This helps find the optimal position for your laptop or antenna.

⚠️ Note: Command line interfaces and utility parameters may change in newer versions of distributions. Always consult the official man pages (man nmcli, man iwctl), if standard commands do not work.

Frequently Asked Questions (FAQ)

How do I save my WiFi password so I don't have to enter it every time?

When using NetworkManager Passwords are automatically stored in encrypted form in the keyring or in configuration files /etc/NetworkManager/system-connections/. IN wpa_supplicant The password is stored in plain text or hashed form in a configuration file you create.

Why doesn't the sudo iwlist scan command work?

Utility iwlist is considered deprecated and has been replaced by in many new distributions. iw And nmcliIn addition, to perform scanning, the interface must be up, and in some cases, it is necessary to disable the network manager that has exclusive control over the device.

Is it possible to connect to a hidden network (Hidden SSID)?

Yes, it is possible. In nmcli add parameter hidden yes to the connection command. In the configuration file wpa_supplicant a line needs to be added scan_ssid=1 inside the network block to initiate active scanning.

How do I switch between saved WiFi networks?

If you have multiple profiles, use the command nmcli con up id "Profile_Name" to switch. NetworkManager will automatically disconnect from the current network and attempt to connect to the selected one. Connection priority can be configured in the profile settings.