16

How can I flush the DNS cache in Debian 9.1 with KDE?

5
  • 2
    Which one? Debian 9 has ISC's BIND, unbound, Knot Resolver, and PowerDNS Recursor. And there are even more different softwares (dbndns, djbdns) in Debian "sid". All with caches.
    – JdeBP
    Aug 20, 2017 at 17:02
  • All cached DNS entries which were fetched from the external DNS servers. I'd be interested in what each of these are about but after all I'm just looking for a simple way to delete all cached entries.
    – mYnDstrEAm
    Aug 20, 2017 at 17:18
  • 1
    All of the cached entries in what software? Which caching software are you running?
    – JdeBP
    Aug 20, 2017 at 17:28
  • I'd like to find out. I did not install anything in particular for DNS caching.
    – mYnDstrEAm
    Aug 20, 2017 at 18:36
  • 2
    Please show the contents of your /etc/host.conf and /etc/resolv.conf files. Are you sure you have a DNS cache? Aug 22, 2017 at 8:34

5 Answers 5

18

If using systemd-resolved as your DNS resolver (i.e. the hosts line of your /etc/nsswitch.conf file includes the word resolve and/or /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
3
  • 8
    Please elaborate on what this command is supposed to do.
    – Mio Rin
    Jul 24, 2018 at 13:14
  • Got this with both command: Failed to flush caches: Unit dbus-org.freedesktop.resolve1.service not found.
    – SAMPro
    Aug 17, 2022 at 4:35
  • Both sd_bus_open_system: No such file or directory in debian 11 by WSL2.
    – huang
    Jan 21 at 22:37
7

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.

3

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 sudo.

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.

5
  • Welcome to the site and thank you for your contribution. Please edit your answer to add some words on which OS flavor/version you are using. The reason is that yours seems to use SysV-Init, whereas in particular in the Linux world, systemd is currently the standard, and the service name and syntax to use are different there.
    – AdminBee
    Apr 8, 2020 at 9:38
  • @AdminBee Nope, this answer works for me, though I have systemd as init and systemctl restart networking works too.
    – Arnie97
    Jul 29, 2020 at 16:54
  • It is really weird, nslookup my.domain.tld returns the new IP address while ping my.domain.tld goes to the old one. Restarting the networking service fixes this.
    – Arnie97
    Jul 29, 2020 at 16:58
  • @Arnie97 Yes, the answer may work because currently there is limited backwards-compatibility support for the init.d mechanism, but it is unlikely to survive long into the future.
    – AdminBee
    Jul 30, 2020 at 8:12
  • 2
    @Arnie97 Some versions of nslookup will always bypass any local caches and will instead read /etc/resolv.conf and automatically contact the nameserver(s) found in there directly (unless the command line includes a specific nameserver to query). On the other hand, ping will always use the currently configured resolver, which may or may not include a caching feature.
    – telcoM
    Sep 23, 2021 at 6:44
2

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
4
  • 3
    Would it make sense to flush the cache if one needs to first install nscd? Isn't nscd required for DNS caching? Or is it only needed for flushing it?
    – mYnDstrEAm
    Aug 20, 2017 at 16:11
  • Not true at all: you do not need nscd to have DNS caching feature. Installing a DNS resolver is enough to have DNS caching. Aug 20, 2017 at 22:04
  • 2
    The libc stub resolver does not cache. If nscd is installed and configured to cache DNS requests, its DNS cache can be invalidated by nscd -i hosts. Installing it definitely won't help with avoiding caching. BTW nscd is rather unstable, I recommend unscd instead of it anyway, which has the same interface. Aug 22, 2017 at 7:45
  • 1
    The install failed in my Debian 10 VM due to lack of DNS. Rebooting the host (Windows 10) fixed it, but then i didn't need nscd anymore. Jun 9, 2021 at 13:01
2
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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .