« Back to Networking: Frequently Asked Questions

Show to clear the DNS cache with systemd

When using systemd, it is common to have the resolve daemon being responsible for handling DNS requests. It might be possible that a previous query is cached in this local resolver. To clear out this cache, we need the resolvectl in combination with the flush-caches subcommand.

Clear DNS cache

On modern systemd implementations, run the following command:

resolvectl flush-caches

Under normal conditions, this command won’t show any result.

If your Linux distribution is older, then use systemd-resolve --flush-caches instead.

To confirm that the cache is empty, retrieve the statistics and look at the current cache size.

# resolvectl statistics
DNSSEC supported by current servers: no

Transactions                
Current Transactions: 0
  Total Transactions: 145185
                            
Cache                       
  Current Cache Size: 0
          Cache Hits: 30468
        Cache Misses: 46205
                            
DNSSEC Verdicts             
              Secure: 0
            Insecure: 0
               Bogus: 0
       Indeterminate: 0

In this case is the cache size back to zero, which is the expected result. The DNS cache is now empty and can be slowly filled again when new DNS requests are made.

Learn more about resolvectl

This article uses the resolvectl command to achieve its tasks. Want to learn how to use it or additional options that may be available?

Other questions related to Networking

Feedback

Is the described answer not working or incorrect, got another tip or question? Share your thoughts!