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.
<img alt="Debian Terminal" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/04/echo/word-image-137.png" ezimgfmt="rs rscb10 src ng ngcb10" height="213" loading="lazy" src="data:image/svg xml,” width=”221″>
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
<img alt="Flush DNS cache using systemd" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/04/echo/word-image-138.png" data-ez ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="45" loading="lazy" src="data:image/svg xml,” width=”524″>
In case you get the following message after running the command,
<img alt="systemd error message" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/04/echo/word-image-139.png" data-ez ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="84" loading="lazy" src="data:image/svg xml,” width=”734″>
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:Advertisement
$ sudo systemd-resolve --statistics
<img alt="Systemd resolver statistics" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/04/echo/word-image-140.png" data-ez ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="302" loading="lazy" src="data:image/svg xml,” width=”736″>
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
<img alt="Flush DNS cache by restart networking service" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/04/echo/word-image-141.png" data-ez ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="117" loading="lazy" src="data:image/svg xml,” width=”732″>
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.