A DNS or domain name server can be described as the most important part of your Internet link. DNS translates domain names to and from IP addresses so that we do not need to remember or store a list of all the IP addresses of websites we ever want to access. Our systems also maintain a list of DNS records so that we can access frequently visited websites faster thanks to the fast resolution of IP addresses. This cache in our system needs to be cleaned from time to time. This cleanup is necessary because websites can change their addresses over and over again, so it is recommended to avoid IP address conflicts by clearing the cache. Clearing the cache is also a good way to clean up junk data residing on our systems.
So, let’s see how we can clear the DNS cache on our Debian systems.
We have completed the commands and procedures mentioned in this article for the Debian 10 Buster system. Since we use the Linux command line – Terminal to clear the cache, you can open it by searching through the application Launcher.
Access to the Application Launcher can be obtained using the Super / Windows key on your laptop.
Method 1: use systemd resolution
On most Linux systems, the systemd-resolver daemon runs. Your system already uses this for many things. So, let’s use it to clear the cache with the following command:
$ sudo systemd-resolve --flush-caches
If after running the command you receive the following message,
Run the following command to enable the service in your Debian:
$ sudo systemctl enable systemd-resolved.service
Then run the command “systemd-resolve-flush-caches” again.
You can then check the statistics to make sure your cache size is now zero, so it is cleared. Run the following command to view statistics:
$ sudo systemd-resolve --statistics
The size of cache 0 in the above output indicates that the DNS cache is cleared.
Method 2. Using the ‘/etc/init.d/networking utility.
Another way to clear the DNS cache is to restart the /etc/init.d/networking utility. To do this, run the following command in your terminal:
$ sudo /etc/init.d/networking restart
Or use the command:
$ sudo service networking restart
Now you have learned two effective methods for flushing the DNS cache in Debian. In both cases, the process is quite simple and does not require a reboot of the Linux system.
Two ways to clear the DNS cache in Debian 10 (Buster)