Connecting to WiFi via the terminal in Kali Linux

Working with the operating system Kali Linux Security often involves using the command line, even for basic tasks like connecting to a wireless network. A graphical interface may not be available, for example, when working with server versions, over an SSH connection, or when debugging network modules. In such situations, knowing how to connect to WiFi via the terminal becomes a critical skill for any information security professional.

Unlike desktop distributions, where network management is hidden behind icons, Kali Linux gives you direct access to the network stack. This allows you not only to connect to access points but also to analyze traffic, conduct security audits, and manage interfaces at a low level. NetworkManager And wpa_supplicant — are the two main tools we will use to solve this problem.

Before you begin, make sure your wireless adapter is physically connected and detected by the system. Most modern USB adapters and integrated modules already have drivers included in the kernel, but in rare cases, manual installation of proprietary firmware files may be required. We'll cover standard scenarios that cover 95% of use cases.

Checking the status of the wireless adapter

The first step is always hardware diagnostics. You need to ensure that the system sees your WiFi module and that it's ready to use. The primary tool for viewing network interfaces in modern distributions is the utility ip. Enter the command ip link showto see a list of all network devices. Wireless interfaces usually have a prefix wl, For example, wlan0 or wlp2s0.

If the interface is displayed as DOWN, it must be activated. This is done with the command sudo ip link set dev wlan0 up, Where wlan0 is replaced with the name of your device. If the interface is missing from the list, it may indicate a problem with the device's drivers or physical connection. In some cases, the adapter may be blocked by software or hardware.

To check for blockages, use the utility rfkill. Team rfkill list will show the status of all wireless devices. If you see the status Soft blocked: yes, unlock the device with the command sudo rfkill unblock wifiHardware lock (Hard blocked) is usually solved by switching a physical switch on the laptop or by using function keys.

  • 📡 Use ip link to identify the wireless interface name.
  • 🔓 Apply rfkill unblock wifi to remove software restrictions.
  • 🔍 Make sure the interface is not in the down state DOWN.
⚠️ Note: If you plan to conduct network security audits, you may need to put the interface into monitor mode. However, for normal internet connectivity, the interface must remain in managed mode (managed mode).

Using NetworkManager (nmcli) to connect

The easiest and most modern way to connect to WiFi in Kali Linux is to use the console client. NetworkManager, known as nmcliThis tool is standard for most Debian-based distributions and allows you to manage connections without having to manually edit configuration files.

First, scan for available networks around you. Run the command nmcli dev wifi listYou'll see a list of access points with their SSID, signal strength, channel, and security status. If the list is empty, try refreshing it by adding a flag. --rescan yesThis is especially useful if you've just turned on your router or moved to another room.

To connect to a network with a password, use the following construction: nmcli dev wifi connect "Network_Name" password "Your_Password"Please note that quotation marks are required if the network name or password contains spaces or special characters. The system will automatically create a connection profile and attempt to obtain an IP address via DHCP.

nmcli dev wifi connect "HomeWiFi" password "SuperSecretPass123"

On some corporate networks or when using hidden SSIDs, the syntax may be slightly different. If the network is hidden, add the parameter hidden yesNetworks with WPA3 or Enterprise security may require additional settings, such as a username or certificates, but for home use, a password is sufficient.

  • 📝 Team nmcli dev wifi list shows available access points.
  • 🔑 The connection syntax requires you to specify the SSID and password in quotation marks.
  • 🔄 Automatic reconnection occurs if there is a saved profile.
⚠️ Note: The history of entered commands is saved in a file ~/.bash_historyIf you entered your password in cleartext, it is highly recommended to clear your history or use environment variables to improve security.
📊 What is your preferred connection method in Linux?
Graphical user interface (GUI)
nmcli (terminal)
wpa_supplicant (manual configuration)
Network TUI
Other

Manual configuration via wpa_supplicant

In situations where NetworkManager is missing, corrupted, or a minimalistic approach is required, NetworkManager comes to the rescue wpa_supplicantThis is a fundamental daemon, operating at a lower level than nmcli. It directly interacts with the wireless card driver and the WPA/WPA2 encryption protocols.

The connection process consists of several steps. First, you need to create a configuration file containing network information. You can generate a hashed password for security using the command wpa_passphrase "SSID" "password"The result of this command needs to be saved to a file, for example, /etc/wpa_supplicant/wpa_supplicant.conf.

Once the configuration is prepared, start the daemon by specifying the interface and path to the settings file: sudo wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf. Flag -B means running in the background. After this, the interface will be associated with the access point, but an IP address will not yet be obtained.

