I am working on scripting a way to flush dns cache on different linux distros. I want to support doing this with Ubuntu-server, Ubuntu-desktop, Centos8-desktop, and Centos7-server(nogui)

I have built 4 vms of each.

For ubuntu its easy. I can just run sudo systemd-resolve --flush-caches and that does the trick.

However for the centos distros I cant seem to find a way to accomplish clearing the cache or even understanding how DNS is working. What I have read online is that for centos/rhel I can use either dnsmasq or nscd based off this link, but my results are different...

On the centos8 box, I found the dnsmasq service was stopped and disabled after deployment. Trying to start service gave an error that port 53 was taken. I looked up ss -tulpn and found that port 53 was taken by virb0 interface, which is apart of libvirtd. IT seems kvm is installed by default in centos8 stream? Either way I am curious how dns / caching even works with this service enabled. How do I clear a cache on a centos host that has libvirtd enabled?

On the cnetos7 box, I found no dnsmasq or nscd service. So I am kind of puzzled how dns caching even works at all?

How can I determine how dns is cached on the centos8 and centos7 hosts. How do I look at the current dns cache? and how do I clear the cache?

Note I have two nameserver configured in my /etc/resolve on each centos box.

2 Answers 2


Short answer, dns caching does not appear to be enabled by default on centos7 and centos8.

Ok so I found this post and it details what I thought. Without systemd there was no dns caching on linux boxes. There were two alternative options which were nscd service or dnsmasq. It seems nscd was flaky and not found on newer boxes. dnsmasq was no included by default on all boxes so that would need to be installed and enabled.

I was able to get the centos8 box to work based off this post. It seems dnsmasq, libvirt, and systemd-resolve are all installed. But none of them are really enabled to do the work of caching. It needs to be enabled manually. After I systemctl start systemd-resolved.service and systemctl enable systemd-resolved.service that fixed the centos8 box.

The centos7 box has nothing on it to enable caching. So I will have to figure out how to set that up. Probabbly will set up systemd-resolved to stay normalized with NetworkManager, systemd, and todays trends.


You can try with command (as root):

resolvectl flush-caches

If you have nscd just restart it. Also check if you have AD bind and sssd can cache some records.

  • That does not work, anything systemd-resolve or resolvectl on these boxes gives the following error Failed to flush caches: Unit dbus-org.freedesktop.resolve1.service not found.
    – Dave
    Feb 25 at 18:23
  • @Dave, IMHO in such case you do not have any DNS cache. Feb 25 at 18:25
  • @Dave, if you have AD bind check also sssd Feb 25 at 18:27
  • 1
    hmmm more resarch, I found this post bugzilla.redhat.com/show_bug.cgi?id=1855252. I tried enabling systemd-resolved.service and that worked! I can now use resolvectl flush-caches. Not so much on the centos7 box. Why the hell wouldn't that service be enabled out of the box? Weird.
    – Dave
    Feb 25 at 18:30
  • @Dave I assume it's not enabled as most people will be using bind/named or using a local dns system. I would be really hacked of if it was enabled.
    – Bib
    Feb 25 at 18:40

You must log in to answer this question.

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