Configure Google/Cloudflare DNS for Raspberry Pi
Introduction
If you have a Raspberry Pi device and wish to use Google Public DNS or 1.1.1.1 for your Pi, you've come to the right place. This tutorial shows you how to configure DNS settings manually on your Pi system.
Prerequisites
- A Raspberry Pi device running Ubuntu 24.04 OS.
- Basic knowledge of Linux system.
Step-by-step Guide
-
SSH to your Pi device (assumed username is
ubuntu
and hostname israspberry.local
):ssh [email protected]
-
Check if
/etc/resolv.conf
is a symlink:ls -l /etc/resolv.conf
-
Remove if it is a symlink and create a static resolv.conf:
sudo rm /etc/resolv.conf sudo touch /etc/resolv.conf
-
Edit the systemd-resolved configuration:
sudo vi /etc/systemd/resolved.conf
-
Set the DNS servers:
DNS=8.8.8.8 8.8.4.4 # or DNS=1.1.1.1 1.0.0.1
-
Restart the
systemd-resolved
:sudo systemctl restart systemd-resolved
-
Update the
resolv.conf
:nameserver 8.8.8.8 # or 1.1.1.1 nameserver 8.8.4.4 # or 1.0.0.1
-
Make the
resolv.conf
file immutable:sudo chattr +i /etc/resolv.conf
-
Verify the DNS Configuration:
resolvectl status Global Protocols: -LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported resolv.conf mode: foreign DNS Servers: 8.8.8.8 8.8.4.4 Link 2 (eth0) Current Scopes: DNS Protocols: +DefaultRoute -LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported DNS Servers: 8.8.8.8 8.8.4.4 DNS Domain: com
Conclusion
You have now successfully configured the DNS system using one of the Internet's fastest DNS directories.