How to Use the Linux resolvectl Command to Flush the DNS Cache

When you update a DNS record for a website, or migrate a server to a new IP address, your Linux machine may stubbornly refuse to connect to the new location. This happens because modern Linux distributions do not query external DNS servers for every single network request. Instead, they store recent DNS lookups in a local memory cache to improve speed. If the cached entry is outdated, your system will mathematically route traffic to the wrong server. To force the operating system to discard this stale data and fetch fresh records, administrators use the resolvectl command.

Why Use the resolvectl Command?

Historically, flushing the DNS cache in Linux was a fragmented process. Administrators had to memorize different commands depending on whether the system used nscd, dnsmasq, or bind. Modern distributions (like Ubuntu 18.04+, Fedora, and Debian) have standardized network resolution by adopting systemd-resolved. The resolvectl command is the official, unified interface for interacting with this daemon. It allows you to view the current DNS server configuration, check cache statistics, and instantly wipe the memory buffer without needing to restart the entire networking stack.

Step 1: Check Current DNS Settings

Before flushing the cache, it is good practice to verify exactly which DNS servers your system is currently using to resolve domains.

  1. Open your Linux terminal.
  2. Run the command to display the global status:
resolvectl status

The output will list the DNS servers assigned to every active network interface (e.g., eth0 or wlan0), ensuring your system is not querying a broken or malicious server.

Step 2: Flush the DNS Cache

Once you confirm your settings are correct, you can clear the memory buffer.

  1. Run the flush command (this generally requires sudo privileges):
sudo resolvectl flush-caches

Unlike other commands, resolvectl is silent upon success. It will immediately return you to the command prompt without printing a confirmation message.

Step 3: Verify the Cache was Flushed

Because the flush command is silent, you should mathematically verify that the memory buffer was actually cleared.

  1. Run the command to view the cache statistics:
resolvectl statistics

The output will display a \”Cache\” section. Look at the value for Current Cache Size. If the flush was successful, this number should be 0 (or very close to it, as background services may immediately begin caching new lookups).

Step 4: Query a Specific Domain

Finally, to ensure the system is now fetching fresh data, you can force systemd-resolved to query the domain you were troubleshooting.

  1. Use the query command followed by the target domain:
resolvectl query digitash.com

The output will display the exact IP address the system is currently resolving, confirming whether the DNS propagation has successfully reached your machine.

By mastering the resolvectl command, Linux administrators can swiftly resolve network routing errors and guarantee their systems are acting on the most accurate, up-to-date DNS records.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.