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

Working in the command line is often thought of as the domain of system administrators, but for the average user, it's a powerful tool for troubleshooting network problems. When the graphical interface freezes or a driver malfunctions, it's terminal Allows you to quickly diagnose and fix your connection. Understanding how to manually manage wireless interfaces gives you complete control over your network environment.

In this article we will look at how to connect to Wi-Fi networks using only the command line across various operating systems. Whether you're using Linux, macOS, or Windows, the basic principles remain the same: finding the adapter, scanning networks, and entering credentials. We'll cover specific commands and utilities that will make this process seamless.

The advantage of using the command line is the ability to automate and fine-tune settings unavailable in standard menus. You can see hidden networks, force channel changes, or check signal strength in great detail. This is especially useful when configuring servers without a graphical interface or for remote administration.

Checking the status of the wireless adapter

The first step before any connection is to check the presence of a wireless interface and its status. In Linux, the command ip link or more specialized iwconfigIf the adapter is disabled either programmatically or physically, no further steps will be successful, so diagnostics begin at this stage.

For macOS users, the situation is a little different, as the system uses its own set of utilities for network management. The key tool here is networksetup or airportIt's important to make sure Wi-Fi is not in airplane mode and that the interface is active to search for available hotspots.

⚠️ Note: If the command shows the status "DOWN" or "unavailable", try restarting the network manager or check if your antivirus is blocking access to the adapter.

In Windows, the main tool is the utility netsh or PowerShell. These commands not only allow you to view the interface's status but also force it to re-enable if it was previously disabled. This is critical, as many "lost Wi-Fi" issues are resolved by simply enabling the interface through the console.

  • 🔍 Use ip a to quickly view all network interfaces in Linux.
  • 🔍 On macOS, launch networksetup -listallhardwareports to identify a Wi-Fi device.
  • 🔍 In Windows PowerShell the command Get-NetAdapter will show the status of all connections.
📊 What is your primary operating system?
Linux
macOS
Windows
I use several systems

Search and scan for available networks

Once the adapter is activated, you need to find the network name (SSID) you plan to connect to. In Linux, the utility iwlist or nmcli Allows you to scan the airwaves and display a list of all visible access points, along with signal strength and encryption type. This helps you choose the network with the best connection quality.

On macOS, you can use the utility for scanning airport, which is usually hidden in system folders but accessible through the terminal. It provides a detailed list of networks, including the MAC addresses of access points and the channels they operate on. This information is useful if there is a lot of interference in the air.

Windows users can use the command netsh wlan show networks, which will display a list of available Wi-Fi networks. Pay attention to the "Signal" column, which shows the signal strength percentage. The higher the value, the more stable the connection will be once connected.

sudo iwlist wlan0 scan | grep -E 'ESSID|Quality'

When scanning, it's important to pay attention not only to the network name but also to the security type. Modern encryption standards, such as WPA3, provide better protection but may require newer drivers. If your card is older, it may not recognize newer networks or be able to connect to them.

Connecting to Linux via NetworkManager and wpa_supplicant

In Linux distributions, the most convenient way to manage connections is to use NetworkManager via utility nmcliIt allows you to create, edit, and activate connection profiles without manually editing configuration files. This significantly simplifies the process for beginners.

To connect to a network using a WPA2 password, simply enter a command with the network name and security key. The system will automatically create a profile and attempt to obtain an IP address via DHCP. If the connection is successful, you will see a corresponding notification in the terminal.

☑️ Checklist before connecting

Completed: 0 / 4

Older systems or minimalist builds may require the use of wpa_supplicantThis method is more labor-intensive, as it requires creating a temporary configuration file or passing parameters directly on the command line. However, it provides more control over the authentication process.

Method Complexity Flexibility Recommended use
nmcli Low Average Everyday use
nmtui Very low Average Working in pseudographics
wpa_supplicant High High Servers and scripts
iwconfig Average Low Legacy systems
⚠️ Warning: When using commands with a password, your access key may be saved in the console history. We recommend clearing the history or using secure input methods.

Managing Wi-Fi on macOS and Windows

In the macOS operating system, a combination of commands is most often used to connect via the terminal networksetupFirst, you need to select a Wi-Fi port, then enable it and specify the network to connect to. If the network is password-protected, the system will prompt you to enter it or allow you to pass it as an argument to the command.

For Windows, PowerShell provides a powerful set of cmdlets for managing wireless networks. Command Connect-NetConnectionProfile allows you to connect to a known profile. If the profile has not yet been saved, you can create one via netsh wlan add profile, by transferring an XML file with settings.

