In this tutorial, we’ll be discussing how to connect your Raspberry Pi 4, running Ubuntu Server, to a Wi-Fi network. This can be particularly useful when you’re setting up your Raspberry Pi without a screen or keyboard.
To connect a Raspberry Pi 4 running Ubuntu Server to Wi-Fi, you can update the Netplan configuration file located at
/etc/netplan/50-cloud-init.yaml with the SSID and password of your Wi-Fi network. After applying the changes and rebooting the Raspberry Pi, it should automatically connect to the specified Wi-Fi network.
Before we start, ensure that you have the following:
- A Raspberry Pi 4 running Ubuntu Server.
- Access to the terminal of your Raspberry Pi, either directly or via SSH.
- Your Wi-Fi network’s SSID and password.
Updating the Netplan Configuration
Ubuntu Server uses Netplan to manage network configurations. To connect to a Wi-Fi network, we’ll need to update the Netplan configuration file located at
Open the file using a text editor like nano:
sudo nano /etc/netplan/50-cloud-init.yaml
Add the following lines under the
In this configuration:
wifisis the section where we define our Wi-Fi configurations.
wlan0is the name of the wireless network interface on the Raspberry Pi.
optional: truemeans that the boot process won’t wait for the Wi-Fi connection to be established.
access-pointsis where we define the Wi-Fi networks we want to connect to.
"WIFI-PASSWORD"are placeholders for your Wi-Fi network’s SSID and password. Replace them with your actual SSID and password.
dhcp4: trueenables DHCP, which allows your Raspberry Pi to automatically obtain an IP address.
After updating the file, save and close it.
Applying the Changes
To apply the changes, run the following commands:
sudo netplan --debug try
sudo netplan --debug generate
sudo netplan --debug apply
--debug flag is optional, but it can be useful for troubleshooting if the Wi-Fi connection doesn’t work.
try command checks if the new configuration works, the
generate command creates the necessary configuration files, and the
apply command applies the new configuration.
Rebooting the Raspberry Pi
Finally, reboot your Raspberry Pi:
After the Raspberry Pi reboots, it should automatically connect to the specified Wi-Fi network.
If you encounter any issues, you can check the system logs for any error messages related to the network interface or Netplan:
journalctl | grep wlan0
journalctl | grep netplan
These commands display any log entries that mention
netplan, which can help you identify any issues with the Wi-Fi connection or the Netplan configuration.
In this tutorial, we’ve learned how to connect a Raspberry Pi 4 running Ubuntu Server to a Wi-Fi network by updating the Netplan configuration. This can be particularly useful when setting up a headless Raspberry Pi. If you encounter any issues, don’t hesitate to check the system logs or consult the Netplan documentation.
Yes, you can connect your Raspberry Pi 4 to a Wi-Fi network without a screen or keyboard by updating the Netplan configuration file.
You can usually find the SSID and password of your Wi-Fi network on the back or bottom of your Wi-Fi router. If it’s not there, you can check the settings of your router using a device that is already connected to the Wi-Fi network.
Yes, you can connect your Raspberry Pi 4 to multiple Wi-Fi networks by adding additional Wi-Fi configurations in the Netplan configuration file. Simply duplicate the
wlan0 section and modify the SSID and password accordingly.
You can check if your Raspberry Pi 4 is connected to Wi-Fi by using the
ip addr show wlan0 command. If you see an IP address assigned to the
wlan0 interface, it means your Raspberry Pi is connected to Wi-Fi.
Yes, you can connect your Raspberry Pi 4 to a hidden Wi-Fi network by adding the hidden network’s SSID and password in the Netplan configuration file. Simply replace
"SSID-NAME" with the actual SSID of the hidden network.