Debian: How to enable WiFi from the command line

operating system Debian Renowned for its stability and minimalism, this often leaves users without a graphical interface for network management after installation. Unlike distributions aimed at beginners, pure Debian may not automatically activate wireless connections, requiring manual configuration via a terminal. This may seem daunting for those accustomed to mouse clicks, but mastering console utilities gives you complete control over the network stack.

Enabling WiFi via the command line is necessary not only on servers without a graphical shell, but also in cases where the graphical interface GNOME or KDE is not working correctly or is frozen. Understanding how network interfaces work at a low level allows you to diagnose driver and configuration issues hidden in the GUI. We'll cover activation methods for both modern versions and NetworkManager, as well as the classical approach through wpa_supplicant.

Before using commands, make sure you have physical access to a keyboard or an open SSH session if you're setting up a remote server. Any error in network settings can result in a lost connection, so it's important to enter commands carefully and verify the results of each step. In this article, we'll go from checking the adapter's presence to establishing a stable connection to the access point.

Checking for hardware and drivers

The first step in diagnostics is to ensure that the operating system physically sees your wireless adapter. Often, the problem lies not in the network settings, but in the absence of proprietary firmware (microcode) for a specific chipset model. Debian includes only open-source drivers by default, so many modern WiFi cards will require manual installation of packages from the repository. non-free.

To begin, run the command lspci for internal cards or lsusb For USB adapters, you can see the hardware IDs. If the device appears in the list but doesn't work, it's likely missing firmware. You can use the utility dmesg | grep firmwareto see kernel messages about firmware loading errors.

⚠️ Attention: If in the output dmesg If you see messages about "direct firmware load failed," this means the firmware file was found but couldn't be loaded, or it's not present on the system. Make sure the repository non-free-firmware added to /etc/apt/sources.list.

