How to Enable WiFi on Linux Using the Terminal: A Step-by-Step Guide

Working with the operating system Linux Often requires interaction with the command line, especially when the graphical interface fails to load or you're managing a server. Enabling a wireless connection in such situations becomes critical for accessing the network and repositories. Despite the abundance of graphical utilities, knowledge of console commands gives the administrator complete control over the network adapter.

There are several proven methods for activating WiFi, depending on the distribution and network manager used. The most common tools are NetworkManager, utilities from the package wireless-tools And wpa_supplicantThe specific method you choose depends on the default driver stack and configurations installed on your system.

In this article, we'll cover in detail the basic commands and steps for successfully connecting to an access point. You'll learn how to diagnose adapter status, scan the airwaves, and enter security settings. For modern distributions, the de facto standard is to use the nmcli utility, which is part of NetworkManager.

Diagnostics and checking the adapter status

Before attempting to enable a wireless network, you must ensure that the equipment is present and operating correctly. The first step should always be to check if the adapter is visible to the system. To do this, use the command ip link or more specialized iw dev, which displays a list of wireless interfaces.

If the interface is displayed as DOWN, this means it's physically present but software-disabled. Users often forget that laptops may have airplane mode or a hardware switch enabled. You can check for kernel-level blocking using a utility. rfkill.

sudo rfkill list all

In the output you will see the blocking status: Soft blocked (software) or Hard blocked (hardware). If the blocking is present, it must be removed before proceeding. If the interface is not listed, it may indicate driver issues.

Once the locks are removed, the interface should be accessible for management. Make sure you have root access, as most network commands require privileges. sudo.

Network management via NetworkManager (nmcli)

The most modern and convenient way to manage connections in distributions like Ubuntu, Fedora or Debian is the utility nmcliIt is a console client for the service. NetworkManager and allows you to perform all necessary operations without exiting to the graphical shell.

To get started, you need to start the network manager itself if it's stopped. Then you need to activate a specific WiFi adapter. Interfaces are usually called wlan0, wlp2s0 or similarly, as can be learned from the previous diagnostic step.

sudo nmcli radio wifi on

sudo nmcli dev set wlan0 managed yes

After activating the device, you can scan for available access points. This will allow you to see the network SSIDs and signal strength, which is important for choosing the optimal connection in noisy environments.

sudo nmcli dev wifi list

☑️ Check before connection

Completed: 0 / 4

Direct connection to the network is accomplished with a single command, specifying the network name and password. The manager will automatically create a connection profile and attempt to obtain an IP address via DHCP.

sudo nmcli dev wifi connect"Name_SSID" password"Your_Password"

⚠️ Attention: When you first connect to a new network, NetworkManager may ask for confirmation or create a configuration file in /etc/NetworkManager/system-connections/Make sure that the access rights to this directory are not changed, otherwise the password will not be saved.

📊 Which Linux distribution do you use most often?
Ubuntu
Debian
Arch Linux
CentOS/Fedora
Another

Using the iw utility and wpa_supplicant

In minimalist systems, where NetworkManager not installed by default, a bundle is used iw And wpa_supplicantThis method is more low-level and requires manual configuration of security settings, but it provides a complete understanding of the authentication process.

First, you need to open the interface and start scanning. Utility iw Allows you to see detailed technical information about frequencies and channels, which is useful when diagnosing problems with signal stability.

sudo ip link set wlan0 up

sudo iw dev wlan0 scan | grep SSID

Next, a configuration file is created for wpa_supplicant, where the SSID and hashed password are written. Using plaintext for the password is possible, but less secure. To generate a hash, you can use the command wpa_passphrase.

wpa_passphrase"MySSID""MyPassphrase" > /etc/wpa_supplicant.conf

Starting the connection process requires specifying the driver and interface. After successfully associating with the access point, you must launch the DHCP client to obtain an IP address; otherwise, the network will not function.

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

sudo dhclient wlan0

