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 a quick resolution of IP addresses. This cache on our system needs to be flushed from time to time. This flushing 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 Debian systems.
We have executed the commands and procedures mentioned in this article on a Debian 11 system. Since we are using the Linux command line-the Terminal to flush the cache, you can open it by searching for it through the Application Launcher search.
The Application Launcher can be accessed by using the Super/Windows key from your laptop.
Method 1: Using systemd-resolve
Most Linux 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
In case you get the following message after running the command,
Run the following command in order to enable the service on your Debian:
$ sudo systemctl enable systemd-resolved.service
Then again run the “systemd-resolve –flush-caches” command.
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
Your cache size 0 in the above output shows that the DNS cache has been cleared.
Method 2: Using the ‘/etc/init.d/networking’ utility
Another way to clear the DNS cache is by restarting the /etc/init.d/networking utility. Run the following command in your Terminal to do so:
$ sudo /etc/init.d/networking restart
Or use the command:
$ sudo service networking restart
You have now learned two effective methods to clear your DNS cache on Debian. In both cases, the process is pretty simple and does not require you to restart your Linux system.