How to Connect Wi-Fi via the Linux Terminal: 3 Proven Methods

Connecting to Wi-Fi via the terminal in Linux may seem like a daunting task for beginners, but in practice, it's one of the most reliable ways to configure a network—especially when the graphical interface is unavailable or malfunctioning. Unlike Windows or macOS, where network setup typically boils down to a few clicks, the Linux terminal offers flexibility and low-level control. There's no one-size-fits-all solution: methods vary depending on the distribution, kernel version, and even the Wi-Fi adapter model.

In this article we will look at three main approaches: using NetworkManager (the most universal way), setting through wpa_supplicant (for systems without NetworkManager) and low-level commands iwconfig/iw (for experienced users). Each method has its own advantages: for example, nmcli is suitable for most modern distributions, while wpa_supplicant can save the day on minimalist systems like Arch Linux Without a graphical shell. And if you need to connect to a hidden network or set up a static IP, you can't do without a terminal.

Before you begin, make sure your Wi-Fi adapter is recognized by the system. To do this, run the command ip a or iwconfig — the output should show the wireless interface (usually wlan0, wlp3s0 or similar). If it is not there, you may need to install a driver (for example, for adapters Broadcom or Realtek).

📊 Which Linux distribution are you using?
Ubuntu/Debian
Arch Linux
Fedora
OpenSUSE
Another

1. Connecting via NetworkManager (nmcli)

NetworkManager — is the standard network manager in most distributions (Ubuntu, Fedora, Mint, etc.). Its command-line utility nmcli Allows you to manage connections without a graphical interface. The advantage of this method is support for WPA2/3, hidden networks, and automatic IP acquisition via DHCP.

To see a list of available networks, enter:

nmcli dev wifi list

If the command doesn't work, first activate your Wi-Fi adapter:

nmcli radio wifi on

To connect to an open network (without password):

nmcli dev wifi connect "Network_Name"

For a secure network (WPA2-PSK):

nmcli dev wifi connect "Network_Name" password "your_password"
  • 🔍 Network scanning: If the list is empty, refresh it with the command nmcli dev wifi rescan.
  • 🔒 Hidden networks: To connect to a hidden network, add the flag --hidden yes.
  • 📡 Network Priority: To have the system connect to this network automatically, use nmcli con mod "Network_Name" connection.autoconnect yes.
⚠️ Attention: If the Internet does not work after connecting, check if the firewall is blocking it (ufw or firewalld) traffic. Also, make sure DHCP is enabled on your network; otherwise, you'll have to configure the IP manually.

Check the name of the Wi-Fi interface (nmcli dev status)

Make sure Wi-Fi is turned on (nmcli radio wifi on)

Remember the exact network name (case sensitive!)

Prepare a password (for WPA2/3)

-->

2. Configuration via wpa_supplicant (for systems without NetworkManager)

wpa_supplicant — is a low-level wireless connection management daemon. It is indispensable in minimalist distributions (for example, Arch Linux without NetworkManager) or on servers. Unlike nmcli, this requires manual editing of the configuration file.

First, create a configuration file (eg. /etc/wpa_supplicant/wpa_supplicant.conf) and add the network data to it:

network={

ssid="Network_Name"

psk="your_password"

key_mgmt=WPA-PSK

}

To connect, follow these steps:

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

Then get an IP address via DHCP:

dhclient wlan0
Parameter in wpa_supplicant Description Example of meaning
ssid Wi-Fi network name "MyWiFi"
psk Password (for WPA-PSK) "12345678"
key_mgmt Authentication type WPA-PSK or SAE (for WPA3)
priority Network priority (if there are several) 5

If the network uses WPA3, replace key_mgmt=WPA-PSK on key_mgmt=SAEFor open networks, remove the lines with psk And key_mgmt, leaving only ssid.

⚠️ Attention: File wpa_supplicant.conf contains the password in clear text. Set access rights 600so that other users cannot read it: chmod 600 /etc/wpa_supplicant/wpa_supplicant.conf.
How do I connect to a network with Enterprise authentication (802.1X)?

For networks with RADIUS authentication (for example, in universities or offices), add the following block to the config:

network={

ssid="CorpWiFi"

key_mgmt=WPA-EAP

eap=PEAP

identity="your_login"

password="your_password"

phase2="auth=MSCHAPV2"

}

Here eap May be PEAP, TTLS or TLS (depending on network requirements).

3. Low-level commands: iwconfig and iw

Utilities iwconfig (obsolete) and iw (a modern alternative) allow you to control your Wi-Fi adapter directly. This method is suitable for diagnostics or when other methods fail. However, it requires manual IP configuration and doesn't support WPA/WPA2 out of the box—encryption will still require wpa_supplicant.

First, check the adapter status:

iw dev

or (for legacy systems):

iwconfig

To connect to an open network:

iw dev wlan0 connect "Network_Name"

For secure networks, first create a config for wpa_supplicant (as in the previous section), then connect:

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

