How to Clear/Flush the DNS Cache on Linux
You may need to flush or clear the local DNS cache on your Linux system for various reasons.
This could be one of the below reasons.
- Sometimes you may have difficulty reaching certain websites.
- When troubleshooting network related issues.
- After DNS resolvers change.
When you run flush DNS cache, this will destroy the DNS entries in the cache and perform a subsequent query to resolve the domain based on the newly configured DNS settings.
What is DNS cache and what it Does?
The DNS cache is a temporary database maintained by the computer’s operating system.
It stores information about previous DNS lookups (like information on recently visited websites and other web domains).
This will quickly resolve DNS queries when you visit the cached website by getting details from the local DNS database instead of the actual DNS server.
If you want to know DNS information about a website, use one of the commands below.
- Check DNS (Domain Name Server) Records On Linux Using Nslookup Command
- Check DNS (Domain Name Server) Records On Linux Using Dig Command
- Check DNS (Domain Name Server) Records On Linux Using Host Command
What is nscd DNS Cache
nscd stands for name service cache daemon, nscd is a daemon that provides a cache for the most common name service requests. The default configuration file located at
What is dnsmasq DNS Cache
Dnsmasq is a lightweight, small footprint, easy to configure, DNS forwarder and DHCP server. It is designed to provide DNS and optionally, DHCP, to a small network & suitable for resource constrained routers and firewalls. It can serve the names of local machines which are not in the global DNS. It is designed for personal computer use and small size networks, not for big networks.
What is BIND Server DNS Cache
BIND stands for “Berkeley Internet Name Domain”. The most widely used Name Server Software, BIND is open source software that implements the Domain Name System (DNS) protocols for the Internet. BIND is by far the most widely used DNS software on the Internet, providing a robust and stable platform.
How to Clear/Flush the DNS Cache on Linux
By default, DNS caching is not installed or enabled at the OS level, but if you have installed any of the caching services listed below, use the appropriate commands to flush them.
Below is a list of the major DNS cache services used in the Linux operating system.
- systemd Resolved Service
- nscd DNS Cache
- dnsmasq DNS Cache
- BIND server DNS Cache
1) How to Flush DNS Cache on Linux Using the systemd Resolve Service
Most modern Linux operating systems use systemd, so use the command below to flush the DNS cache.
Run the below command to check if the DNS cache service is active on your system.
$ sudo systemctl is-active systemd-resolve.service
You can check the DNS statistics using the below command.
$ sudo systemd-resolve --statistics
If it’s active and the service is running, use the below command to flush it.
$ sudo systemd-resolve --flush-caches
2) How to Clear BIND Server DNS Cache on Linux
The BIND DNS server is used on most servers where the Web Hosting Control Panel is installed. We have seen this on servers where cPanel and CentOS Web Panel are installed.
Run the below command to flush the BIND server DNS cache on Systemd-based Linux systems.
$ sudo systemctl restart named
Run the following command to clear the BIND server DNS cache on SysVinit-based Linux systems.
$ sudo service named restart or $ sudo /etc/init.d/named restart
Also, you can use the following commands for the BIND service.
To clear the BIND DNS cache, use the below command.
$ sudo rndc restart
To clear DNS cache for a particular domain, use the below command.
$ sudo rndc flushname 2daygeek.com
To clear DNS cache for LAN, use the below command.
$ sudo rndc flush lan
To clear DNS cache for WAN, use the below command.
$ sudo rndc flush wan
3) How to Flush nscd server DNS Cache on Linux
Some Linux distributions use the nscd DNS server. If so, flush it using the below commands.
Run the below command to flush the nscd server DNS cache on Systemd-based Linux systems.
$ sudo systemctl restart nscd
Run the following command to clear the nscd server DNS cache on SysVinit-based Linux systems.
$ sudo service nscd restart or $ sudo /etc/init.d/nscd restart
4) How to Clear the dnsmasq Server DNS Cache on Linux
Some distribution may use the dnsmasq DNS server. If so, use the below commands to flush it.
Run the below command to flush the dnsmasq server DNS cache on Systemd-based Linux systems.
$ sudo systemctl restart dnsmasq
Run the following command to clear the dnsmasq server DNS cache on SysVinit-based Linux systems.
$ sudo service dnsmasq restart or $ sudo /etc/init.d/dnsmasq restart
5) How to Clear the DNS Cache on Windows
Use the below command to Flush the dns cache on windows systems.
C:\Windows\system32>ipconfig /flushdns Windows IP Configuration Successfully flushed the DNS Resolver Cache.
You have learned how to clear or flush DNS cache on Windows and Linux operating systems.