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
ubuntuand hostname israspberry.local):bashssh ubuntu@raspberry.local -
Check if
/etc/resolv.confis a symlink:bashls -l /etc/resolv.conf -
Remove if it is a symlink and create a static resolv.conf:
bashsudo rm /etc/resolv.conf sudo touch /etc/resolv.conf -
Edit the systemd-resolved configuration:
bashsudo vi /etc/systemd/resolved.conf -
Set the DNS servers:
iniDNS=8.8.8.8 8.8.4.4 # or DNS=1.1.1.1 1.0.0.1 -
Restart the
systemd-resolved:bashsudo systemctl restart systemd-resolved -
Update the
resolv.conf:bashnameserver 8.8.8.8 # or 1.1.1.1 nameserver 8.8.4.4 # or 1.0.0.1 -
Make the
resolv.conffile immutable:bashsudo chattr +i /etc/resolv.conf -
Verify the DNS Configuration:
bashresolvectl 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.
References
If you found this useful, you can buy me a coffee! Thanks for the support!