A DNS cache (sometimes called a DNS resolver cache) is a temporary database, maintained by a computer’s operating system, that contains records of all the recent visits and attempted visits to websites and other internet domains.
You may want to sometimes clear your DNS Cache, especially if you give access permission to another person, or simply save space if the cache size is large.
We can clear our existing DNS Cache using a few simple steps from the Command-Line.
1. Identify the DNS Resolver Service
In Ubuntu 18.04, the
systemd-resolve service provides the DNS resolution services, and hence, it uses the DNS Cache for Domain Name resolution. We can flush the cache by using this service.
NOTE: This applies only to Ubuntu versions after the 17.04 release. Any version prior to this will not use
systemd services for DNS Resolution.
2. Flush the Cache using systemd-resolve
We now flush the cache using the above systemd service. Since we are modifying a system service, we must have root priviliges to run this command.
sudo systemd-resolve --flush-caches
Now, if the command is successful, it returns
0 and we will be back to our command line prompt.
We have successfully cleared our DNS Cache in just a few simple steps!! Hope you found this tutorial useful for debugging your problem.