operating system Raspberry Pi OS (formerly Raspbian) is configured by default to automatically connect to the network if you first create a file wpa_supplicant.conf on the boot partition of the memory card. However, in real-world use, situations often arise where the graphical interface is unavailable, SSH access is blocked due to network outages, or you're working with a headless version of the board. In such cases, the only tool left is the command line, which requires precise parameter input.
Connection Raspberry Pi Connecting to a wireless network via a terminal gives the user full control over the authorization process and allows for low-level troubleshooting. This is especially true for older models, such as Raspberry Pi Zero or Raspberry Pi 1, where drivers may be unstable, or when using specific USB adapters. Understanding the workings of network managers in Linux is a key skill for any single-board computer owner.
In this article, we will look at all the current configuration methods: from manually editing text files to using interactive utilities like wpa_cli And nmcliYou'll learn not only how to enter passwords, but also how to understand why connections are being dropped and how to forcefully change the channel or security protocol to ensure stable operation of your device in a home or office environment.
Checking the status of the wireless interface
Before entering any connection commands, you need to make sure the system sees your Wi-Fi adapter. In modern versions Raspberry Pi OS (especially on Debian Bookworm) network interfaces may be named differently than in older versions. For initial diagnostics, use the command ip link or more detailed iwconfig, which will show a list of available wireless devices.
If you see an interface with a name like wlan0, meaning the driver has loaded and the device is ready to use. The absence of such an interface may indicate a problem with the drivers or the physical connection of the USB dongle. It's important to check whether the radio interface is blocked by software, as this is a common cause of networks becoming "invisible."
To view the connection status and signal quality in detail, you can use the utility iwlistIt allows you to scan the airwaves and obtain technical information about available access points, including frequency and encryption level. This is the first step before attempting authorization, ensuring that your access point is actually "heard" by the board.
Using the wpa_cli utility for configuration
One of the most reliable ways to manage wireless connections in Linux is the utility wpa_cliShe interacts directly with the demon. wpa_supplicant, which is responsible for security and authorization. This method is preferred for server builds that don't use the heavyweight NetworkManager. To get started, launch interactive mode by entering the command sudo wpa_cli -i wlan0.
Within the interactive shell, you need to create a new network configuration. First, run the command add_network, which will return the network number (usually 0). Then the parameters are set sequentially: set_network 0 ssid "Network_Name" And set_network 0 psk "Password"Please note that the SSID and password must be enclosed in quotation marks if they contain special characters.
☑️ Check before connecting via wpa_cli
After entering all the parameters, the network must be enabled using the command enable_network 0 and save the changes permanently with save_configIf everything went well, you will receive confirmation. OKExit from interactive mode is performed by the command quitThis method is good because the changes are applied instantly and do not require a system reboot.
⚠️ Attention: When using
wpa_cliIn interactive mode, changes are not automatically saved after exiting the commandsave_configis required to write settings to the configuration file, otherwise you will have to configure the Raspberry Pi again after rebooting.
Manually editing the wpa_supplicant.conf file
For users who prefer to work with text editors like nano or vim, direct editing of the configuration file is the most transparent method. File /etc/wpa_supplicant/wpa_supplicant.conf Contains all known networks and their parameters. This approach allows you to quickly copy a pre-configured configuration block from another device or backup.
Open the file with root privileges, adding a new section networkThe block structure must be strict: indication ssid, psk (password) and key_mgmt (encryption type, usually WPA-PSK). For hidden networks, you need to add the parameter scan_ssid=1, otherwise the Raspberry Pi may ignore the access point that is not broadcasting its name.
network={ssid="MyHomeWiFi"
psk="SuperSecretPassword123"
key_mgmt=WPA-PSK
}
After saving the file, you must restart the network service or the board itself for the changes to take effect. Newer OS versions may also use the system connman or NetworkManager, which can intercept control. In this case, manual editing wpa_supplicant.conf may be ignored unless other managers are disabled.
How to generate a password hash?
For increased security, you can avoid storing your password in plaintext. Use the wpa_passphrase "SSID" "Password" command in the terminal. This will generate a pre-built network block with a hashed PSK key, which you can paste into your configuration file.
Connecting via NetworkManager (nmcli)
In desktop versions Raspberry Pi OS and newer builds are used by default NetworkManagerThis is a powerful tool that manages all network connections via the command line using the utility nmcliThis approach differs from the classical one. wpa_supplicant and requires an understanding of the concept of "connections" rather than just interfaces.
To connect to a new network, first scan for available options with the command nmcli dev wifi listFind the desired network in the list and use the connection command: nmcli dev wifi connect "SSID" password "Password"The system will automatically create a connection profile, configure encryption, and attempt to obtain an IP address via DHCP.
Advantage nmcli The advantage of NetworkManager is the ease of managing multiple profiles. You can easily switch between home Wi-Fi, a mobile hotspot, and your work network without manually editing files. Furthermore, NetworkManager automatically restores the connection if the connection is lost, which is crucial for devices. Internet of Things.
| Parameter | Description | Example of meaning |
|---|---|---|
| SSID | Wireless network name | Home_5G |
| BSSID | MAC address of the access point | 00:1A:2B:3C:4D:5E |
| MODE | Operating mode (Infra/Ad-hoc) | Infra |
| CHANNEL | Frequency channel | 36 (5 GHz) |
| RATE | Connection speed | 86.7 Mbps |
Setting up a static IP address
By default Raspberry Pi obtains an IP address dynamically via DHCP. However, servers, CCTV cameras, or smart home systems often require a static address so that the device is always accessible via the same IP address. This configuration is done in the file /etc/dhcpcd.conf, which is standard for Debian-based systems.
At the end of the file you need to add a configuration block for the interface wlan0Here you specify the desired IP address, subnet mask, gateway (router), and DNS servers. It's important to select an address within your local network range but outside the pool of addresses assigned by the router's DHCP server to avoid conflicts.
interface wlan0static ip_address=192.168.1.50/24
static routers=192.168.1.1
static domain_name_servers=192.168.1.1 8.8.8.8
After making changes, restart the service. dhcpcd team sudo service dhcpcd restartCheck the settings are applied via ip addr show wlan0If the static address is not applied, check the file syntax for extra spaces or typos, as the configurator is formatting-sensitive.
⚠️ Attention: Don't set a static IP address that matches the router's IP address (usually .1) or the address of another important device on the network. This will result in loss of access to both devices and will require a router reset.
Diagnosing and troubleshooting connection problems
If the connection fails the first time, don't panic. The most common causes of errors are an incorrect password or incompatible encryption protocols. You can find the exact reason for the failure in the system logs. Use the command journalctl -u wpa_supplicant or dmesg | grep wlan to view system messages related to the wireless module.
A weak signal is a common problem. Raspberry Pi, especially models with built-in Wi-Fi, are sensitive to interference from USB 3.0 ports and power supplies. If the signal strength (RSSI) is below -80 dBm, the connection will be unstable. In such cases, using a USB extender to extend the antenna or switching to the 2.4 GHz frequency, which penetrates walls better, can help.
It's also worth paying attention to the region. By default, the Raspberry Pi may be configured for a region GB (UK), which allows different channels and power levels than Russia or the US. This can cause the card to simply "not see" your network. You can change the region in the file /etc/wpa_supplicant/wpa_supplicant.conf, adding a line country=RU (or your country code).
Questions and Answers (FAQ)
How to connect to a hidden network (Hidden SSID)?
To connect to a network that hides its name when editing wpa_supplicant.conf add parameter scan_ssid=1 inside the network block. When using wpa_cli run the command set_network 0 scan_ssid 1 before turning on the network. This will force the adapter to actively poll the airwaves for a specific SSID.
Why can't Raspberry Pi 3 see 5 GHz networks?
The Raspberry Pi 3 and Zero W models only support the 2.4 GHz band. To use the 5 GHz band, you need a Raspberry Pi 4, Raspberry Pi 400, or Raspberry Pi 5. Also, make sure your router settings don't allow older devices to use 5 GHz only if you're trying to connect them to a dual-band network.
How to reset all WiFi settings?
The easiest way is to delete the contents of the file /etc/wpa_supplicant/wpa_supplicant.conf (leaving only the basic country settings) or delete connection profiles in NetworkManager using the command nmcli connection delete "Profile_Name"After this, the system will behave as new when searching for networks.
Is it possible to use a USB Wi-Fi adapter instead of the built-in one?
Yes, most modern USB adapters with Realtek or MediaTek chips are supported by the Linux kernel by default. However, some models may require additional drivers (firmware), which can be found in the repository. firmware-realtek or on the chip manufacturers' GitHub.