operating system Linux Often associated with the need to use a terminal, and although modern distributions offer convenient graphical interfaces, knowledge of console utilities is a critical skill. Situations where the graphical shell fails to load, the server has no monitor, or remote administration is required arise regularly. It's in such situations that the ability to quickly set up a wireless connection becomes a lifesaver for a system administrator or enthusiast.
Unlike Windows, where network management is hidden behind many windows, Ubuntu In Debian-based distributions, all network processes are transparent and managed by powerful utilities. Connecting to Wi-Fi via the command line not only solves the problem of a lack of a graphical interface but also allows for automated setup by creating scripts for deploying the system to multiple machines. This gives you complete control over connection parameters.
In this guide we will cover the basic connection methods: from using a universal tool nmcli before working with low-level configurations through netplan And wpa_supplicantYou'll learn how to find your wireless interface name, scan the airwaves, save passwords, and set up a static IP address. Understanding these processes will transform chaotic attempts to "guess the command" into confident, professional work.
Network Interface Identification and Preparation
The first step before doing anything in the terminal is understanding your current hardware configuration. You need to know the exact name of your wireless adapter, as commands without specifying the interface may not work or may be applied to an Ethernet port. In modern versions of Ubuntu, interface names often follow a pattern udev, For example, wlp2s0 or wlan0.
To get a list of all network devices, use the command ip link or more detailed nmcli deviceThe first one will show the link status (UP/DOWN), and the second one will show the NetworkManager control status. If you see the status unmanaged, this means that the network manager does not control the device and you will have to either change the configuration or use alternative utilities.
⚠️ Attention: If the team
ip linkIf your Wi-Fi adapter isn't showing up at all, it's possible the drivers are missing or the kernel module isn't loaded. In this case, check with the commandlspci(for internal cards) orlsusb(for USB dongles) will help identify the device and find the required driver package.
It's also important to ensure that the wireless interface itself is enabled. It can often be disabled after a reboot or to save power. To enable it, use the command nmcli radio wifi on, which software switches the radio module's state. Without this step, network scanning will be useless.
Connecting via NetworkManager (nmcli)
The most convenient and common way to manage the network in Ubuntu is the utility nmcli (NetworkManager command line interface). It is a frontend for the NetworkManager service and allows you to perform all the same actions as the graphical interface, but with greater flexibility. This is the preferred method for most users of desktop versions of Ubuntu.
The connection process consists of two main steps: scanning for available access points and establishing a connection with saved settings. First, scan to see the SSID (network name) and signal strength. The command nmcli device wifi list will output a table with available networks, where the column SIGNAL will show the reception quality as a percentage.
nmcli device wifi connect "Your_Network_Name" password "Your_Password"
This command will automatically create a new connection profile, attempt to connect, and save the settings for automatic future connections. If the network is hidden (not broadcasting its SSID), you must add a flag. hidden yes.
☑️ Checking the connection via nmcli
To view all saved profiles, use the command nmcli connection showHere you will see a list of connections, their UUIDs, and the current status. If the connection was successful, the status will be connectedIf an error occurs, the system will display an error code that will help diagnose the problem: an incorrect password, a weak signal, or an encryption protocol incompatibility.
Setting up a static IP address
By default, Ubuntu uses DHCP to obtain an IP address automatically. However, servers, printers, or smart home systems often require a static address so it doesn't change after a router reboot. Setting up a static IP via nmcli requires changing the parameters of a specific connection.
First, you need to disable automatic address acquisition for IPv4 and manually enter the address, gateway, and DNS. This is done through a series of commands. modifyFor example, to set the address 192.168.1.50, gateway 192.168.1.1 and DNS 8.8.8.8, the following construction is used, where Connection_Name taken from the list of connections.
nmcli connection modify "ConnectionName" ipv4.method manualnmcli connection modify "ConnectionName" ipv4.addresses 192.168.1.50/24
nmcli connection modify "ConnectionName" ipv4.gateway 192.168.1.1
nmcli connection modify"ConnectionName" ipv4.dns"8.8.8.8 1.1.1.1"
After making changes, you must reactivate the connection for the settings to take effect. Command nmcli connection up"ConnectionName" Reconnect the interface with the new settings. Make sure the selected IP address is outside your router's DHCP pool range to avoid address conflicts on the network.
What is CIDR (/24)?
The /24 entry indicates a subnet mask of 255.255.255.0. This is the standard for home networks and allows addresses from 192.168.1.1 to 192.168.1.254. If your network uses a different mask, replace /24 with the appropriate value.
Working with Netplan on Ubuntu Server
Ubuntu server editions (starting with version 17.10) and some desktop builds use a configuration system Netplan. It works with YAML files and is more low-level than nmcliNetplan abstracts the backend (NetworkManager or systemd-networkd) and allows you to describe the desired network state declaratively.
Netplan configuration files are located in the directory /etc/netplan/ and have an extension .yaml (For example, 00-installer-config.yaml or 50-cloud-init.yaml). Editing these files requires extreme care with indentation, as YAML is space-sensitive. Indentation errors will prevent the configuration from being applied.
An example configuration for a static IP via Netplan looks like this. Here we specify the renderer version, interface name, and DHCP or static address parameters.
network:version: 2
renderer: networkd
ethernets:
wlp2s0:
dhcp4: no
addresses: [192.168.1.50/24]
gateway4: 192.168.1.1
nameservers:
addresses: [8.8.8.8, 1.1.1.1]
After editing the file, you need to apply the changes with the command sudo netplan applyIf the syntax is correct, the network will reconfigure instantly. If there is an error, the command sudo netplan try This will allow you to test your configuration: if the connection is not confirmed within 120 seconds, the system will roll back the changes, preventing loss of remote access.
Using wpa_supplicant for minimalist systems
In very lightweight distributions, containers, or when debugging drivers, you may need to use wpa_supplicant Directly, without intermediaries like NetworkManager. This is a daemon that manages wireless connections and performs handshake with the access point. This method is more complex, but it provides insight into fundamental Wi-Fi processes.
To use this feature, you need to create a configuration file containing a network password hash. Using plaintext passwords in configuration files is possible, but less secure. First, generate the hash using the utility. wpa_passphrase, transmitting the SSID and password to it.
wpa_passphrase"MySSID""MyPassword" > /etc/wpa_supplicant/wpa_supplicant.conf
Then we start the daemon, specifying the interface and the created config. Command wpa_supplicant -B -i wlp2s0 -c /etc/wpa_supplicant/wpa_supplicant.conf -D wext will start the process in the background. After that, get the IP address via dhclient or ipThis method is often used in automation scripts or during system recovery.
| Parameter | Description | Example of meaning |
|---|---|---|
-B |
Run in the background (daemonize) | Flag (no meaning) |
-i |
Wireless interface name | wlp2s0, wlan0 |
-c |
Path to the configuration file | /etc/wpa_supplicant.conf |
-D |
Driver (usually detected automatically) | wext, nl80211 |
Diagnostics and problem solving
Even with the correct command syntax, connection issues may still occur. Common causes include MAC address blocking on the router or incompatible encryption standards. In Ubuntu, network event logs are stored in the system log, which can be viewed with the command journalctl -u NetworkManager or dmesg | grep wifi.
If the connection is established, but there is no Internet, check the routing with the command ip route. Make sure the default gateway (default via) is specified correctly. Also try pinging an external resource, for example, ping 8.8.8.8If the ping works but websites don't open, the problem is with your DNS.
⚠️ Note: Interfaces and configuration files may differ depending on the Ubuntu version and installed hardware. Always check the interface names using
ip linkbefore entering commands, as copying commands from an article without adapting them to your system is a common mistake made by beginners.
To reset all network settings and return to the state "as after installation", you can delete the connection configuration files in the directory /etc/NetworkManager/system-connections/ and restart the service. This helps when a large number of faulty profiles have accumulated, interfering with normal operation.
Frequently Asked Questions (FAQ)
How do I find the password for a saved Wi-Fi network in Ubuntu?
Passwords are stored encrypted in NetworkManager configuration files. However, if you have root privileges, you can find the connection file in /etc/NetworkManager/system-connections/. Open the corresponding file (the file name matches the connection name) and find the line psk=. You may need a command to view it. sudo cat.
Why does the nmcli command say "Error: Connection activation failed"?
This error can occur for several reasons: an incorrect password, a weak signal, the router not distributing DHCP, or MAC address filtering. Check the logs with the command journalctl -xe immediately after attempting to connect to obtain the exact error code.
Is it possible to connect Ubuntu to a hidden network (Hidden SSID)?
Yes, it is possible. In nmcli need to add parameter hidden yes when creating a connection. Example: nmcli connection add type wifi ifname wlp2s0 con-name"MyHidden" ssid"MySSID" wifi-sec.key-mgmt wpa-psk wifi-sec.psk"password" wifi.hidden yes.
How to stop Ubuntu from connecting to the network automatically?
Use the command nmcli connection modify"ConnectionName" connection.autoconnect noThis will prevent the profile from automatically activating when a network is detected, but will allow you to connect manually by command. nmcli connection up.