NetworkGuide

How to flush the DNS cache on Linux

On this page
  1. Step 1: find out which resolver you run
  2. Step 2: flush systemd-resolved
  3. Step 3: flush nscd or dnsmasq instead
  4. Confirm the cache is empty
  5. When there’s nothing to flush

To flush the DNS cache on Linux you first have to know which resolver is doing the caching, because unlike Windows there is no single universal command. On modern Ubuntu, Debian and Fedora that resolver is systemd-resolved, and sudo resolvectl flush-caches clears it instantly. Older or lighter systems use nscd or dnsmasq, each cleared its own way, and a surprising number of Linux machines run no local cache at all, so there is genuinely nothing to flush. Here's how to tell which resolver you are running, the exact command for each one, how to confirm the cache emptied, and where to look when the stale record actually lives outside your machine.

The short answer

First find out what actually caches DNS on your system. On modern distros it is systemd-resolved: sudo resolvectl flush-caches. On others it is nscd or dnsmasq, each restarted differently. Many Linux machines cache nothing locally and need no flush at all.

resolvectlflush-caches (systemd)
nscdor dnsmasq on older boxes
sudorequired for the flush
Answer card showing sudo resolvectl flush-caches as the way to clear systemd-resolved on Linux.
The command depends on your resolver. Step one is finding out which one you run. PNG

Step 1: find out which resolver you run

Linux
resolvectl status

If you get a Global block listing DNS servers, you are on systemd-resolved, so use Step 2. If resolvectl is command not found, you are on nscd or dnsmasq (Step 3), or nothing local caches DNS and there is nothing to flush.

Step 2: flush systemd-resolved

Linux
sudo resolvectl flush-caches

That clears the cache instantly, with no output on success. On older systemd releases the same command is sudo systemd-resolve --flush-caches.

Step 3: flush nscd or dnsmasq instead

If a separate caching daemon runs, restart it. For nscd:

Linux
sudo systemctl restart nscd

For dnsmasq (common on routers and on setups using NetworkManager’s resolver):

Linux
sudo systemctl restart dnsmasq

Confirm the cache is empty

For systemd-resolved, the statistics show the live cache size:

Linux
resolvectl statistics | grep "Current Cache Size"

It reads 0 straight after a flush, then climbs as you make new lookups. Here is the full sequence:

Terminal showing resolvectl statistics before and after sudo resolvectl flush-caches, with the cache size dropping to zero.
Check the size, flush, check again. Zero means it worked. PNG

When there’s nothing to flush

Plenty of Linux desktops and servers keep no local DNS cache, so the answer you are chasing sits at the router or the public resolver, held there until its TTL expires. macOS is different again: there it is sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder.

On Windows? There it is a single command for everyone: see how to flush the DNS cache on Windows.

Frequently asked questions

How do I know if I use systemd-resolved?

Run "resolvectl status". If it prints a Global section with DNS servers, systemd-resolved is active and caching. If the command does not exist, you are on nscd, dnsmasq, or you have no local cache at all.

What is the command on older systemd versions?

Before resolvectl existed the same job was "sudo systemd-resolve --flush-caches". It still works as an alias on many systems, so try it if resolvectl is missing but systemd-resolved is running.

My distro has no local resolver. Where is DNS cached then?

Then nothing on your machine caches it. The record is held by whatever resolver /etc/resolv.conf points to (your router or a public resolver such as 1.1.1.1) and it stays until its TTL expires. Our DNS TTL guide explains that wait.

Does flushing the cache need sudo?

Yes for the flush itself (resolvectl flush-caches, or restarting nscd or dnsmasq), because you are touching a system service. Reading the status and statistics does not need sudo.