How to Flush DNS in Linux

Published on Aug. 22, 2023, 12:15 p.m.

To flush the DNS cache in Linux, the method may vary depending on the DNS resolver or service running on your system. Here are a few methods you can try:

  1. Using systemd-resolved:

On systems running the systemd-resolved service, you can use the following command to flush the DNS cache:

sudo systemd-resolve --flush-caches
  1. Using dnsmasq:

If you’re using dnsmasq, you can clear the DNS cache by restarting the service:

sudo /etc/init.d/dnsmasq restart
  1. Using nscd:

If you’re using the nscd service, you can flush the DNS cache by restarting the service:

sudo /etc/init.d/nscd restart
  1. Clearing the DNS cache manually:

If the above methods don’t work, you may need to clear the DNS cache manually by removing the files where the DNS cache is stored. On most Linux distributions, DNS cache files are typically located in the /var/lib/ directory. You can try removing the relevant files using the rm command:

sudo rm /var/lib/systemd/resolv/cache

Note that removing cache files manually can cause unexpected behavior, so you should only do so if you’re sure it’s safe to do.

I hope this helps you flush the DNS cache on your Linux system!

Tags:

related content