DNS is responsible for resolving website names into their respective IPs. Whenever you visit a website, your operating system and web browser will keep a record for the domain and the corresponding IP address. The cache files contain information about all visited sites like hostname, IP address.
The cache files validity period is determined by Time to Live. As long as the cache files are valid, it will answer content requests without having to go through the DNS server. Using outdated DNS cache files will leads to errors and security vulnerabilities. Here is some reason why you should flush your DNS frequently.
- Technical Issues: to force the operating system to search the updated DNS records to resolve the connection and display incorrect content.
- Search Behaviour: store DNS records makes it easier for hackers to get your search history.
- Security: DNS cache files are the important and main target for spoofing, which can put user’s sensitive information in danger.
In Linux, no such OS level DNS caching unless a caching service such as systemd-resolved, DNSMasq, or NSCD is installed and running.
- Systemd Resolved
Follow the below command in order to check the weather service is running or not.
sudo systemctl is-active systemd-resolved.service
If the service is running it will show Active either it shows Inactive. To clear a DNS cache, use the command Systemd Resolved command.
sudo systemd-resolved --flush-caches
Make a note that, if your service is active and the command got fired successfully, it will return nothing. So, it means you have to flush the DNS cache.
It is a lightweight DNS caching nameserver. If your system is using DNSMasq as a caching server, you will need to restart that service in order to flush the DNS cache
sudo systemctl restart dnsmasq.service
sudo service dnsmasq restart
It's the preferred DNS caching system for most of the Linux systems. If you are using this system, run the below command in order to flush the DNS cache.
sudo systemctl restart nscd.service
sudo service nscd restart