As a user of Ubuntu 22.04 or 20.04, you may have noticed slow website access or network connectivity issues that may be hindering the effectiveness of your work. One of the reasons for these problems could be an outdated or corrupted DNS cache in your system. To resolve this issue, it is necessary to clear the DNS cache.
This article provides a step-by-step guide on how to clear DNS cache in Ubuntu 22.04 or 20.04 using two methods: the systemd-resolved service and the network manager service. But before diving into the methods, let’s first check if the DNS cache is causing the problem.
To check the DNS cache in Ubuntu, follow these simple steps:
1. Open the terminal by pressing Ctrl+Alt+T or searching for the terminal in the applications menu.
2. Type the following command and press enter: sudo systemd-resolve –statistics
This command will display the DNS resolver’s statistics, including the number of queries, cache hits, and cache misses. Check the cache hit rate, and if it is less than 50%, it means that the cache is not being utilized effectively.
Now that we have checked the DNS cache let’s proceed with clearing it. Here are the two methods that you can use:
Method 1: Using systemd-resolved Service
The systemd-resolved service provides system-wide DNS caching and name resolution. Follow the steps below to clear the DNS cache using this service:
1. Open the terminal and enter the following command to flush the cache: sudo systemd-resolve –flush-caches
2. After flushing the cache, enter the following command to restart the systemd-resolved service: sudo systemctl restart systemd-resolved.service
This command will reload the systemd-resolved configuration and start the service.
3. Verify whether the cache has been cleared by running the “sudo systemd-resolve –statistics” command again.
Method 2: Using Network Manager Service
The network manager service manages network connections in Ubuntu, and restarting this service can help clear the DNS cache. Follow the steps below to clear the DNS cache using this service:
1. Open the terminal and enter the following command to stop the network manager service: sudo systemctl stop NetworkManager.service
2. Enter the following command to flush the cache: sudo systemd-resolve –flush-caches
3. Finally, enter the following command to start the network manager service: sudo systemctl start NetworkManager.service
4. Check if the cache has been cleared by running the “sudo systemd-resolve –statistics” command again.
Clearing the DNS cache can help improve network connectivity issues in Ubuntu. By following these simple steps, you can clear the DNS cache using either the systemd-resolved service or the network manager service.
In conclusion, clearing the DNS cache in Ubuntu 22.04 or 20.04 can help you to resolve issues with network connectivity and slow website access. So, if you are facing similar issues with your Ubuntu system, give these methods a try, and you might be surprised by how effective they are!