How to flush DNS cache on linux?

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.

  • DNSMasq:

    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

  • NSCD:

    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

Related Articles

How to Kill a Process Running on Specific Port in Linux?

First of all, we will need to identify the Process ID which runs on any port. Once we find the...

How to delete mailman archives on cPanel using command?

If you have created a mailman mailing list called [email protected] and want to clear it, then...

How to install Dotnet Core on Centos 7 ?

Dotnet Core is now available with the Linux OS. Following are the steps to install Dotnet Core on...

How to install Virtualmin/Webmin control panel in CentOS 7?

Please refer to the following steps to install Virtualmin/Webmin on Centos 7.x Let us update...

How do I enable apache file and directory indexing in Linux or UNIX?

There are 2 ways to enable apache file and directory indexing. Using Apache config file : You...

  • 0 Users Found This Useful

Was this answer helpful?