News & Updates

Clear Ubuntu DNS Cache: Fast & Easy Guide

By Ava Sinclair 7 Views
ubuntu dns cache clear
Clear Ubuntu DNS Cache: Fast & Easy Guide

Managing a reliable network environment on Ubuntu often requires dealing with DNS behavior, and knowing how to flush the local resolver cache is a fundamental skill. The Domain Name System cache stores recent lookup results to speed up subsequent requests, but it can sometimes hold onto stale or incorrect data. When applications fail to resolve hostnames correctly, clearing this storage is one of the first troubleshooting steps any administrator should consider.

Understanding the DNS Cache on Ubuntu On modern Ubuntu installations, the DNS cache is not managed by a traditional standalone daemon but is typically handled by systemd-resolved, NetworkManager, or a local caching service like nscd. systemd-resolved is the most common on desktop and server environments using systemd, and it maintains a local cache that improves resolution speed and reduces external queries. Understanding which service is active is essential before attempting to clear the cache, as the command syntax differs between implementations. Check Which DNS Resolver Is Running

On modern Ubuntu installations, the DNS cache is not managed by a traditional standalone daemon but is typically handled by systemd-resolved, NetworkManager, or a local caching service like nscd. systemd-resolved is the most common on desktop and server environments using systemd, and it maintains a local cache that improves resolution speed and reduces external queries. Understanding which service is active is essential before attempting to clear the cache, as the command syntax differs between implementations.

Before clearing the cache, verify the active DNS resolution method to avoid using incorrect commands. The `systemd-resolve` or `resolvectl` utilities are used for systems with systemd-resolved, while other environments might rely on different mechanisms. Running a quick status check ensures you target the right service and prevents confusion during troubleshooting.

Command
Purpose
resolvectl status
Shows if systemd-resolved is active and lists current DNS servers
systemd-resolve --status
Provides detailed information about cached entries and DNS configuration
ps aux
grep -E 'nscd
dnsmasq'
Checks if alternative caching services are running

Flush systemd-resolved Cache

When systemd-resolved is the active resolver, you can flush its internal cache using the `resolvectl` command with administrative privileges. This operation is safe, does not affect network connectivity, and immediately forces new DNS lookups to query authoritative servers. The syntax is straightforward and works consistently across recent Ubuntu releases.

To clear the cache, open a terminal and execute:

sudo resolvectl flush-caches

You can verify that the cache statistics have reset by running:

resolvectl statistics

Alternative Services and Manual Methods

In environments where systemd-resolved is not in use, such as older configurations or custom setups, you might need to target services like nscd or dnsmasq. Restarting these services effectively clears their respective caches, and in some cases, you may need to restart NetworkManager to ensure all layers are refreshed. Each service has its own management commands, but the outcome is the same—stale data is discarded.

Flush nscd cache: sudo /etc/init.d/nscd restart or sudo service nscd restart

Flush dnsmasq cache: sudo /etc/init.d/dnsmasq restart or send SIGHUP via sudo killall -HUP dnsmasq

Restart NetworkManager: sudo systemctl restart NetworkManager

Verification and Best Practices

After clearing the cache, test hostname resolution using tools like `dig`, `nslookup`, or `ping` to confirm that fresh queries are reaching the DNS servers. Monitoring cache behavior over time can help identify recurring resolution issues, and regular cache maintenance is a good practice in high-churn network environments. Combining cache management with proper DNS configuration reduces downtime and improves system reliability.

A

Written by Ava Sinclair

Ava Sinclair is a Senior Editor covering culture, travel, and premium experiences. She focuses on clear reporting and practical takeaways.