The final step is to obtain an IP address. This is done using a DHCP client, such as dhclient or dhcpcd. Team sudo dhclient wlan0 will request an address from the router. If everything goes well, you'll receive the address and be able to access the internet.

  • 🛠 wpa_passphrase generates a secure configuration file.
  • ⚙️ wpa_supplicant manages the authentication process.
  • 🌐 dhclient Requests an IP address after a successful connection.

☑️ Connection algorithm via wpa_supplicant

Completed: 0 / 4

This method requires more steps than using nmcli, but it provides a complete understanding of the processes occurring during connection. It's indispensable in minimalist Kali builds or when debugging driver issues where high-level managers may behave incorrectly.

Comparison of network management tools

The choice between nmcli And wpa_supplicant It depends on your goals. For everyday work and fast internet access NetworkManager is a preferred choice due to its simplicity and automation. It can save profiles, switch between networks, and handle login pop-ups.

On the other side, wpa_supplicant Provides more granular control and fewer dependencies. It's often used in automation scripts or on embedded systems. Understanding how both tools work makes you a more flexible administrator.

Characteristic nmcli (NetworkManager) wpa_supplicant iwconfig (deprecated)
Difficulty level Short Medium/High High
DHCP Automation Yes (built-in) No (dhclient required) No
Saving profiles Yes (automatically) Yes (manually in conf) No
WPA3 support Full Depends on the version Limited
Recommendation For daily use For scripts and servers Not recommended

Please note that the utility iwconfig, which was the de facto standard in the past, is now considered obsolete. It does not support modern encryption standards and has been replaced by the package iwHowever, it can still be useful for basic diagnostics, but for connection it is better to use modern tools.

Why is iwconfig deprecated?

The iwconfig utility only works with wireless interfaces and cannot manage new features of the mac80211 drivers. It does not support WPA3, mesh networks, or many modern operating modes. The modern iw package and nmcli utility have fully adopted its functionality, providing more stable operation.

Troubleshooting common problems

Even with proper configuration, errors can still occur. A common problem is the inability to obtain an IP address. This may be due to the router's DHCP server not responding or the address pool being exhausted. Try restarting the network service with the command sudo systemctl restart NetworkManager.

Another common issue is an incorrect password. You may not see a clear "incorrect password" error message in the terminal; the process will simply try to connect indefinitely. Check the system logs via sudo journalctl -u NetworkManager -f or dmesg | grep wifito see the details of the authentication failure.

Driver issues can also prevent connection. If the adapter is detected but won't turn on, firmware may need to be installed. In Kali Linux, the package firmware-realtek or firmware-atheros often solves problems with popular chipsets. Install them through apt, if they are absent.

  • 📉 A weak signal can cause connection drops.
  • 🔌 Reconnecting the USB adapter to a different port may help.
  • 📜 Logs journalctl contain the exact cause of the error.
⚠️ Note: Network settings and command interfaces may change with Kali Linux distribution updates. If the standard commands don't work, check the official repositories or manuals for the latest documentation.

Additional settings and optimization

For stable WiFi operation in Kali Linux, manual power management is sometimes required. Aggressive power saving settings can cause the adapter to shut down when idle. You can disable this by creating a configuration file for NetworkManager with parameter wifi.powersave = 2.

It's also worth paying attention to MAC addressing. To increase privacy when scanning and connecting, you can use random MAC addresses. nmcli this is configured by a parameter wifi.mac-addressThis is useful when working on public networks to avoid device tracking.

If you're using an external adapter with an antenna, make sure it's securely attached. Signal quality directly impacts speed and ping. You can monitor the signal strength in real time in the terminal by looking at the value. signal when scanning networks.

Configuring DNS servers can also improve response speed. By default, Kali uses servers provided by your ISP, but you can specify public DNS (such as Google or Cloudflare) in the connection settings for greater reliability and speed.

Frequently Asked Questions (FAQ)

How do I find out the name of my wireless interface?

Use the command ip link show or iwconfigThe name usually starts with wl (For example, wlan0). If the interface is not displayed, check the device connection and the presence of drivers.

Why is nmcli command not found?

In minimalist versions of Kali, the NetworkManager package may not be installed by default. Install it with the command sudo apt update && sudo apt install network-manager.

Is it possible to connect to a hidden network via terminal?

Yes, you need to know the exact network name (SSID) for this. nmcli use the flag hidden yes: nmcli dev wifi connect "SSID" password "PASS" hidden yes.

How do I forget a network I no longer want to connect to?

Use the command nmcli connection delete "Network_Name"This will remove the connection profile and password from the network manager's memory.

What should I do if the adapter doesn't see 5 GHz networks?

Check supported frequencies with the command iw listIf the adapter supports 5 GHz but there is no network, the wrong region may be selected. You can change the region using the command sudo iw reg set US (or your country code).