Working with the operating system Ubuntu often requires interaction with the command line, especially when a graphical interface is not available or the system is running on a headless server. Connecting to a wireless network NetworkManager is a primary task, without which further system configuration, package installation, or remote management become impossible. Unlike desktop versions, server builds often lack the NetworkManager graphical shell by default, forcing the administrator to use text-based utilities.
There are several proven methods for establishing a connection, each with its own advantages depending on the distribution version and user preferences. Modern versions of Ubuntu, starting with 17.10, use Netplan as the standard network configuration tool, while older methods such as /etc/network/interfaces, are becoming a thing of the past. However, for temporary connections or diagnostics, utilities are excellent nmcli And nmtui, which allow you to manage the network dynamically without restarting services.
In this guide, we'll detail the steps for various scenarios, paying special attention to command syntax and potential errors. You'll learn not only how to connect to open and secure networks, but also how to properly configure static IP addresses if your infrastructure requires it. It's important to understand that The name of the configuration file in Netplan always ends with .yaml, and the slightest error in indentation can lead to the network stack not working.
Wireless interface identification
The first step before manipulating the network is to find the name of your wireless adapter in the system. Linux assigns interfaces names that may differ from the ones you're used to. wlan0, especially on modern hardware with predictable interface names. To list all network devices, use the command ip link or more detailed iw dev, which will show specifically Wi-Fi adapters.
In the command output you will see names like enp3s0 (for wired) and wlp2s0 (for wireless). If the command iw not found, package wireless-tools or iw You'll need to install it via a wired connection or using a USB model. The absence of a wireless interface in the list often indicates missing drivers or a disabled physical switch on the laptop.
⚠️ Attention: If the interface appears as
DOWN, this doesn't always indicate an error. Often, the interface is simply deactivated and needs to be reactivated with the commandsudo ip link set dev interface_name upbefore scanning networks.
To quickly check the status, you can use the utility nmcli, if the NetworkManager package is installed. It will provide a summary of available devices and their current connection status. In the list of devices, look for a line where the type is listed as wifi, and the state can be disconnected or connected.
Using nmcli for quick connection
The most versatile and frequently used tool in Ubuntu is nmcli (Network Manager Command Line Interface). This utility allows you to manage network connections on the fly, without requiring a system reboot or restarting network services. To connect to a known network with a password, use the connect command, specifying the network name (SSID) and security key.
The command syntax is fairly simple, but it does require careful attention to the case of the characters in the network name. If the SSID contains spaces, they must be escaped or the name must be enclosed in quotation marks. An example connection command looks like this:
nmcli dev wifi connect "Network_Name" password "Your_Password"
After the command is successfully executed, the system will try to obtain an IP address via DHCP and configure DNS. If the connection is successful, you will see the message "Connection successfully activated." If there is an error, you should check the password and signal strength, as nmcli sensitive to the quality of the connection at the moment of handshake.
☑️ Check before connecting via nmcli
Setting up Netplan for static configurations
In server versions of Ubuntu, the utility has become the de facto standard Netplan, which reads configuration from YAML files located in the directory /etc/netplan/This method is ideal for creating persistent settings that should persist across server reboots. Configuration files are typically called 00-installer-config.yaml or 50-cloud-init.yaml.
The YAML file structure strictly requires indentation (usually 2 or 4 spaces), as tabs are prohibited. The renderer must be specified in the configuration (usually networkd (for servers), interface name, and IP parameters. For a static IP address, the structure will differ from the DHCP client.
network:version: 2
renderer: networkd
ethernets:
wlp2s0:
dhcp4: false
addresses:
- 192.168.1.50/24
routes:
- to: default
via: 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 incorrect, the system will return an error and not apply the configuration, which will prevent loss of access to the server. To check the configuration before applying it, use the command sudo netplan try, which will roll back the changes after 120 seconds if you don't confirm them.
⚠️ Note: Interfaces in Netplan may be named differently than in the command
ifconfig. Useip linkto precisely define the interface name (e.g. enp0s3 instead ofeth0).
Alternative method via wpa_supplicant
In minimalist Linux builds or if you have problems with NetworkManager, you can use it directly wpa_supplicantThis method is more low-level and requires creating a configuration file with the password hash or plaintext password. First, you need to create a configuration file, for example, /etc/wpa_supplicant/wpa_supplicant.conf.
A network block with the SSID and PSK (password) parameters is added to this file. To generate a secure password hash, you can use the utility wpa_passphrase, which will prevent the password from being stored in plaintext. The command looks like this wpa_passphrase"SSID""password" >> /etc/wpa_supplicant/wpa_supplicant.conf.
The connection process is initiated by running a daemon in the background, specifying the interface and configuration path. After this, the interface must be brought up and the DHCP client must be started to obtain an IP address. This method is often used in automation scripts or in very old versions of distributions.
sudo wpa_supplicant -B -i wlp2s0 -c /etc/wpa_supplicant/wpa_supplicant.conf
sudo dhclient wlp2s0
Generating a password hash
Using wpa_passphrase eliminates the need to store the password in clear text in the configuration file, which is a good security practice, especially if the configuration file can be read by other users of the system.
Diagnosing and resolving driver problems
A common issue in Ubuntu is the lack of proprietary drivers for wireless cards, especially Broadcom and some Realtek models. If the interface doesn't appear or can't scan for networks, you should check the driver status with the command lspci -k or lsmodThe absence of a kernel module indicates the need to install packages firmware.
Installing drivers often requires a temporary connection via Ethernet cable or USB modem (Android/iOS), as the repositories are located online. Packages are usually called firmware-b43-installer, firmware-misc-nonfree or similar depending on the chipset vendor. After installation, a reboot or manual loading of the module may be required via modprobe.
It's also worth checking whether the wireless interface is blocked by software or hardware. Utility rfkill Shows the status of blocks. If Soft blocked: yes, you can unblock it with the command sudo rfkill unblock wifiHard blocked indicates a physical switch or Fn key combination.
Connection Method Comparison Table
The choice of method depends on your goals: temporary connection, permanent server configuration, or debugging. Below is a comparison table of the main approaches.
| Method | Configuration type | Complexity | Reboot |
|---|---|---|---|
| Tool | Purpose | Level | Required |
| nmcli | Dynamic / Temporary | Low | No |
| Netplan | Static / Constant | Average | Desirable |
| nmtui | Interactive / Visual | Low | No |
| wpa_supplicant | Low Level / Manual | High | No |
For most server users, the optimal choice is a combination nmcli for quick setup and Netplan to finalize the settings in the configuration files. This ensures management flexibility and reliability during reboots. Don't forget to check the system logs (/var/log/syslog or journalctl) when cyclic reconnections occur.
Why doesn't Wi-Fi work after updating the kernel?
Updating the Linux kernel may cause proprietary driver modules (DKMS) to not be automatically built for the new version. In this case, you will need to reinstall the driver packages or explicitly run sudo dkms autoinstallIt is also worth checking whether the correct kernel module is loaded using the command lsmod | grep wifi.
How to save Wi-Fi passwords in Ubuntu?
When using NetworkManager, passwords are stored in encrypted form in the directory /etc/NetworkManager/system-connections/Files have root access rights only. If you use wpa_supplicant, passwords are stored in cleartext in the configuration file unless a hash is used.
Is it possible to connect Ubuntu to a hidden network (Hidden SSID)?
Yes, it is possible. Add the parameter to nmcli hidden yes to the connection command: nmcli con add type wifi ifname wlp2s0 con-name"MyHidden" ssid"HiddenName" wifi-sec.key-mgmt wpa-psk wifi-sec.psk"password" hidden yesIn Netplan, you can also specify the ssid even if the network does not broadcast the name.