A Windows feature requires administrator privileges to perform most network operations. Without elevated privileges, commands simply won't execute or will return an access violation. This is a security measure to prevent unauthorized changes to network settings.

  • 🍏 On macOS, use networksetup -setairportnetwork for quick connection.
  • 💻 In Windows PowerShell the command netsh wlan show profiles will show saved networks.
  • 💻 To delete your old profile, use netsh wlan delete profile.

Both systems allow you to save profiles for automatic connection in the future. This eliminates the need to enter a password every time you are in range. Saved profiles can also be managed via the terminal.

Setting up static IP and DNS

Sometimes automatic address acquisition via DHCP does not work correctly or a fixed IP is required to access network resources. In Linux, via nmcli You can change the IPv4 method to "manual" and specify the address, gateway, and DNS servers. This ensures a stable connection for server tasks.

In Windows, setting up a static address is also available through netsh or PowerShell. It's important to correctly specify the subnet mask and default gateway, otherwise the internet won't work, even if you're connected to the router. An error in one bit of the mask can isolate your computer from the network.

Why might DNS not work?

Your provider's DNS servers are sometimes slow or block certain websites. Replacing them with public DNS servers (such as Google 8.8.8.8 or Cloudflare 1.1.1.1) often speeds up page loading and improves privacy.

Checking your DNS settings is critical for proper internet operation. If websites don't open by name but can be pinged by IP address, the problem is DNS. This can be easily diagnosed and fixed in the terminal by setting alternative name servers.

nmcli con mod "Home-Wifi" ipv4.addresses 192.168.1.50/24

nmcli con mod "Home-Wifi" ipv4.gateway 192.168.1.1

nmcli con mod "Home-Wifi" ipv4.dns "8.8.8.8 8.8.4.4"

Diagnosing and troubleshooting connection errors

If the connection fails, the first thing to do is check the system logs. In Linux, the commands dmesg or journalctl Messages from the wireless card driver will be displayed. These may indicate an incorrect password, DHCP timeouts, or encryption standard compatibility issues.

A common issue is an IP address conflict or incorrect security settings. Make sure you're using the correct encryption type (usually WPA2-PSK). You should also try forgetting the network and reconnecting, clearing old configuration files.

Windows has a built-in utility netsh wlan show interfaces Provides detailed information about the current connection status, including connection speed and radio type. If the speed is low, you may be far from the router or the channel is congested with neighboring devices.

⚠️ Note: Command line interfaces may be updated with new OS versions. If a command doesn't work, check the documentation for your specific distribution or Windows version.

Automation and profile saving

It's important for system administrators to be able to automate the connection process. Bash or PowerShell scripts can check for the presence of a network and connect to it at system boot. This is especially important for servers that don't have a graphical interface for selecting a network.

Saving profiles allows the system to automatically reconnect when the connection is lost. In Linux, profiles are stored in the directory /etc/NetworkManager/system-connections/They can be exported and imported to other computers for quick fleet setup.

Using a terminal to manage Wi-Fi gives you flexibility unavailable in graphical environments. You can create complex scenarios for switching between networks based on the time of day or the availability of specific resources. This transforms network connectivity from a chore into a manageable process.

FAQ: Frequently Asked Questions

How do I find the MAC address of my Wi-Fi adapter in the terminal?

In Linux, use the command ip link show or ifconfigThe MAC address will be listed as "link/ether" and consists of 6 pairs of hexadecimal digits. On macOS, the command networksetup -listallhardwareports will also show the Ethernet Address.

What should I do if the terminal says "command not found" for nmcli?

This means that the NetworkManager utility is not installed or added to the PATH. Try installing the package. network-manager via your package manager (apt, yum, pacman) or use alternative commands like wpa_supplicant.

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

Yes, it is possible. In nmcli you need to specify a parameter hidden yes When creating a connection, you'll need to know the exact network name (SSID), as scanning won't reveal it.

How can I save my password in my profile so I don't have to enter it every time?

When using nmcli The password is saved in the system keystore automatically. For wpa_supplicant The password can be hashed with the command wpa_passphrase and save the config file with access rights only for root.

Why isn't the internet working after successfully connecting to Wi-Fi?

Most likely, the problem is with DNS or the default gateway. Check if your interface has received an IP address with the command ip addrTry pinging the router's IP address and the external IP (e.g., 8.8.8.8). If you can ping but websites don't load, change your DNS.