Contents
11 sections · 5 min read
Linux terminal showing systemd-resolve flush-caches command
Domain Management

How to Flush DNS Cache on Linux (Ubuntu, Debian, CentOS, Arch)

A
Domain 360 Team
·July 14, 2026·5 min read

Linux DNS flushing depends on which DNS caching service is running — and this varies by distribution and configuration. Unlike Windows (always ipconfig /flushdns) or Mac (two fixed commands), Linux has several possible services.

Quick answer: Linux DNS flushing depends on which DNS service is running — systemd-resolved, nscd, or dnsmasq. Here is the right command for each common Linux distribution.

Step 1: How Do You Identify Your DNS Service?

systemctl status systemd-resolved systemctl status nscd systemctl status dnsmasq

The one showing "active (running)" is your DNS caching service.

How Do You Flush DNS Using systemd-resolved?

Ubuntu 18.04, 20.04, 22.04, 24.04, and Fedora all use systemd-resolved by default.

Flush command: sudo systemd-resolve --flush-caches

Verify: sudo systemd-resolve --statistics — look for "Current Cache Size: 0"

How Do You Flush DNS Using nscd on Older Systems?

If systemctl status nscd shows active:

sudo service nscd restart

nscd does not have a flush command — restarting the service clears its cache.

How Do You Flush DNS Using dnsmasq?

sudo killall -HUP dnsmasq

Or: sudo systemctl restart dnsmasq

How Do You Clear DNS Cache via NetworkManager?

Ubuntu desktop may use dnsmasq embedded inside NetworkManager:

sudo systemctl restart NetworkManager

Note: briefly drops and reconnects network connections.

Does the Command Differ Across Ubuntu Versions?

Ubuntu 24.04: sudo systemd-resolve --flush-caches Ubuntu 22.04: sudo systemd-resolve --flush-caches Ubuntu 20.04: sudo systemd-resolve --flush-caches Ubuntu 18.04: sudo systemd-resolve --flush-caches Ubuntu 16.04: sudo systemd-resolve --flush-caches Ubuntu 14.04: sudo service dns-clean restart (if installed)

How Do You Verify No Cache Exists?

Many minimal Linux server installations have no local DNS cache. Every DNS query goes directly to the configured resolver without caching.

Check: systemctl list-units --type=service | grep -E "dns|nscd|resolved"

If nothing relevant appears as active, there is no local cache to flush. DNS changes take effect on the next query automatically.

Does Docker or a Container Have Its Own DNS Cache?

Yes, and this trips people up when troubleshooting from inside a container rather than the host. Containers typically use their own resolver configuration (often pointing to Docker's embedded DNS server or a resolver defined in /etc/resolv.conf inside the container), which is separate from whatever caching service runs on the host machine. Flushing DNS on the host has no effect on a container's resolution behavior. If you're debugging a DNS issue inside a container, restart the container itself or its networking, rather than looking for a flush command inside a minimal container image that likely doesn't have one installed at all.

What If Flushing Does Not Resolve the Issue?

If DNS flush does not fix the problem, test with public resolvers:

dig @1.1.1.1 yourdomain.com dig @8.8.8.8 yourdomain.com

If these return different results from your local query, your configured resolver is the issue. If they all return the same (wrong) result, it is propagation — the change has not reached these servers yet.

A domain returning NXDOMAIN everywhere may have expired — WHOIS lookup on the domain shows expiry status immediately.

How Do You Flush DNS Inside WSL?

WSL is a special case worth calling out separately, since it behaves differently from both native Linux and native Windows. WSL2 runs its own lightweight virtualized network stack, so flushing DNS on the Windows host (ipconfig /flushdns) does not touch the cache inside the WSL distribution, and vice versa. Inside the WSL shell, use whichever command matches the distribution you installed — Ubuntu on WSL uses the same systemd-resolve --flush-caches command as native Ubuntu in recent WSL2 versions with systemd support enabled, or a full WSL restart (wsl --shutdown from PowerShell, then reopening the terminal) if systemd is not enabled, which resets the entire network stack including any cached DNS state.

What's the Quick Reference for Every Distro?

DNS ServiceCommon OnCommand
systemd-resolvedUbuntu 18.04+, Fedora, most modern distrossudo systemd-resolve --flush-caches
nscdOlder distros, minimal installssudo service nscd restart
dnsmasqSystems running dnsmasq directlysudo systemctl restart dnsmasq
NetworkManager (dnsmasq plugin)Desktop systems where NetworkManager manages DNSsudo systemctl restart NetworkManager

When genuinely unsure which applies, running the identification commands from Step 1 above takes ten seconds and removes the guesswork entirely.

On a Mac instead? See how to flush DNS on macOS. If you're troubleshooting resolution behavior rather than just a stale cache, DNS over TLS vs DNS over HTTPS covers the underlying protocols.

Quick Answers

How do I flush DNS on Ubuntu?
On Ubuntu with systemd-resolved (default since Ubuntu 16.04): sudo systemd-resolve --flush-caches. Verify with: sudo systemd-resolve --statistics. On older Ubuntu using nscd: sudo /etc/init.d/nscd restart.
How do I flush DNS on CentOS or RHEL?
On CentOS/RHEL 7 and newer with systemd-resolved: sudo systemd-resolve --flush-caches. If using nscd: sudo service nscd restart. If using dnsmasq: sudo service dnsmasq restart.
How do I check which DNS service is running on Linux?
Run: systemctl status systemd-resolved to check if systemd-resolved is active. Try: systemctl status nscd for nscd. Try: systemctl status dnsmasq for dnsmasq. The active service is the one whose status shows "running".
Does Linux have a DNS cache by default?
It depends on the distribution and configuration. Ubuntu with systemd-resolved has DNS caching enabled by default. Minimal server installations often have no local DNS cache at all — each lookup goes directly to the configured DNS server. Desktop distributions are more likely to have caching enabled.
How do I flush DNS on Arch Linux?
Arch Linux with systemd-resolved: sudo systemd-resolve --flush-caches. Arch with dnsmasq: sudo systemctl restart dnsmasq. If running NetworkManager with dnsmasq plugin: sudo systemctl restart NetworkManager.

Never lose a domain again

Track every domain you own in one dashboard. Free for up to 15 domains.