Linux DNS flush guide showing resolver cache, flush commands, and verification steps.

Pages refuse to load. A site still resolves to the old server hours after a migration. Both usually trace back to stale records sitting on your own machine. Linux stores the addresses it looks up, and those entries go bad with time. A linux flush dns clears them so the next lookup starts clean. Which command you need depends on the resolver running on your box.

What the DNS Cache Stores on Linux

Each cached entry pairs a domain name with an IP address. Reusing that entry skips a full lookup, so the page opens faster.

Problems start when the stored answer stops matching reality. Common signs:

  • sites that will not open at all
  • connection errors on domains that worked yesterday
  • slow first loads
  • tabs that fail again and again

Plain glibc caches nothing. A local DNS cache exists only when systemd-resolved, nscd or dnsmasq runs, which is why one universal command does not exist on Linux.

Browser own cache Local resolver systemd-resolved / nscd Router or ISP upstream cache Authoritative name server the only cache your flush command touches
Where a name lookup travels, and which cache a flush command actually clears.

Find Your Resolver Before You Linux Flush DNS

Check which program answers queries on port 53 first. Open a terminal and run:

sudo lsof -i :53 -S
PieceWhat it does
lsofLists open files and the processes holding them
-i :53Limits output to port 53, the standard DNS port
-SCaps the time spent on slow kernel calls

If systemd-resolved appears in the output, that service handles name resolution and the resolvectl method below applies. Nothing on port 53 means no local cache exists, so there is nothing to clear. Sorting out address ranges on the same box is quicker with an IP subnet calculator.

Four Ways To Linux Flush DNS

MethodCommandWorks on
resolvectlsudo resolvectl flush-cachesAny systemd build
USR2 signalsudo killall -USR2 systemd-resolvedUbuntu 20.04 and newer
Service restartsudo systemctl restart systemd-resolvedAny systemd build
nscdsudo /etc/init.d/nscd restartOlder distributions

Clear the DNS Cache With resolvectl

Press Ctrl + Alt + T for a terminal, then run:

sudo resolvectl flush-caches

The sudo prefix grants root rights. resolvectl talks to systemd-resolved, and flush-caches tells it to drop every stored entry. The command prints nothing when it succeeds. Systems on systemd 238 or older need sudo systemd-resolve --flush-caches instead, since the tool was renamed at version 239.

Flush systemd-resolved With a USR2 Signal

You can also poke the daemon directly:

sudo killall -USR2 systemd-resolved

killall matches processes by name, and USR2 is the signal systemd-resolved treats as an order to empty its cache. The service never stops, so open connections survive. Check the result in the journal:

sudo journalctl -r -u systemd-resolved

Here -r puts the newest entries first and -u narrows output to that single unit.

Restart systemd-resolved to Clear the Cache

A restart wipes the cache too, because the service rebuilds its store on startup:

sudo systemctl restart systemd-resolved

Use this when the resolver itself misbehaves, not just its stored data. Anyone writing or fixing unit files around it can save time with a systemd unit file generator. A full machine reboot clears the cache as well, though that is heavier than the job needs.

Flush DNS on Older Distributions With nscd

Legacy builds ship the Name Service Cache Daemon rather than systemd-resolved. Restart it:

sudo /etc/init.d/nscd restart

The daemon comes back with an empty store. On setups running dnsmasq, send it a hangup signal with sudo killall -HUP dnsmasq. This dnsmasq configuration guide covers how that resolver caches and forwards queries.

Verify the Linux Flush DNS Worked

Two checks confirm the result. Start with the cache counter:

resolvectl statistics

Current Cache Size should read 0 straight after a flush. Then confirm the service is healthy and run a live query:

sudo systemctl status systemd-resolved
nslookup google.com

A fresh answer means your machine pulled the record again rather than reading it from memory.

Common Linux Flush DNS Errors and Fixes

ProblemFix
command not foundConfirm the box actually uses systemd-resolved
Lookups still failCheck /etc/resolv.conf, restart networking, verify server addresses
No systemd presentUse nscd or dnsmasq, whichever the distribution ships
Old IP keeps returningThe stale record sits upstream, not on your machine

A “command not found” error on resolvectl usually points to a release older than systemd 239, or a distribution that never enabled the service. Confirming the release settles it fast, and this walkthrough on identifying your Ubuntu release shows three ways to read it.

When queries keep failing after a flush, open /etc/resolv.conf and read the nameserver lines. If you are new to the editor, the shortcuts for saving and quitting nano save some guessing. Restart networking afterwards with sudo systemctl restart network-manager.

Still stuck on an old address? Your router or public resolver holds it until the TTL expires, and no local command shortens that wait. Clear it from the router admin panel instead. Firewall rules can also swallow port 53 traffic, which nftables rule handling explains in detail.

FAQs

How do I flush DNS in Linux quickly?

Run sudo resolvectl flush-caches in a terminal. It clears the systemd-resolved cache on Ubuntu, Debian, Fedora and most current distributions, and returns no output when it succeeds.

Does every Linux system cache DNS records?

No. Plain glibc keeps no cache. Caching happens only when systemd-resolved, nscd, dnsmasq or a local BIND resolver runs, so many minimal servers have nothing to flush.

Why does resolvectl say command not found?

Your distribution either predates systemd 239 or does not use systemd-resolved. Try sudo systemd-resolve –flush-caches, or switch to the nscd or dnsmasq command for your setup.

How can I confirm the DNS cache is empty?

Run resolvectl statistics and read Current Cache Size. A value of 0 confirms the flush worked. Follow it with nslookup or dig to test a live lookup.

Do I need to restart my computer after flushing DNS?

No. The flush takes effect at once. A reboot clears the cache as a side effect, but it is never required for the change to apply.

Willie has over 15 years of experience in Linux system administration and DevOps. After managing infrastructure for startups and enterprises alike, he founded Command Linux to share the practical knowledge he wished he had when starting out. He oversees content strategy and contributes guides on server management, automation, and security.