Configure Google/Cloudflare DNS for Raspberry Pi

Raspberry Pi DNS
Raspberry Pi DNS

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

  1. SSH to your Pi device (assumed username is ubuntu and hostname is raspberry.local):

    ssh [email protected]
    
  2. Check if /etc/resolv.conf is a symlink:

    ls -l /etc/resolv.conf
    
  3. Remove if it is a symlink and create a static resolv.conf:

    sudo rm /etc/resolv.conf
    sudo touch /etc/resolv.conf
    
  4. Edit the systemd-resolved configuration:

    sudo vi /etc/systemd/resolved.conf
    
  5. Set the DNS servers:

    DNS=8.8.8.8 8.8.4.4 # or DNS=1.1.1.1 1.0.0.1
    
  6. Restart the systemd-resolved:

    sudo systemctl restart systemd-resolved
    
  7. Update the resolv.conf:

    nameserver 8.8.8.8 # or 1.1.1.1
    nameserver 8.8.4.4 # or 1.0.0.1 
    
  8. Make the resolv.conf file immutable:

    sudo chattr +i /etc/resolv.conf
    
  9. 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.

References

Comments