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

You fixed the DNS record, and your Linux box keeps serving the old IP anyway. On modern Ubuntu, Debian and Fedora the fix is sudo resolvectl flush-caches, because systemd-resolved is what's caching. Unlike Windows there's no single universal command, though. Older or lighter systems run nscd or dnsmasq, each cleared its own way, and plenty of Linux machines run no local cache at all, so there's genuinely nothing to flush. We'll show you how to tell which resolver you've actually got, the exact command for each one, how to confirm the cache emptied, and where the stale record hides when it lives outside your machine.

The short answer

Find out what actually caches DNS on your box first. On modern distros it’s systemd-resolved: sudo resolvectl flush-caches. On others it’s nscd or dnsmasq, each restarted its own way. And plenty of Linux machines cache nothing locally, so there’s nothing to flush.

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

A Global block listing DNS servers means you’re on systemd-resolved, so jump to Step 2. If resolvectl comes back command not found, you’re on nscd or dnsmasq (Step 3), or nothing local caches DNS and you’re already done.

Step 2: flush systemd-resolved

Linux
sudo resolvectl flush-caches

Done. It clears instantly, and no output means success. On older systemd releases the same command is sudo systemd-resolve --flush-caches.

Step 3: flush nscd or dnsmasq instead

Running a separate caching daemon? 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

Don’t just trust it. 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 new lookups land. 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

We see this a lot on minimal server installs: no local DNS cache at all. The stale answer you’re chasing sits at the router or the public resolver, held there until its TTL expires, and no command on your box will hurry it along. macOS is different again (honestly, I look that one up every time): there it’s sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder.

On Windows? One 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". A Global section with DNS servers means systemd-resolved is active and caching. If the command doesn't exist, you're on nscd or 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". Many systems still keep it around as an alias, so it's worth a try when resolvectl is missing but systemd-resolved is clearly running.

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

Then nothing on your machine caches it. The record sits with whatever resolver /etc/resolv.conf points to (your router, or a public resolver such as 1.1.1.1) and it stays put 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), since you're touching a system service. Reading the status and statistics works fine without it.