How To Clear DNS Cache in Linux

In this tutorial, you will learn to Clear or Flush DNS Cache in Linux.

A DNS cache (sometimes called a DNS resolver cache) is a temporary database, maintained by a computer’s operating system, that contains records of all the recent visits and attempted visits to websites and other internet domains.

In other words, a DNS cache is just a memory of recent DNS lookups that your computer can quickly refer to when it’s trying to figure out how to load a website.

When troubleshooting cache poisoning or other internet connectivity problems, a computer administrator may wish to flush (i.e. clear, reset, or erase) a DNS cache.

Since clearing the DNS cache removes all the entries, it deletes any invalid records too, and forces your computer to repopulate those addresses the next time you try accessing those websites. These new addresses are taken from the DNS server your network is set up to use.

Steps To Clear DNS Cache in Linux

To complete this guide, you must log in to your Linux server as a non-root user with sudo privileges.

Now follow the steps below.

Flush DNS Cache with systemd-resolved in Linux

The easiest way to flush the DNS on Linux, if you are using systemd-resolved, is to use the “systemd-resolve” command followed by “–flush-caches”.

Alternatively, you can use the “resolvectl” command followed by the “flush-caches” option.

# sudo systemd-resolve --flush-caches

# sudo resolvectl flush-caches

To confirm that you have to enter the following command:

sudo system-resolve --statistics

If you see that the “current cache size” is zero, you will get confirmation that your DNS cache has been cleared.

Conclusion

At this point, you have learned to Clear DNS Cache in Linux.

Hope you enjoy it.

Also, you may be like these articles:

Check Installed Linux Kernel in Command Line

Check What Service is Listening on a Specific Port on Linux

How To Troubleshoot DNS in Linux

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Leave a Reply

Stay informed and not overwhelmed, subscribe now!