• About
  • Editorial policy
  • Contact
  • Privacy
  • Legal
  • Cookie settings
Monday, November 2, 2026
  • Login
PacketNebula
  • Home
  • News
  • Tools
    • Network
    • Security
    • Developer
    • Sysadmin
    • SEO
    • Email & DNS
  • Guides
  • Trackers
    • LLM API pricing
    • Open-weight models
    • Retirements calendar
    • Infrastructure deals
  • About
  • Download
No Result
View All Result
PacketNebula
No Result
View All Result
Home Network

How to flush the DNS cache on Linux

by Stéphane Cardon
3 September 2026
in Network
0
Tux the Linux penguin mascot as a small figurine holding an IBM Software label, on a workbench

Image: Renato.pierri / Wikimedia Commons, CC BY-SA 4.0

Share on FacebookShare on Twitter

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.

Find which resolver you run, then flush it

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.

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.

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.

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

Worth saying plainly: plenty of Linux desktops and most minimal servers have no DNS cache at all. If nothing is running systemd-resolved, dnsmasq or nscd, then every lookup already goes straight to your resolver and there’s nothing to flush. A stale answer in that case is coming from the upstream resolver or from the application, not from your machine.

One naming trap on systemd. The old systemd-resolve --flush-caches was renamed to resolvectl flush-caches in systemd 239, and the old name lingers in half the answers online. Both work on many distributions because the old binary is kept as a symlink, but on a recent Ubuntu the modern form is the one to use. Check the effect rather than trusting the exit code.

Linux
resolvectl statistics

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’ve no local cache at all.

What’s 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.

Tags: dnsguidelinux
ShareTweet
Previous Post

How to flush the DNS cache on Windows

Next Post

How to kill the process using a port on Windows

Stéphane Cardon

Stéphane Cardon

Network cybersecurity engineer: architecture, LAN and WLAN, system administration. He runs PacketNebula, where he publishes the tools and answers he wanted for his own work.

Next Post
RJ45 Ethernet cable plugged into the network port of a laptop, link LEDs glowing green and amber

How to kill the process using a port on Windows

Free tools

  • IPv4 subnet calculator
  • DNS lookup
  • SSL certificate checker
  • HTTP headers checker
  • SPF, DKIM and DMARC checker
  • JWT decoder
  • Cron expression builder
  • Chmod calculator
  • Password generator

All 24 tools →

Guides to keep handy

  • Flush the DNS cache on Windows
  • Kill the process using a port
  • Generate an SSH key
  • Secure a new Ubuntu VPS
  • Find files on Linux
  • Extract and create tar.gz

More guides →

Who writes this

Stéphane Cardon, network cybersecurity engineer. Architecture, LAN and WLAN, system administration. PacketNebula holds the tools and answers he wanted for his own work.

About this site →

  • About
  • Editorial policy
  • Contact
  • Privacy
  • Legal
  • Cookie settings

Copyright © 2026 Stephane Cardon.

No Result
View All Result
  • Home
  • News
  • Tools
    • Network
    • Security
    • Developer
    • Sysadmin
    • SEO
    • Email & DNS
  • Guides
  • Trackers
    • LLM API pricing
    • Open-weight models
    • Retirements calendar
    • Infrastructure deals
  • About
  • Download

Copyright © 2026 Stephane Cardon.

Cookies, your call

We use Google Analytics to see which pages get read. Once our AdSense application is approved, articles and guides will carry Google ads. Nothing runs until you say yes, and nothing runs on the tool pages. Details