Command / Utility Purpose Complexity Dependencies
nmcli Full network management Low NetworkManager
iwconfig Basic setup (deprecated) Average wireless-tools
wpa_supplicant WPA/WPA2 authentication High No (basic)
dhclient Obtaining an IP address Low dhcp-client

Usage wpa_supplicant This is especially relevant on servers where resource conservation is critical. However, configuration files in this case require careful syntax control.

Problems with Broadcom drivers

Some Broadcom cards require proprietary drivers (bcmwl-kernel-source). Without them, the interface may not work even with the correct commands.

Setting up a static IP address in the terminal

Corporate networks or servers often require a fixed IP address instead of dynamically allocated via DHCP. Setting up a static address can be done through nmcli or by directly editing configuration files.

When using nmcli you need to change the connection method from auto on manual and enter the address, gateway, and DNS. This ensures that the settings will be preserved after a reboot and won't conflict with other devices.

sudo nmcli con mod"MyConnection" ipv4.addresses 192.168.1.50/24

sudo nmcli con mod"MyConnection" ipv4.gateway 192.168.1.1

sudo nmcli con mod"MyConnection" ipv4.dns"8.8.8.8 1.1.1.1"

sudo nmcli con mod"MyConnection" ipv4.method manual

If you are working with a classic configuration file /etc/network/interfaces (relevant for Debian/older versions), changes are made using a text editor. After making changes, you must restart the network service with the command sudo systemctl restart networking or sudo /etc/init.d/networking restart.

⚠️ Attention: Errors in specifying the gateway or subnet mask during manual configuration will result in loss of network access. Always check the syntax before applying changes, especially if you are connecting remotely.

Solving common connection problems

Even if you enter the commands correctly, the connection may fail. Often, the problem lies in drivers that don't support monitoring mode or have conflicts with the kernel. Check the logs via dmesg or journalctl -u NetworkManager helps to identify the cause of the failure.

Another common cause is an incorrect system time. WPA2-Enterprise and some WPA3 security protocols require time synchronization for successful authentication. Make sure this service is installed and running. chrony or ntpd.

  • 📶 Weak signal: Use the command iwlist wlan0 scanning To evaluate the signal level in dBm. Values ​​below -80 dBm are considered unstable.
  • 🔒 Password error: Make sure your keyboard layout matches what you expect, or use copy-paste to avoid typos.
  • 🔄 IP conflict: If the address is already taken, try clearing the DHCP arena with the command sudo dhclient -r before asking again.

In some cases, switching WiFi channels may be necessary if the current one is heavily polluted by neighboring routers. This can be done through the router settings, but Linux can tell you which channels are free.

Hidden networks

To connect to hidden SSIDs, you must explicitly specify the network name in the wpa_supplicant configuration with the scan_ssid=1 parameter.

Automation and profile saving

After successful setup, the connection is usually saved automatically. Profiles are stored in a secure system directory. You can manage them by deleting old ones or editing security settings without re-entering your password.

To view all saved connections in nmcli use the command nmcli con showThis allows you to quickly switch between known networks, such as between your home WiFi and a mobile hotspot.

nmcli con up"Home_WiFi"

nmcli con down"Office_Guest"

Regular network settings maintenance includes updating trusted network lists and deleting profiles no longer in use. This reduces the risk of automatically connecting to unsafe open networks with similar names.

How do I find out the name of my WiFi interface in Linux?

Use the command ip link or iw devNames usually start with "w" (wlan0, wlp3s0). If the interface is named "lo," it's a loopback device, not WiFi.

Why doesn't the sudo nmcli dev wifi list command show anything?

The interface may be blocked (check rfkill), disabled by software, or the driver doesn't support scanning. Also, make sure you're not too far from the router.

Is it possible to share WiFi from a Linux laptop via the terminal?

Yes, this is possible by creating a virtual access point (Hotspot) via nmcli or hostapd if the network card supports Master (AP) mode.

What should I do if I forgot the password for a saved WiFi network?

Passwords are stored encrypted in NetworkManager configuration files. You can view them using the command sudo nmcli -s -g 802-11-wireless-security.psk connection show "Network_Name", entering the root password.