Stale DNS records can cause frustrating connection errors, slow page loads, and stubborn site unavailability on Linux systems. When your browser refuses to reach a recently updated domain, your local machine or local resolver is likely holding onto outdated IP address mappings.
Fixing this requires clearing the DNS cache on your Ubuntu system. Depending on your specific Ubuntu version and network configuration stack, systemd-resolved, NetworkManager, or third-party caching tools handle DNS lookups differently. This guide walks you through verifying your caching service and purging old records cleanly.
Checking Your DNS Resolution Stack
Before running any flush commands, you need to identify which resolver your Ubuntu system uses. Modern Ubuntu releases rely on systemd-resolved by default. Older installations or custom desktop setups might use dnsmasq, nscd, or plain NetworkManager bindings.
Open your terminal and check the status of the systemd resolver service with this command: BBC has provided coverage on this critical subject in great detail.
systemctl status systemd-resolved
If the output displays an active (running) status, your system manages DNS records via systemd-resolved. If it's inactive or disabled, you'll need to check alternative caching daemons running on your environment.
For further reading on network management services, check the Ubuntu Networking Documentation.
Clearing Cache with systemd-resolved
When systemd-resolved is active, Ubuntu provides a built-in command to flush internal DNS caches immediately without restarting the entire network stack.
Run the following command in your terminal using administrative privileges:
sudo resolvectl flush-caches
If you're running an older Ubuntu release where resolvectl isn't available yet, use the older syntax instead:
sudo systemd-resolve --flush-caches
Verifying the Flush Operation
After executing the flush command, you can confirm that the cache statistics have reset to zero. Run this command to inspect resolver metrics:
resolvectl statistics
Look for the Current Cache Size line in the output. If it reads 0, your DNS cache is successfully cleared.
Restarting NetworkManager for Dynamic Interfaces
If your desktop environment or server relies on NetworkManager and you suspect interface-level caching, restarting the network service forces a fresh reload of all active connection profiles.
Run this command to restart NetworkManager on Ubuntu:
sudo systemctl restart NetworkManager
Note: Restarting NetworkManager will briefly drop your active wired or wireless connection for a couple of seconds. Avoid running this during active SSH remote sessions unless you have physical or console access to the machine.
Flushing DNS in Browser Caches
Sometimes the issue isn't your Ubuntu system cache at all, but rather your web browser holding onto its own independent DNS records. Even after flushing systemd-resolved, browsers like Google Firefox or Chrome might still fail to load pages.
Clearing Firefox DNS Cache
- Open Firefox and type
about:networkingin the address bar. - Click on the DNS tab in the left sidebar.
- Click the Clear DNS Cache button.
Clearing Chromium or Chrome DNS Cache
- Open your browser and type
chrome://net-internals/#dnsorbrave://net-internals/#dnsin the URL bar. - Click on DNS from the sidebar options.
- Click the Clear host cache button.
Common Mistakes to Avoid
When troubleshooting DNS problems on Linux, administrators often run into a few recurring pitfalls that waste valuable time:
- Ignoring local host file overrides: If you added custom test entries to
/etc/hosts, flushingsystemd-resolvedwon't change them. Always check your hosts file if a domain points to the wrong local IP. - Forgetting application-level caching: Development tools, database clients, and programming language runtimes (like Node.js or Python scripts) often implement their own internal DNS caching layers independent of the operating system.
- Running redundant flush commands: Running random commands found on unverified forums can break your resolv.conf symlinks. Stick to native tools supported by your specific Ubuntu release.
Frequently Asked Questions
How do I check if my DNS queries are working properly?
You can test domain resolution using the dig or nslookup utility. For example, typing dig ubuntu.com queries your active resolver and shows you the exact IP address returned along with the query time.
Does rebooting Ubuntu clear the DNS cache?
Yes. By default, systemd-resolved stores its cache in volatile memory (RAM). A standard system reboot completely wipes the cache and forces fresh lookups upon startup.
Why do I get a "command not found" error for resolvectl?
This usually happens on older Ubuntu versions (like Ubuntu 18.04 or earlier) that predated resolvectl. On those systems, use sudo systemd-resolve --flush-caches instead.
Can I disable DNS caching entirely on Ubuntu?
While possible by editing /etc/systemd/resolved.conf and setting Cache=no, it isn't recommended. Caching reduces network latency and prevents unnecessary query loads on your upstream DNS provider.