Newsletter Subscribe
Enter your email address below and subscribe to our newsletter
DNS cache stores the DNS query results for faster access to frequently visited websites. However, sometimes the cache may become outdated or corrupted, leading to issues with website access. Clearing the DNS cache may be necessary if you’re experiencing problems with website access or network connectivity. In this article, I’ll show you how to flush DNS cache in Ubuntu 22.04 or 20.04.
Table of Contents
Before clearing the cache, let’s first check if the cache is causing the issue. Follow the steps below:
Ctrl+Alt+T
or search for the terminal in the applications menu.sudo systemd-resolve --statistics
This command will display statistics for your DNS resolver, including the number of queries, cache hits, and cache misses.
There are multiple ways to clear DNS cache in Ubuntu, but we’ll focus on the two most common methods: using the systemd-resolved service and restarting the network manager service.
The systemd-resolved service provides system-wide DNS caching and name resolution. Here are the steps to clear DNS cache using this service:
sudo systemd-resolve --flush-caches
sudo systemctl restart systemd-resolved.service
This command will reload the systemd-resolved configuration and start the service.
sudo systemd-resolve --statistics
command again.The network manager service is responsible for managing network connections in Ubuntu. Restarting this service can help clear the DNS cache. Here’s how:
sudo systemctl stop NetworkManager.service
sudo systemd-resolve --flush-caches
sudo systemctl start NetworkManager.service
sudo systemd-resolve --statistics
command again.Clearing DNS cache can help improve network connectivity issues in Ubuntu. I hope this article helped you resolve any issues you were facing with DNS cache in Ubuntu.