Sometimes simple things are absurdly complicated with Linux. I get it, new versions etc. But man… Anyhow, if you don’t want to waste an hour looking for a working solution to the problem of setting static IP address and DNS servers for you Raspberry Pi running Ubuntu or Raspberry OS (acutually, any linux distribution using netplan) here is what you have to do:
Edit /etc/netplan/50-cloud-init.yaml
with root rights. If file 50-cloud-init.yaml
does not exists, use already existing file or create a new one. Number in front of the name is used to determine order of execuction. So, 1-
will be executed first, 2-
second and so on.
sudo vim /etc/netplan/50-cloud-init.yaml

In this example I want to set eth0
to use static IP of 10.0.2.6
and net mask 255.255.0.0
(which is an equivalent of /16 mask) and DNS servers from Cloudflare and Google.
network:
version: 2
ethernets:
eth0:
optional: true
dhcp4: false
addresses: [10.0.2.4/16]
gateway4: 10.0.0.1
nameservers:
addresses: [1.1.1.1, 8.8.8.8]
After making changes to the network configuration, apply it with
sudo netplan apply
And verify if custom configuration was correctly set using
resolvectl status

Leave a Reply