Flushing your DNS cache on Ubuntu 20.04

Often enough I run into this little problem: I make a DNS change and want to see the results. When I check for the changes though it looks as if nothing has changed, and sometimes this is caused by my system’s DNS cache.

Clearing the cache on Ubuntu 20.04 can be done with the following command: sudo systemd-resolve --flush-caches, you can verify that the caches have been emptied by following that up with the command systemd-resolve --statistics which then gives an output like shown below:

DNSSEC supported by current servers: yes

Transactions               
Current Transactions: 0    
  Total Transactions: 21870
                           
Cache                      
  Current Cache Size: 0    
          Cache Hits: 6722 
        Cache Misses: 15158
                           
DNSSEC Verdicts            
              Secure: 7783 
            Insecure: 21703
               Bogus: 0    
       Indeterminate: 0    

The text and numbers will vary per setup, the “Current Cache Size” should however display a value of 0 to indicate your cache has been cleard.

If you are running dnsmasq next to the standard systemd-resolve like I do, restarting dnsmasq (with sudo systemctl restart dnsmasq) will ensure its caches are cleared to (otherwise you may still end up getting cached results).

And that’s all that I have for this very short post. If you have feedback on this article or have questions based on its contents then feel free to reach out to me on Twitter or through e-mail.