How can I flush the DNS cache in Debian 9.1 with KDE?
systemd-resolved as your DNS resolver (i.e. the
hosts line of your
/etc/nsswitch.conf file includes the word
/etc/resolv.conf contains the line
nameserver 127.0.0.53), then this command will flush its cache:
$ sudo systemd-resolve --flush-caches
A newer version of this command seems to be:
$ sudo resolvectl flush-caches
If no DNS name servers (BIND, unbound, Knot Resolver, PowerDNS Recursor, and others) or a DNS resolver (like dnsmasq) or a DNS cache (like nscd) are installed, and they are not installed by default, there is no DNS cache except the cache that a web browser (Firefox, Chrome, etc) might keep. Just re-starting the web browser will clear the DNS cache it keeps.
If any DNS server has been installed, probably restarting the service will clear its cache (for example):
# sudo systemctl restart bind9
The only other local network cache possible is the one that a DNS server running on the network router might keep, just reboot the router.
Also this worked for me: Open the Terminal (either from a menu or an icon or by pressing Ctrl+Alt+T), and type:
sudo /etc/init.d/networking restart
in the terminal.
It cleared my DNS cache, so I could see the WWW page I had been working on with the DNS name I had allocated it. The DNS allocation was done remotely via the Web hosting service. The sudo command via the Terminal asked for the password, and it was my normal user's password since I used
I am using MX Linux 19.1_x64 patito feo and it supports and includes both systemd and init-V functionality and kernels. It is based on Debian GNU/Linux buster 10 stable, and is a desktop distribution called MX Linux 19.1 "patito feo". That is why I can use the command "sudo /etc/init.d/networking restart" without problems in it.
Here is how to flush the DNS cache in Linux:
- Open your Terminal.
- Restart the name service cache daemon by executing this command:
sudo /etc/init.d/nscd restart
There are some cases when the nscd daemon might not be installed. In Ubuntu (and other Debian-based distros) you can install it from your Terminal by executing this command:
apt-get install nscd
sudo systemd-resolve --flush-caches
In case you get the following message after running the command:
Failed to flush caches: Unit dbus-org.freedesktop.resolve1.service not found.
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