# Configure Wi-Fi on Ubuntu Server for Raspberry Pi Using Netplan

> How to configure headless Wi-Fi networking on Ubuntu Server LTS (18.04, 20.04, 22.04, and 24.04) on a Raspberry Pi using Netplan and wpa_supplicant.

- Canonical URL: <https://carlossura.com/blog/ubuntu-server-raspberry-pi-3-wifi/>
- Author: Carlos Sura
- Published: 2020-03-13
- Updated: 2026-10-20
- Tags: linux, raspberry, ubuntu, wifi, netplan

Setting up headless Wi-Fi on a **Raspberry Pi** (Pi 3, Pi 4, or Pi 5) running **Ubuntu Server LTS** relies on **Netplan** (`/etc/netplan/50-cloud-init.yaml`), which generates backend configurations for `systemd-networkd` and `wpa_supplicant`.

Because YAML is whitespace-sensitive and modern versions of Netplan enforce strict file permissions when plain-text Wi-Fi passwords are present, a single tab character or overly permissive file mode can prevent `wlan0` from associating at boot.

---

## Update System Packages and Verify `wpasupplicant`

Before disconnecting the Ethernet cable, update the system packages and ensure `wpasupplicant` and `wireless-tools` are installed:

```bash
sudo apt update && sudo apt full-upgrade -y
sudo apt install -y wpasupplicant wireless-tools
```

Verify the wireless interface name (typically `wlan0` on Raspberry Pi boards):

```bash
ip -br link show
```

---

## Back Up and Edit `/etc/netplan/50-cloud-init.yaml`

Create a backup of the default cloud-init Netplan file and lock down its permissions to `0600` (required by Netplan on Ubuntu 22.04+ and 24.04+ to avoid `Permissions for /etc/netplan/50-cloud-init.yaml are too open` warnings):

```bash
cd /etc/netplan/
sudo cp 50-cloud-init.yaml 50-cloud-init.yaml.bak
sudo chmod 600 50-cloud-init.yaml
sudo nano 50-cloud-init.yaml
```

Add the `wifis` block under `network:`, using **spaces only** (never tabs) for indentation. Setting `optional: true` is critical so `systemd-networkd-wait-online.service` does not hang the boot sequence for 2 minutes if the Wi-Fi access point is temporarily unreachable:

```yaml
network:
  version: 2
  renderer: networkd
  ethernets:
    eth0:
      dhcp4: true
      optional: true
  wifis:
    wlan0:
      optional: true
      dhcp4: true
      access-points:
        "your-ssid-here":
          password: "your-wifi-password-here"
```

---

## Validate and Apply the Netplan Configuration

Always validate syntax and renderer output with `--debug generate` and `netplan try` (which automatically rolls back after 120 seconds if you lose SSH connectivity):

```bash
sudo netplan --debug generate
sudo netplan --debug try
```

Once confirmed, apply the configuration permanently and verify that `wlan0` obtains an IPv4 lease:

```bash
sudo netplan --debug apply
ip -4 addr show dev wlan0
```

Reboot the Raspberry Pi (`sudo reboot`) to confirm `wlan0` connects automatically on cold boot.
