How to Connect to Wi-Fi Using a Terminal: A Complete Guide

Connecting to a wireless network via a graphical interface seems simple and intuitive, but for system administrators, developers, or enthusiasts, the command line offers much more. The terminal allows you to diagnose problems when the graphical shell is unresponsive or automate connections to hidden networks using scripts. It's more than just a way to "fix the internet"; it's a tool for deep control over the operating system's network stack.

In this article we will look at how to do this connecting to Wi-Fi via a terminal in various operating systems. We will look at standard Linux utilities, such as nmcli And wpa_supplicant, as well as Windows commands. Understanding these processes is essential if you're working with servers without a graphical interface or debugging network drivers.

Using the console gives you access to hidden settings not available in the standard settings. You can manually manage the wireless adapter's status, scan the airwaves for interference, and force a reconnection. Direct interaction with the network driver via the terminal can often bypass software lockups that occur when the GUI crashes.

Checking the status of the wireless adapter

Before attempting to connect, you need to make sure your wireless interface is active and correctly detected by the system. In Linux, this is done using the utility ip or iwconfig. Team ip link show will list all network interfaces, where you need to find a device with a name like wlan0, wlp2s0 or wifi0If the interface is marked as DOWN, it must be raised by the command sudo ip link set dev wlan0 up.

For Windows the situation is a little different, here a utility is used netsh. Launch netsh wlan show interfaces will show the Wi-Fi adapter's status, its SSID, and signal strength. It's important to ensure the interface status is "Connected" or at least "Enabled." If the adapter is disabled programmatically, it must be enabled through Device Manager or the appropriate PowerShell command.

⚠️ Attention: If the team iwconfig It can't find any wireless devices. The drivers may not be installed or the kernel module may be blocked. Check the output. dmesg | grep wifi to search for hardware initialization errors.

A common problem is the power saving mode, which can disable the adapter to save battery power. In Linux, this can be resolved by sudo iw dev wlan0 set power_save offMake sure you have superuser (root) privileges, as most network operations require elevated privileges. Without them, the commands will simply return an access error.

📊 What is your primary operating system?
Linux (Ubuntu/Debian)
Linux (Arch/Fedora)
Windows
macOS
Another Unix-like

Search for available networks and analyze SSIDs

The next step is to scan the airwaves to find available access points. In Linux, this is done using the command sudo iwlist wlan0 scan or more modern sudo iw dev wlan0 scanThe output will contain detailed information: MAC address (BSSID), frequency, signal strength, and network name (SSID). Look for the line ESSID for the name of your network.

In Windows, the equivalent is the command netsh wlan show networksIt will display a list of visible networks with their indexes and signal strength. If your network is hidden (not broadcasting its SSID), it will not be listed, and you will need to know the exact network name in advance to enter it manually. Hidden networks require special consideration when configuring profiles.

When analyzing your network list, pay attention to channels and bandwidth. Channel congestion in apartment buildings is a common cause of slow speeds. Below is a table of channel and frequency mappings for the 802.11b/g/n standard:

Range Channels Frequency (GHz) Peculiarities
2.4 GHz 1-13 2.412 - 2.472 High noise level
5 GHz (low) 36-48 5.180 - 5.240 Less interference, worse performance
5 GHz (high) 149-165 5.745 - 5.825 High speed, DFS channels
6 GHz 1-29 5.955 - 7.125 Wi-Fi 6E, minimal interference

Use the data you receive to select the optimal connection point. If you see multiple networks on the same channel, it makes sense to manually configure the router to a less congested channel, but using the client terminal, you're still only selecting the target. Write down the BSSID of the desired network, as this may be necessary to force a connection to a specific router in densely populated areas.

Connecting via NetworkManager (nmcli)

In modern Linux distributions such as Ubuntu, Fedora, and Debian, NetworkManager is the de facto standard. The command-line utility nmcli significantly simplifies the connection process. First, you need to make sure Wi-Fi is enabled with the command nmcli radio wifi on. Then perform a scan: nmcli dev wifi list.

To connect to an open network, the command will look simple: nmcli dev wifi connect"Network_Name"However, most networks are password protected. In this case, the flag is used. password. Full command syntax:

nmcli dev wifi connect"Your_SSID" password"Your_Password"

If the connection is successful, NetworkManager will create a connection profile that will be used automatically the next time the network is in range. This is the most reliable method for desktop systems. It automatically handles obtaining an IP address via DHCP and configuring DNS.

☑️ Check before connection

Completed: 0 / 4

Manual configuration via wpa_supplicant

In server environments or minimalist Linux installations, NetworkManager may be absent. This is where wpa_supplicant — a daemon that manages wireless connections. This is a more complex, but fundamental method. First, you need to create a configuration file, usually located in /etc/wpa_supplicant/wpa_supplicant.conf.

To generate a hashed password (so as not to store it in clear text), use the utility wpa_passphrase. Team wpa_passphrase"SSID""password" will output the configuration block that needs to be added to the file. Example of the configuration file contents:

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev

update_config=1

network={

ssid="MyHomeNetwork"

psk="hashed_password_or_plaintext"

key_mgmt=WPA-PSK

}

After creating the file, you need to start the daemon, specifying the interface and path to the configuration:

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

Next, you need to get the IP address. To do this, use the command dhclient or dhcpcd, For example: sudo dhclient wlan0If everything is done correctly, you will receive an address and be able to access the network. This method requires precision, as syntax errors in the config file will result in connection failure.

⚠️ Attention: File wpa_supplicant.conf contains passwords in cleartext (if hashing is not used). Set access rights chmod 600 on this file so that other users of the system cannot read it.

Connecting to Wi-Fi in Windows via CMD

Windows users can also manage Wi-Fi via the command line using the built-in tool netshThis is useful for creating deployment scripts or connecting to networks that aren't visible in the GUI. First, let's create an XML network profile. For this, it's convenient to use the export command for an existing profile or create a new one manually.

However, it is easier to use the direct connection command if the profile is already saved. The command netsh wlan show profiles will display a list of known networks. To connect, use:

netsh wlan connect name="Profile_Name" ssid="Network_Name"

If the profile is not saved, you can create it by connecting via the GUI once, or generate an XML file using netsh wlan export profileTo connect to a new network without a GUI, you will need to create an XML configuration file with security keys and add it with the command netsh wlan add profile filename="profile.xml".

What should I do if Windows says "Unable to connect"?

Often, the issue lies with the security type. Make sure the profile specifies the correct encryption algorithm (AES or TKIP). Try deleting the profile with the command 'netsh wlan delete profile name="Name"' and creating it again.

Diagnosing and resolving connection problems

Even if you enter the password correctly, the connection may fail. First, check the logs. On Linux, use journalctl -u NetworkManager -f or dmesg | tail immediately after a connection attempt. This will show at what stage the disconnect occurs: association, authentication, or IP acquisition.

A common error is an incorrect encryption type. If the network uses WPA3, but your adapter or driver is configured only for WPA2, the connection will fail. There may also be issues with MAC filtering on the router. Make sure the MAC address of your interface is allowed. You can find it with the command ip link (Linux) or ipconfig /all (Windows).

To reset network settings in Windows, the following command is effective: netsh winsock reset And netsh int ip reset, followed by a reboot. On Linux, restarting the service often helps: sudo systemctl restart NetworkManager. Don't forget that wireless card drivers can freeze, and in this case, physically reconnecting the module or command will help. rmmod And modprobe for the kernel module.

Frequently Asked Questions (FAQ)

How to find the MAC address of a Wi-Fi adapter in the terminal?

In Linux, use the command ip link show wlan0 or ifconfig wlan0