dhclient wlan0

  • 🔄 Change channel: If the network is not visible, try specifying the channel manually: iw dev wlan0 set channel 6.
  • 📶 Signal check: Find out the signal level with the command iw dev wlan0 link.
  • 🔧 Debugging: For diagnostics use dmesg | grep wlan or journalctl -u wpa_supplicant.

4. Setting up a static IP address

By default, Linux obtains an IP address automatically via DHCP. However, if you need to set a static IP (for example, for a server or specific network rules), you can do so via the terminal.

For systems with NetworkManager:

nmcli con mod "Network_Name" ipv4.addresses 192.168.1.100/24

nmcli con mod "NetworkName" ipv4.gateway 192.168.1.1

nmcli con mod "NetworkName" ipv4.dns "8.8.8.8,8.8.4.4"

nmcli con mod "Network_Name" ipv4.method manual

nmcli con up "NetworkName"

For systems with wpa_supplicant edit /etc/network/interfaces (Debian/Ubuntu):

auto wlan0

iface wlan0 inet static

address 192.168.1.100

netmask 255.255.255.0

gateway 192.168.1.1

dns-nameservers 8.8.8.8 8.8.4.4

wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

After making changes, restart the network:

systemctl restart networking
⚠️ Attention: When using a static IP, make sure the address you choose doesn't conflict with other devices on the network (for example, it's not in the router's DHCP pool). Addresses in the range 192.168.1.100–192.168.1.200.

5. Diagnosing connection problems

If Wi-Fi doesn't connect, start by checking the adapter status:

ip link show wlan0

Make sure the interface is up UPIf not, activate it:

ip link set wlan0 up

Check if the system sees networks:

iw dev wlan0 scan | grep SSID

Common causes of problems:

  • 🚫 Driver not loaded: Check the output lsmod | grep iwlwifi (for Intel) or lsmod | grep rtl8xxxu (for Realtek).
  • 🔌 Adapter disabled: On some laptops, Wi-Fi is blocked by a hardware switch or key combination (e.g. Fn+F2).
  • 🔒 Incorrect password: Make sure that in the config wpa_supplicant The password is specified without quotes (if they are not part of the password).

For detailed diagnostics, run wpa_supplicant in debug mode:

wpa_supplicant -i wlan0 -c /etc/wpa_supplicant.conf -d

6. Automate connection at system startup

To connect Wi-Fi automatically at startup, set up autostart wpa_supplicant And dhclient through systemd.

Create a service file /etc/systemd/system/wpa_supplicant@.service:

[Unit]

Description=WPA supplicant daemon

After=sys-subsystem-net-devices-%i.device

[Service]

Type=simple

ExecStart=/sbin/wpa_supplicant -c /etc/wpa_supplicant/wpa_supplicant.conf -i %i

Restart=always

RestartSec=5

[Install]

WantedBy=multi-user.target

Activate the service:

systemctl enable wpa_supplicant@wlan0

systemctl start wpa_supplicant@wlan0

To obtain IP automatically, add to /etc/network/interfaces line:

up dhclient wlan0

Wi-Fi will now connect every time the system boots. To check the service status, use:

systemctl status wpa_supplicant@wlan0

FAQ: Frequently Asked Questions about Wi-Fi Connections in Linux

My Wi-Fi adapter isn't detected. What should I do?

First, check if the adapter is visible in the system:

lspci | grep -i network

or for USB adapters:

lsusb

If the adapter is not displayed, you may need to install a driver. To Broadcom use the package broadcom-sta-dkms, For Realtek RTL8188EUrtl8188eu-dkmsAfter installation, reboot the system.

How do I connect to Wi-Fi with a captive portal (e.g., in a hotel)?

First, connect to the network as usual (even if the internet is down). Then, open a browser in the terminal using elinks, lynx or w3m:

sudo apt install elinks

elinks http://example.com

You will be redirected to the authorization page. Enter your details and save cookies. Alternatively, you can use curl to emulate login (authorization form analysis required).

Is it possible to save a Wi-Fi password in encrypted form?

Yes, wpa_supplicant Supports storing passwords in encrypted format. First, generate a hash:

wpa_passphrase "Network_Name" "Your_Password"

The output will contain the line psk=... — copy it into the config file instead of the plaintext password. However, remember that the hash can still be extracted from the file, so restrict access to it (chmod 600).

How do I connect to a 5 GHz network if my adapter can't see it?

The issue may be due to regional restrictions. Check supported channels:

iw list | grep -A 10 "Frequencies"

If 5 GHz is not available, please set the correct region (eg. US):

sudo iw reg set US

sudo systemctl restart NetworkManager

Please note that in some countries (for example, Russia) 5 GHz channels have power limitations and require support DFS.

Why is Wi-Fi speed slower on Linux than on Windows?

This may be due to:

  • Outdated driver (check the kernel version and update it).
  • Lack of support 802.11n/ac (check iw list | grep "Supported interface modes").
  • Energy saving (turn it off: iw dev wlan0 set power_save off).

Also try explicitly specifying the Wi-Fi standard:

sudo iw dev wlan0 set type managed

sudo iw dev wlan0 set channel 36 HT40+