The DNS or the Domain Name Server can be characterized as the most essential part of your link to the internet. The DNS translates the domain names to and from the IP addresses so that we don’t need to remember or keep a list of all the IP addresses of the websites we ever want to access. Our systems also maintain a list of DNS records so that we can access our frequently visited websites faster through quick resolution of IP addresses. This cache on our system needs to be flushed from time to time. This is required because websites may change their addresses time and again, so it is a good idea to avoid IP conflict by clearing the cache. Flushing the cache is also a good way to clear unnecessary data residing on our systems.
So let us see how we can flush the DNS cache on our Ubuntu Systems.
We have executed the commands and procedures mentioned in this article on an Ubuntu 18.04 LTS system. Since we are using the Linux command line-the Terminal to flush the cache, you can open it through the system Dash or the CTRL+ALT+T shortcut.
Method 1: Using systemd-resolve to flush DNS-Cache
Most Ubuntu and Debian systems are running the systemd-resolve daemon. Your system already uses it for a lot of things. So let us use it for flushing the cache through the following command:
$ sudo systemd-resolve --flush-caches
You can then check the statistics in order to make sure that your cache size is now zero, thus cleared. Run the following command in order to view the statistics:
$ sudo systemd-resolve --statistics
You cache size 0 in the above output shows that the DNS cache has been cleared.
Method 2: Using dns-clean to flush DNS-Cache
Another way to clear the DNS cache is by starting the dns-clean utility. Run the following command in your Terminal to do so:
$ sudo /etc/init.d/dns-clean start
You have now learned two effective methods to clear your DNS cache. In both the cases, the process is pretty simple and does not require you to restart your Linux system.