« Back to Networking: Frequently Asked Questions

Show to clear the DNS cache with systemd

How to clear the DNS resolver cache with systemd?

To clear the systemd resolver cache use the resolvectl command with the 'flush-caches' subcommand.

resolvectl flush-caches

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

    Related articles

    Like to learn more? Here is a list of articles within the same category or having similar tags.

    Feedback

    Small picture of Michael Boelen

    This article has been written by our Linux security expert Michael Boelen. With focus on creating high-quality articles and relevant examples, he wants to improve the field of Linux security. No more web full of copy-pasted blog posts.

    Discovered outdated information or have a question? Share your thoughts. Thanks for your contribution!

    Mastodon icon