DNS caching speeds up name resolution by storing recent answers locally, but stale records can cause failed connections, wrong IP addresses, or unexpected redirects after a domain change. On Linux, clearing the DNS cache depends on which resolver or caching service is actually running. Ubuntu, Debian, CentOS, and Fedora may use systemd-resolved, nscd, dnsmasq, BIND, or no local DNS cache at all.
TLDR: First identify your DNS caching service, then flush or restart it. For example, on a modern Ubuntu or Fedora system using systemd-resolved, run sudo resolvectl flush-caches and confirm with resolvectl statistics. In a typical office migration, clearing DNS cache on 25 workstations after a web server IP change can reduce “site not reachable” reports within minutes, especially when old DNS records had a TTL of 1 hour or more.
Why DNS Cache Needs Clearing
When you visit a domain such as example.com, your system resolves it to an IP address. To avoid repeating that lookup every time, DNS results are cached by components such as the operating system resolver, a local DNS daemon, a browser, or even an upstream router.
Clearing the DNS cache is useful when:
- A website was moved to a new server and your machine still uses the old IP address.
- Internal company DNS records changed after VPN, Active Directory, or infrastructure updates.
- You are troubleshooting intermittent name resolution failures.
- You want to remove a poisoned or incorrect cached DNS response.
- You changed
/etc/hosts, DNS servers, or network profiles and need fresh lookups.
Important: Linux does not have one universal DNS cache command. The correct method depends on the service handling DNS queries.

Step 1: Identify the DNS Service in Use
Before flushing anything, check which DNS-related services are active. Run:
systemctl is-active systemd-resolved
systemctl is-active nscd
systemctl is-active dnsmasq
systemctl is-active named
You can also inspect your resolver configuration:
cat /etc/resolv.conf
ls -l /etc/resolv.conf
If /etc/resolv.conf points to 127.0.0.53, your system is likely using systemd-resolved. If it points to 127.0.0.1 or another local address, a local caching service such as dnsmasq or BIND may be involved.
Clear DNS Cache on Ubuntu
Most modern Ubuntu releases, including Ubuntu 20.04, 22.04, and 24.04, commonly use systemd-resolved. To flush its DNS cache, run:
sudo resolvectl flush-caches
On older Ubuntu systems, this equivalent command may be available:
sudo systemd-resolve --flush-caches
To verify cache statistics, use:
resolvectl statistics
If you need to fully restart the resolver service, run:
sudo systemctl restart systemd-resolved
Restarting the service is usually safe, but it may briefly interrupt DNS lookups. In production environments, prefer flush-caches first.
Clear DNS Cache on Debian
Debian systems vary more than Ubuntu. A minimal Debian installation may not run a local DNS cache at all. If systemd-resolved is active, use:
sudo resolvectl flush-caches
If Debian is using nscd, the Name Service Cache Daemon, flush the hosts cache with:
sudo nscd -i hosts
Alternatively, restart the service:
sudo systemctl restart nscd
If dnsmasq is installed and used as a local resolver, restart it:
sudo systemctl restart dnsmasq
For Debian servers running BIND as a caching resolver, the service may be named bind9. Flush it with:
sudo rndc flush
Or reload the service:
sudo systemctl reload bind9
Clear DNS Cache on CentOS
CentOS DNS behavior depends heavily on the version and server role. CentOS 7 systems often use nscd, dnsmasq, or BIND if configured by an administrator. CentOS Stream and newer environments may also use systemd-resolved, although it is not always enabled by default.
If nscd is active, run:
sudo nscd -i hosts
Or restart it:
sudo systemctl restart nscd
If dnsmasq is active:
sudo systemctl restart dnsmasq
If BIND is running as named, flush the cache with:
sudo rndc flush
If rndc is not configured, reload or restart named:
sudo systemctl reload named
Use restart only when necessary:
sudo systemctl restart named
Note: On business-critical DNS servers, restarting named can temporarily disrupt service. A controlled rndc flush is preferred when available.
Clear DNS Cache on Fedora
Fedora commonly uses systemd-resolved in recent releases. The standard command is:
sudo resolvectl flush-caches
Check resolver statistics with:
resolvectl statistics
If you suspect the resolver is stuck, restart it:
sudo systemctl restart systemd-resolved
Fedora systems using NetworkManager may also receive DNS configuration from DHCP, VPN clients, or Wi-Fi profiles. If DNS server settings changed and flushing the cache is not enough, reload NetworkManager:
sudo systemctl restart NetworkManager
This can briefly disconnect the network, so avoid doing it over a fragile remote SSH session unless you have console access or another recovery method.
What If There Is No Local DNS Cache?
Sometimes there is nothing to flush. Many Linux systems simply query the configured DNS server directly and do not cache DNS responses locally. In that case, commands such as resolvectl flush-caches may fail because the service is not installed or active.
If no local caching service is running, check other places where DNS may be cached:
- Web browser cache: Chrome, Firefox, and Chromium-based browsers may maintain their own DNS cache.
- Application cache: Java, Node.js applications, containers, and database clients may cache DNS internally.
- Router or gateway cache: Office routers and firewalls often cache DNS responses.
- Upstream DNS provider: Public or corporate DNS servers may retain records until TTL expiry.
How to Test After Clearing DNS Cache
After flushing the cache, confirm that DNS resolution returns the expected result. Use dig if installed:
dig example.com
To query a specific DNS server, run:
dig @8.8.8.8 example.com
You can also use:
getent hosts example.com
resolvectl query example.com
Compare the returned IP address with the correct DNS record from your DNS provider or internal DNS administrator. If the wrong IP still appears, the issue may be outside the local Linux cache.

Practical Troubleshooting Tips
- Check TTL values: A record with a TTL of 3600 seconds may remain valid for up to one hour in many caches.
- Flush the right layer: Clearing systemd-resolved will not clear Chrome’s internal DNS cache or a router cache.
- Be careful on remote servers: Restarting NetworkManager or DNS services can interrupt SSH access.
- Use reload before restart: For BIND,
rndc flushorsystemctl reloadis usually less disruptive than a full restart. - Document changes: In managed environments, record when DNS was changed and which caches were cleared.
Conclusion
Clearing DNS cache on Linux is straightforward once you know which resolver is active. On Ubuntu and Fedora, sudo resolvectl flush-caches is commonly the right command. On Debian and CentOS, you may need to flush nscd, restart dnsmasq, or use rndc flush for BIND. A careful approach is best: identify the service, flush the cache, verify DNS results, and only restart network services when necessary.
