Wireless Networking Setup on Raspberry Pi Using Command Line
This comprehensive guide will walk you through setting up a wireless connection on your Raspberry Pi using the command line interface.
This method is versatile and should work for various security protocols, including WEP, WPA, WPA2, and WPA3.
Enable Wireless Networking
Before configuring your Wi-Fi, ensure the wireless radio is enabled and set the correct country code to comply with local regulations:
Set WLAN Country: Open the raspi-config
tool to set your country for wireless networking.
sudo raspi-config
Navigate to Localisation Options
> WLAN Country
and select your country.
Check Wi-Fi Status: Verify if the Wi-Fi radio is enabled.
nmcli radio wifi
If it returns disabled
, enable it:
nmcli radio wifi on
Finding Networks
Scan for available Wi-Fi networks:
nmcli dev wifi list
This command displays a list of available networks. Identify the SSID (network name) you wish to connect to.
Connect to a Network
Secured Network
To connect to a secured network:
sudo nmcli --ask dev wifi connect <example_ssid>
Replace <example_ssid>
with your network's SSID. You will be prompted to enter the network password.
Unsecured Network
For an unsecured network:
sudo nmcli dev wifi connect <example_ssid>
Hidden Network
For a hidden network, specify it's hidden:
sudo nmcli --ask dev wifi connect <example_ssid> hidden yes
Set Network Priority
Your Raspberry Pi can automatically connect to a preferred network among several known ones based on priority:
Check Current Priority
nmcli --fields autoconnect-priority,name connection
This command shows the priority values for known networks.
Change Network Priority
To prioritise a network, adjust its autoconnect priority:
nmcli connection modify "Pi Towers" connection.autoconnect-priority 10
This example sets "Pi Towers" as a preferred network with a priority of 10.
Confirm Connection
After connecting, confirm that your Pi is connected to the desired network:
nmcli dev wifi list
Look for an asterisk (*) in the "IN-USE" column next to your network.
Additional Tips
Editing Network Configurations: Directly edit connection configurations at
/etc/NetworkManager/system-connections/
.Security Note: Exercise caution when connecting to unsecured wireless networks.
Network Troubleshooting: If you encounter connection issues, recheck your SSID and password, and ensure your Raspberry Pi is within a good range of the Wi-Fi signal.
By following these steps, you can configure and prioritize wireless networks on your Raspberry Pi using the command line, providing flexibility and control over your device's network connections.
Last updated
Was this helpful?