After installing the required firmware packages (for example, firmware-iwlwifi for Intel or firmware-realtek (For Realtek), you must reboot the system or kernel module. Only after successful driver initialization can you begin managing the interface state.

List of popular firmware packages for Debian

firmware-iwlwifi (Intel), firmware-realtek (Realtek), firmware-mwifi (Marvell), firmware-ath9k (Atheros)

Managing interface state via ip and ifconfig

In modern Linux distributions, the main network management tool is the utility ip from the package iproute2, which replaced the outdated one ifconfigHowever, knowledge of basic commands is necessary to quickly bring the interface into a state UP (active). First, you need to find out the name of your wireless interface, which usually starts with wl or wlan.

Enter the command ip link showto see a list of all network devices. Find your WiFi adapter in the list and note its status. If there's a flag next to the interface name, DOWN, the interface is administratively disabled and cannot scan or connect to networks.

sudo ip link set wlan0 up

After running this command, repeat ip link show and make sure the status has changed. If the interface doesn't go up, check for the driver or the physical WiFi switch on the laptop case. In some cases, you may need to unlock RF-kill by running sudo rfkill unblock wifi.

☑️ Interface diagnostics

Completed: 0 / 4

Using NetworkManager via Terminal (nmcli)

The most convenient way to manage WiFi in Debian with or without a graphical environment is to use a console client. NetworkManager, known as nmcliThis tool provides a powerful interface for scanning networks, saving connection profiles, and managing adapter status without having to write complex configuration files manually.

First, check the status of NetworkManager with the command nmcli general statusIf the service is active, you can scan for available access points around. The command nmcli dev wifi list will display a list of networks with SSID, operating mode, channel and signal strength.

nmcli command Description of action Example of use
nmcli r wifi on Enables WiFi adapter radio Activating the wireless module
nmcli dev wifi connect Connecting to the network nmcli dev wifi connect"MyWiFi" password"12345"
nmcli con show Show active connections Check current IP and status
nmcli con delete Deleting a profile Removing an erroneous configuration

To connect to a secure network, use the command nmcli dev wifi connect"SSID_network" password"your_password"NetworkManager will automatically create a connection profile and attempt to obtain an IP address via DHCPIf the connection is successful, you will see the message "Connection successfully activated".

Configuring wpa_supplicant for minimalist systems

In server builds of Debian, where NetworkManager is not installed, the main tool for working with encrypted WPA/WPA2 networks is the daemon wpa_supplicantThis approach requires creating a configuration file and manually starting the process, which provides flexibility but is less convenient for frequent switching between networks.

First, create a hashed password for your network so you don't have to store it in plaintext in the configuration. Use the utility wpa_passphrase, passing it the network name and password. The result of this command should be saved in a configuration file, usually located at /etc/wpa_supplicant/wpa_supplicant.conf.

wpa_passphrase"MyHomeWiFi""SuperSecretPassword" | sudo tee /etc/wpa_supplicant/wpa_supplicant.conf

After creating the configuration file, you need to start the daemon itself, specifying the interface name and the path to the configuration file. The command looks like this: sudo wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf. Flag -B means running in the background.

⚠️ Note: When using wpa_supplicant by itself, an IP address is not assigned automatically. After successfully associating with an access point, you will need to manually run dhclient or configure systemd-networkd to obtain an IP address.

This method is ideal for static configurations where the computer connects to only one known network. For mobile devices or laptops that frequently change environments, NetworkManager is preferable. wicd.

📊 Which network management method do you prefer?
Graphical UI (GNOME/KDE)
nmcli (NetworkManager)
wpa_supplicant (Manual)
Systemd-networkd

Obtaining an IP address and checking the connection

Once the wireless interface is enabled and associated with an access point, the next critical step is obtaining a network address. Most home and office networks use the protocol DHCP, which will automatically give you the IP, subnet mask, gateway and DNS servers.

If you use NetworkManager, this step happens automatically. If you use manual control via wpa_supplicant or ip, you need to run a DHCP client. Debian often uses it by default. dhclient or dhcpcd. Run the command sudo dhclient -v wlan0 to request an address.

To check if the connection is successful, use the utility ip addr show wlan0You should see a line inet with a local network address (e.g. 192.168.xx). If the address is received, try pinging an external resource, for example, ping -c 4 8.8.8.8.

Automate connection at system boot

For servers and desktop workstations, it's important for WiFi to connect automatically immediately after the operating system boots, without user intervention. Debian implements this through various mechanisms, depending on the network management method selected: systemd, NetworkManager or classic /etc/network/interfaces.

If you are using NetworkManager, you only need to successfully connect to the network once with the auto-connect flag enabled (it is enabled by default). NetworkManager.service The service will automatically restore the connection upon reboot. Make sure the service is enabled for startup: sudo systemctl enable NetworkManager.

For systems using /etc/network/interfaces, you need to add an interface description. However, for WiFi, this method is considered obsolete due to difficulties with processing WPA keys. The current de facto standard is to create a systemd service or use netplan (although the latter is more typical for Ubuntu).

[Unit]

Description=Wifi connection

After=network.target

[Service]

Type=simple

ExecStart=/usr/bin/nmcli con up id"MyHomeWiFi"

RemainAfterExit=yes

[Install]

WantedBy=multi-user.target

Save this file as /etc/systemd/system/wifi-connect.service and activate it with the command systemctl enable wifi-connectNow your device will automatically connect to the network every time you start the system, ensuring the availability of network services.

Problems with systemd

If the service fails to start, check the logs with journalctl -u wifi-connect -b . A common error is an attempt to start the service before the WiFi driver has loaded. Add the After=firmware-load.service dependency if necessary.

Frequently Asked Questions (FAQ)

Why doesn't the iwconfig command see my wireless adapter?

Utility iwconfig is part of the old package wireless-tools and often does not see interfaces controlled by the new driver mac80211. Use the command ip link or iw dev for up-to-date information about interfaces.

How to save a WiFi password in plaintext if wpa_passphrase doesn't work?

You can edit the file manually. /etc/wpa_supplicant/wpa_supplicant.conf and enter the password in the field psk="your_password" Without hashing. This is less secure, but it avoids key generation issues if the utility malfunctions.

My WiFi connection keeps disconnecting after a few minutes. What's causing this?

Most likely, the power saving mechanism is triggered. Try disabling it by creating a configuration file for NetworkManager or adding the parameter iw wlan0 set power_save off into the startup script. Also, check the logs for driver buffer overflows.

Is it possible to share WiFi from a Debian laptop to other devices?

Yes, it's possible. The feature is called Hotspot. In NetworkManager, this is done with the command nmcli dev wifi hotspot ssid"MyHotspot" password"12345678"The Linux kernel and adapter driver must support Master (AP) mode.