Working with the operating system Linux often requires interaction with the command line, especially when the graphical interface is unavailable or not working correctly. For system administrators and advanced users, knowing how connect to WiFi without the use of graphical utilities, becomes a critical skill. In the environment Ubuntu This process can be implemented in several ways using built-in network management tools.
The main advantage of using the terminal is the ability to automate processes and remotely manage the server. Even if the GNOME or KDE desktop environment freezes completely, you can still restore internet access. This allows you to download necessary drivers or correct configuration files without rebooting the system in safe mode.
In this guide, we'll cover the basic wireless connection setup methods that are relevant for modern versions of the distribution. We'll also cover using the utility NetworkManager, as it is the de facto standard for desktop versions of Ubuntu. We will also cover manual configuration via wpa_supplicant for those cases where a minimalistic approach is required.
Checking the status of the wireless adapter
Before attempting to connect to the network, you need to ensure that your wireless module is physically enabled and recognized by the system. Users often forget that the adapter may be blocked at the BIOS level or by a software switch. For initial diagnostics, use the command ip link, which displays a list of all network interfaces.
In the command output you should see an interface, usually called wlan0 or wlp2s0, depending on the connection type (USB or PCIe). If you see the message "file not found" instead of the interface name or the list is empty, you may be missing the necessary driversIn this case, you will need to connect via an Ethernet cable to install them.
Additionally, it is worth checking the radio module blocking status using the utility rfkillIt shows whether WiFi is hard blocked or soft blocked. If you see the status "blocked: yes," you need to run the command sudo rfkill unblock wifi to activate the module.
- 📡 Use
ip link showto view the status of all interfaces. - 🔒 Team
rfkill listwill show blocked wireless devices. - 🔧 Utility
lspciorlsusbwill help you find the device ID to search for drivers. - 🚀 Restarting the network service often solves problems with a frozen adapter.
⚠️ Attention: If the team
rfkillIf the error message shows "Hard blocked," software methods won't help. You'll need to find a physical switch on the laptop case or change the BIOS/UEFI settings.
Using NetworkManager (nmcli)
The most common and convenient tool for managing network connections in Ubuntu is NetworkManagerIts console client nmcli Provides a powerful interface for scanning networks, entering passwords, and managing profiles. This method is preferred by most users, as it is integrated into the system by default.
To get started, you need to scan for available access points. Command nmcli dev wifi list will display a list of all visible networks within range of your adapter. The list will show the SSID (network name), operating mode, channel, signal speed, and current security status.
Once you've selected a network, you can connect. You'll need to know the exact network name (SSID) and password. The command looks like this: nmcli dev wifi connect "Network_Name" password "Your_Password"Please note that quotation marks are required if there are spaces in the network name or password.
nmcli dev wifi connect "Home_WiFi" password "SuperSecretPassword123"
If the connection is successful, the system will automatically create a connection profile and remember it for future use. When you return to the network's coverage area, Ubuntu will attempt to connect automatically. You can also manage saved profiles by deleting old ones or editing security settings.
- 🔍 Network scanning:
nmcli dev wifi rescan. - 📝 View saved connections:
nmcli connection show. - ❌ Disconnect from the network:
nmcli dev disconnect wlan0. - ⚙️ Change IP to static via
nmclirequires profile editing.
Manual configuration via wpa_supplicant
In some cases, especially on server versions of Ubuntu or in minimalist builds, NetworkManager may be absent. This is where wpa_supplicant — a daemon that handles WPA parameter negotiation and connection to the access point. This method requires more steps but provides complete control over the process.
The first step is to create a configuration file that will store network data. It is usually located at /etc/wpa_supplicant/wpa_supplicant.conf. You need to add a section to this file with a description of your network, including the SSID and hashed password. To generate the password hash, use the utility wpa_passphrase.
| Parameter | Description | Example of meaning |
|---|---|---|
| ssid | Wireless network name | MyHomeWiFi |
| psk | Password (either plaintext or hash) | password123 |
| key_mgmt | Key management method | WPA-PSK |
| proto | Security protocol | RSN |
Once the configuration is ready, you need to start the daemon by specifying the interface and file path. The command looks like this: sudo wpa_supplicant -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf -B. Flag -B means running in the background. After this, the interface needs to be assigned an IP address, usually via dhclient.
⚠️ Caution: When using wpa_supplicant The text file may contain the password in cleartext if you don't use hashing. Restrict access rights to the configuration file with the command
chmod 600.
How to generate a password hash for wpa_supplicant?
Use the wpa_passphrase "SSID" "PASSWORD" command. Copy the command output to the config file, removing the cleartext password line and leaving only the psk= line with the hash.
Setting up a static IP address
Although most home networks use dynamic address assignment through DHCPIn corporate environments or for servers, a static IP is often required. This provides a permanent address that always makes the device accessible on the local network. Configuration is accomplished by editing Netplan configuration files, which is the default setting in Ubuntu.
Netplan configuration files are located in the directory /etc/netplan/ and have an extension .yamlIt is important to follow the correct indention (indentation), as YAML is sensitive to it. Indentation errors will result in the network not working after applying the configuration.
The configuration file must specify the renderer (usually networkd or NetworkManager), the interface name, and IPv4 parameters. This includes the address, default gateway, and DNS servers. After making changes, the configuration is applied using the command sudo netplan apply.
network:version: 2
ethernets:
wlan0:
addresses:
- 192.168.1.50/24
routes:
- to: default
via: 192.168.1.1
nameservers:
addresses: [8.8.8.8, 1.1.1.1]
- 📍 Addressing: Please enter the address in CIDR format (e.g. /24).
- 🌐 Gateway: Must match your router's IP address.
- 🔢 DNS: Use reliable public servers or local DNS.
- 💾 Backup: Always create a copy of a file before editing.
Diagnostics and troubleshooting
Even with the correct setup, situations may arise where the connection fails to establish or is unstable. The first step in diagnostics is to check the system logs. In Ubuntu, major events are recorded in a log syslog or through a utility journalctl.
A common issue is a driver conflict or incorrect operation of power-saving modes. The adapter may shut down to save power, leading to connection interruptions. This can be disabled by creating a configuration file for NetworkManager with the parameter wifi.powersave = 2.
It is also worth checking whether the built-in firewall is blocking the connection. UFW or other iptables rules. If you see that the association with the access point was successful (status: connected), but the IP address hasn't been received, the problem is most likely with the router's DHCP server.
⚠️ Note: Configuration file interfaces and names may vary across Ubuntu versions. Always consult the official documentation for your specific distribution before making changes to system files.
- 📜 Logs:
journalctl -u NetworkManager -ffor real-time monitoring. - 🔄 Restart:
sudo systemctl restart NetworkManageroften solves temporary problems. - 📉 Signal: Low signal strength (RSSI) may cause connection timeouts.
- 🛡️ Security: Check if MAC address filtering is enabled on your router.
☑️ WiFi Diagnostic Checklist
Automate connection at boot
For servers and kiosks, it's critical that the WiFi connection is established automatically immediately after the operating system boots. In modern versions of Ubuntu, Netplan And NetworkManager This happens by default if the connection was marked as "autoconnect".
However, if you are using manual scripts or wpa_supplicant Without NetworkManager, you need to configure the corresponding systemd service. Creating your own unit file allows you to control the startup order of network services relative to other system components.
Additionally, you can use scripts in the directory /etc/network/interfaces.d/ (if using ifupdown) to set parameters. However, remember that mixing different network management methods (for example, Netplan and manual ifconfig) can lead to unpredictable results and conflicts.
How to make a connection a priority?
In NetworkManager, you can set the connection priority. Use the command nmcli connection modify "NetworkName" connection.autoconnect-priority 100The higher the number, the higher the priority when selecting a network.
What to do if the router has hidden the SSID?
Hidden networks don't broadcast their names. In nmcli, use the --hidden flag: nmcli dev wifi connect "Name" password "Password" hidden yesIn wpa_supplicant, add the line scan_ssid=1 to the network block.
Is it possible to connect to WPA3 via terminal?
Yes, if your adapter and drivers support the WPA3 standard. NetworkManager will automatically detect the security type. Make sure the wpa-micro or wpa_supplicant package is updated to the latest version.
How to forget a network in the terminal?
Use the command nmcli connection delete "Network_Name"This will delete the connection profile and all saved passwords for this network from the system memory.