# 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.&#x20;

This method is versatile and should work for various security protocols, including WEP, WPA, WPA2, and WPA3.

### <mark style="color:blue;">Enable Wireless Networking</mark>

Before configuring your Wi-Fi, ensure the wireless radio is enabled and set the correct country code to comply with local regulations:

<mark style="color:green;">**Set WLAN Country:**</mark> Open the `raspi-config` tool to set your country for wireless networking.

```bash
sudo raspi-config
```

Navigate to `Localisation Options` > `WLAN Country` and select your country.

<mark style="color:green;">**Check Wi-Fi Status:**</mark> Verify if the Wi-Fi radio is enabled.

```bash
nmcli radio wifi
```

If it returns `disabled`, enable it:

```bash
nmcli radio wifi on
```

### <mark style="color:blue;">Finding Networks</mark>

Scan for available Wi-Fi networks:

```bash
nmcli dev wifi list
```

This command displays a list of available networks. Identify the SSID (network name) you wish to connect to.

### <mark style="color:blue;">Connect to a Network</mark>

#### <mark style="color:green;">Secured Network</mark>

To connect to a secured network:

```bash
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.

#### <mark style="color:green;">Unsecured Network</mark>

For an unsecured network:

```bash
sudo nmcli dev wifi connect <example_ssid>
```

#### <mark style="color:green;">Hidden Network</mark>

For a hidden network, specify it's hidden:

```bash
sudo nmcli --ask dev wifi connect <example_ssid> hidden yes
```

### <mark style="color:blue;">Set Network Priority</mark>

Your Raspberry Pi can automatically connect to a preferred network among several known ones based on priority:

<mark style="color:green;">**Check Current Priority**</mark>

```bash
nmcli --fields autoconnect-priority,name connection
```

This command shows the priority values for known networks.

<mark style="color:green;">**Change Network Priority**</mark>

To prioritise a network, adjust its autoconnect priority:

```bash
nmcli connection modify "Pi Towers" connection.autoconnect-priority 10
```

This example sets "Pi Towers" as a preferred network with a priority of 10.

### <mark style="color:blue;">Confirm Connection</mark>

After connecting, confirm that your Pi is connected to the desired network:

```bash
nmcli dev wifi list
```

Look for an asterisk (\*) in the "IN-USE" column next to your network.

### <mark style="color:blue;">Additional Tips</mark>

* **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.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://education.raspberrypiaustralia.online/network-manager/wireless-networking-setup-on-raspberry-pi-using-command-line.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
