Connecting to Wi-Fi via a graphical interface seems intuitive, but what if the graphics card drivers aren't installed, the screen isn't working, or you're administering a server without a GUI? In such cases, command line becomes the only tool for setting up a network. This guide will help you connect to a wireless network on Windows 10/11, Linux (Debian/Ubuntu, Arch) and macOS without using a mouse - only using text commands.
We'll cover not only the basic connection commands, but also troubleshooting, saving network profiles, managing priorities, and even hidden features like connecting to Wi-Fi Direct or access points with WPA3-EnterpriseIf you're a system administrator, an enthusiast, or just want to understand how networks work at a low level, this article is for you.
Warning: working with the command line requires special attention. A typo in a command can lead to a lost connection or reset. But don't worry—we'll explain each step in detail and provide solutions for common errors.
1. Preparation: Checking the adapter and drivers
Before connecting to Wi-Fi, make sure your wireless adapter is recognized by the system and has the correct drivers installed. Without these, no commands will work.
On Windows open Command prompt as administrator (Win + X → Terminal (Administrator)) and run:
netsh wlan show drivers
In the output, find the following lines:
- 🔹
Supported radio type— it should be802.11n,802.11acor802.11ax(Wi-Fi 4/5/6). - 🔹
Hosted network support—Yes(if you plan to distribute Wi-Fi). - 🔹
Pluggable interface type—Native Wi-Fi Driver(if the driver is correct).
If you see an error instead "Unable to find any wireless devices", Means:
- 🔌 The adapter is physically disconnected (check the button
Wi-Fion a laptop or a switch on a USB adapter). - 🔧 The driver is not installed (download from the manufacturer's website, for example, for Intel AX200 or Realtek RTL8821CE).
- 🖥️ The adapter is broken (check in
Device Manager- if there is a yellow triangle next to the device, this is a hardware problem).
On Linux The adapter is checked using the command:
iwconfig
Look for the interface with the name wlan0, wlp3s0 or similar. If it is not there, install the driver (for example, for Broadcom you will need a package bcmwl-kernel-source).
On macOS use:
networksetup -listallhardwareports
Find in the output Wi-Fi or AirPort (on older Macs) If the adapter is missing, reboot SMC (For MacBook Pro before 2018: Shift + Control + Option + Power).
2. Connecting to Wi-Fi on Windows via netsh
Utility netsh (Network Shell) is the primary tool for managing networks in Windows. It allows you to connect to a network, save a profile, and even set up automatic connections.
First, get a list of available networks:
netsh wlan show networks
In the results, find the name (SSID) the desired network and its security parameters (Authentication And Cipher). For example:
SSID 1: MyWiFi
Network type: Infrastructure
Radio type: 802.11ax
Authentication: WPA2-Personal <--- Important for the connection command!
Encryption: CCMP
Now connect to the network. If the network open (without password):
netsh wlan connect name="MyWiFi"
If the network password protected, first create a profile:
netsh wlan add profile filename="C:\path\to\profile.xml"
But it's easier to generate a profile directly in the team. For WPA2-PSK (the most common type):
netsh wlan add profile name="MyWiFi" ssid="MyWiFi" keyMaterial="mypassword" keyType=persistent
After adding the profile, connect:
netsh wlan connect name="MyWiFi"
Ping to the router (ping 192.168.1.1)|IP Check (ipconfig /all)|Speed test (speedtest-cli)|Saving a profile for automatic connection-->
If the connection fails, please check:
- 🔐 The password is correct (case-sensitive!).
- 📡 Signal level (
netsh wlan show networks mode=bssid— look forSignal). - 🔄 Router operating mode (if you have
802.11n, and the router only works in802.11ac, the connection will not take place).
What to do if netsh It gives the error "Unable to connect to the network"
This error often occurs due to incompatible security types. Try explicitly specifying the authentication type:
netsh wlan set profileparameter name="MyWiFi" authentication=WPA2PSK encryption=AESIf that doesn't help, update the adapter driver or check the router settings (sometimes changing the channel helps).
Auto to a fixed one, for example, 6).3. Managing Wi-Fi in Linux via nmcli And wpa_supplicant
In most Linux distributions, network management is handled by NetworkManagerIts command interface is nmcli — allows you to connect to Wi-Fi in several commands.
First, check the NetworkManager status:
sudo systemctl status NetworkManager
If the service is not active, start it:
sudo systemctl start NetworkManager
Now get a list of available networks:
nmcli device wifi list
Or in the newer syntax:
nmcli -f ALL dev wifi
To connect to open network:
nmcli dev wifi connect"MyWiFi"
For secure network (WPA2):
nmcli dev wifi connect"MyWiFi" password"mypassword"
If nmcli doesn't work (for example, on server distributions without GUI), use wpa_supplicantFirst, create the config:
wpa_passphrase"MyWiFi""mypassword" | sudo tee /etc/wpa_supplicant.conf
Then connect:
sudo wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant.conf
And get the IP via DHCP:
sudo dhclient wlan0
Connection problems in Linux are often related to:
- 🐧 Lack of firmware for the adapter (install the package
firmware-ralinkorfirmware-iwlwifiFor Intel). - 🔌 Radio blocking (
rfkill list- IfSoft blocked: yes, unlock:rfkill unblock wifi). - 📶 Wrong region (
iw reg get- If00, set yours:sudo iw reg set RU).
4. Connecting to Wi-Fi on macOS via networksetup
macOS offers a utility networksetup for managing networks from the terminal. It is less flexible than netsh or nmcli, but covers the basic tasks.
First, get a list of network interfaces:
networksetup -listallhardwareports
Find Wi-Fi or AirPort and remember it Device (usually en0 or en1).
Turn on Wi-Fi (if disabled):
networksetup -setairportpower en0 on
Get a list of available networks:
networksetup -listpreferredwirelessnetworks en0
If your network is not listed, add it:
networksetup -addpreferredwirelessnetworkatindex en0"MyWiFi" 0 WPA2"mypassword"
Where:
en0— interface;"MyWiFi"— network name;0- priority (0 -);WPA2— security type;"mypassword"- password.
Connect to the network:
networksetup -setairportnetwork en0"MyWiFi""mypassword"
Common errors on macOS:
- 🍎
Error: -3906— Incorrect password or security type. Check the register! - 🔄
Error: -3910— the adapter is disabled. Enable it using the command above. - 📡
Error: -3905— Network not found. Make sure the router is turned on and within range.
5. Diagnosing problems and troubleshooting
If the connection fails, start with diagnostics. Here are the universal commands for all operating systems:
| Problem | Diagnostic command (Windows) | Diagnostic command (Linux/macOS) |
|---|---|---|
| No networks available | netsh wlan show networks mode=bssid |
sudo iwlist wlan0 scan | grep SSID |
| The connection is broken | ping 8.8.8.8 -t (stability check) |
ping -c 100 8.8.8.8 |
| No IP address | ipconfig /all (look for Autoconfiguration IPv4) |
ip a or ifconfig |
| Slow speed | netsh wlan show interfaces (check Receive rate) |
iwconfig wlan0 | grep"Bit Rate" |
Critical error: If you can't access the internet after connecting to Wi-Fi, but still receive an IP address (e.g., 192.168.1.100), the problem is most likely with DNS. Check it with the command nslookup google.com — if there is no response, enter the DNS manually:
netsh interface ip set dns"Wi-Fi" static 8.8.8.8
Other common problems and solutions:
- 🔌 The adapter does not turn on: on Windows, check the service
WLAN AutoConfig(services.msc), on Linux -rfkill. - 🔒 Incorrect password: in Linux/Mac, the password can be reset via
nmcli con mod"MyWiFi" wifi-sec.key-mgmt wpa-psk wifi-sec.psk"newpassword". - 📶 Weak signal: try connecting to the router via cable and change the channel to
1,6or11(less busy).
How to reset network settings to factory defaults
On Windows:
netsh winsock reset
netsh int ip reset
ipconfig /flushdnsOn Linux:
sudo nmcli networking off
sudo nmcli networking on
sudo systemctl restart NetworkManagerOn macOS:
sudo ifconfig en0 down
sudo ifconfig en0 up
networksetup -renewdhcp en06. Automation: scripts for quick connection
If you frequently need to connect to the same network, automate the process using scripts.
For Windows create a file connect_wifi.bat:
@echo offnetsh wlan connect name="MyWiFi"
timeout /t 5
ping -n 1 8.8.8.8 | find"TTL=" >nul && (echo Connected successfully!) || (echo Connection error)
pause
For Linux (bash script connect_wifi.sh):
#!/bin/bashnmcli dev wifi connect"MyWiFi" password"mypassword" || {
echo "Connection error. Checking adapter..."
ip a | grep wlan
}
Make it executable:
chmod +x connect_wifi.sh
For macOS (AppleScript connect_wifi.scpt):
do shell script"networksetup -setairportnetwork en0 MyWiFi mypassword" with administrator privileges
Automation tips:
- 📁 Save scripts in
C:\Scripts\(Windows) or/usr/local/bin/(Linux/macOS). - 🔑 Don't store passwords in plaintext - use environment variables or
read -sfor input. - 🕒 Set up a script to run automatically when you log in (via
Task Schedulerorcron).
7. Security: How to protect your connection
Connecting via the command line is no less secure than via the GUI, but it requires attention to detail. Here are the key points:
1. Password encryption:
- 🔐 In Windows, passwords are stored in
C:\ProgramData\Microsoft\Wlansvc\Profiles\Interfacesin encrypted form, but they can be extracted using utilities like WirelessKeyView. - 🐧 In Linux, passwords are stored in
/etc/NetworkManager/system-connections/in open form (though only root is accessible).
2. Network authentication:
- 🕵️ Before connecting to public Wi-Fi, check
BSSIDrouter (netsh wlan show networks mode=bssid). Fraudsters can deploy a fake network with the sameSSID. - 🔍 Use
WPA3instead ofWPA2, if your router supports it. On Windows:
netsh wlan set profileparameter name="MyWiFi" authentication=WPA3-Personal
3. Limitation of rights:
- 👤 On Linux/Mac, run network commands as a regular user, not
root(usesudoonly when necessary). - 🛡️ Turn it off
WPSOn the router, this function is vulnerable to brute-force attacks.
8. Advanced features: hidden networks, priorities, Wi-Fi sharing
The command line allows you to configure things that are not available in the graphical interface.
1. Connect to a hidden network (without broadcasting SSID):
On Windows:
netsh wlan add profile name="HiddenWiFi" ssid="HiddenWiFi" keyMaterial="password" keyType=persistent
netsh wlan connect name="HiddenWiFi" ssid="HiddenWiFi"
On Linux:
nmcli dev wifi connect"HiddenWiFi" password"password" hidden yes
2. Network Priority Management:
On Windows, networks are connected in the order they are added. To change the priority:
netsh wlan set profileorder name="MyWiFi" interface="Wi-Fi" priority=1
On macOS:
networksetup -ordernetworkpreferences en0"MyWiFi""BackupWiFi"
3. Wi-Fi distribution (Windows):
Turn your laptop into a hotspot:
netsh wlan set hostednetwork mode=allow ssid=MyHotspot key=password123
netsh wlan start hostednetwork
Then turn on Internet sharing in Network and Control Center or via:
netsh interface ipv4 set address "Local Area Connection* 12" static 192.168.137.1 255.255.255.0netsh routing ip nat install
netsh routing ip nat add interface"Wi-Fi" full
netsh routing ip nat add interface "Local Area Connection* 12" private
4. Connecting to Wi-Fi Direct (P2P):
On Linux, check support:
iw list | grep"P2P"
Start the access point:
sudo systemctl start wpa_supplicant
wpa_cli -i wlan0 p2p_group_add
⚠️ Attention: Wi-Fi distribution via hostednetwork on Windows 10/11 may not work on some adapters (eg. Realtek RTL8188EU). In this case, use third-party utilities like Connectify or mHotspot.
FAQ: Frequently Asked Questions
Is it possible to connect to Wi-Fi via CMD if I don't have administrator rights?
On Windows, most commands netsh wlan Administrator rights are required. However, you can:
- Create a network profile in advance (with admin rights) and then connect without rights.
- Use PowerShell with parameter
-ExecutionPolicy Bypassto bypass some restrictions.
On Linux/Mac, a normal user can connect to saved networks, but adding new ones requires sudo.
How do I connect to Wi-Fi with WPA3-Enterprise (for example, at a university)?
For WPA3-Enterprise on Windows:
netsh wlan add profile filename="C:\path\to\enterprise_profile.xml"
Where enterprise_profile.xml must contain:
<WLANProfile><name>UniWiFi</name>
<SSIDConfig><SSID><name>UniWiFi</name></SSID></SSIDConfig>
<connectionType>ESS</connectionType>
<MSM><security>
<authEncryption><authentication>WPA3-Enterprise</authentication>
<encryption>AES</encryption>
<useOneX>true</useOneX>
<EAPType>25</EAPType> <!-- TTLS -->
</authEncryption></security></MSM>
</WLANProfile>
On Linux use wpa_supplicant with config:
network={ssid="UniWiFi"
key_mgmt=WPA-EAP
eap=TTLS
identity="student@uni.edu"
password="yourpassword"
phase2="auth=MSCHAPV2"
}
Why doesn't Windows automatically connect to Wi-Fi after rebooting?
Reasons and solutions:
- Service
WLAN AutoConfigdisabled: run it throughservices.msc. - The network profile is corrupted.: delete it (
netsh wlan delete profile name="MyWiFi") and add again. - Driver problems: Update your adapter driver or roll back to a previous version.
- IP conflict: set a static IP or reset the TCP/IP stack (
netsh int ip reset).
How to connect to Wi-Fi on a server without a GUI (e.g. Ubuntu Server)?
On server distributions without NetworkManager use wpa_supplicant:
- Install
wpa_supplicantAndwireless-tools: - Create a config:
- Connect:
- Add to startup (
/etc/rc.local):
sudo apt install wpasupplicant wireless-tools
wpa_passphrase"MyWiFi""mypassword" | sudo tee /etc/wpa_supplicant.conf
sudo wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant.conf
sudo dhclient wlan0
wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant.conf
dhclient wlan0
Is it possible to see the password for a saved network via the command line?
Yes, but the methods are different:
Windows:
netsh wlan show profile name="MyWiFi" key=clear
Look for the line Key Content.
Linux (NetworkManager):
sudo grep psk= /etc/NetworkManager/system-connections/MyWiFi
macOS:
security find-generic-password -wa"MyWiFi"
⚠️ Attention: Extracting passwords requires administrator privileges. On corporate PCs, this may violate security policy.