How to Flush Local DNS Cache on Linux

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

Hello, friends. In this post, you will learn how to flush local DNS cache on Linux. This trick can improve your connection in some ways, and it’s worth doing from time to time. Let’s go.

In a nutshell, the DNS cache is a record of the websites we have visited. When we use our web browser to access websites, what we do is to request the DNS resolution of a domain. But occasionally, it is convenient to clear the cache to improve the connection and to meet certain needs.

An example of this is that if you have visited a website correctly, and it changes its IP address, the system may not be able to connect to it because when it queries the cache it still has the old address. The solution is basically to clear the cache.

Keep in mind that this cache can be stored both in the operating system and in the browser. In this post, we will delete the system cache.

Let’s get started.

How to Flush Local DNS Cache on Linux

The process is basic thanks to the resolvectl command that comes standard on modern distributions such as Fedora, Ubuntu, RHEL and Debian.

Thanks to this command, the process is easy to do, but first you need to check the status of the DNS cache.

Open a terminal and run

resolvectl statistics | grep -i cache    

You will get an output screen like this:

Cache                     
  Current Cache Size: 36  
          Cache Hits: 904 
        Cache Misses: 623 

And to flush the cache then, you have to run

resolvectl flush-caches

This command does not produce any output, but the process has been done well. If you want to check, you can query the cache again.

resolvectl statistics | grep -i cache    

You will see something like this

Flush the local DNS Cache
Flush the local DNS Cache

So, the process was successful.

Conclusion

Clearing the DNS cache is a simple thing to do, but it can solve some network problems.

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"
Angelo
Angelo
I am Angelo. A systems engineer passionate about Linux and all open-source software. Although here I'm just another member of the family.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest articles

Join us on Facebook