Flush DNS Cache with Command Quick Guide

Updated: Jul 20

The primary purpose of DNS cache is to store the location of web servers that we have recently accessed. The next time when we type in that website address, the browser will look for its DNS information in the local cache first and be able to find the site more quickly.


If the location of any web server changes before the entry in the DNS Cache updates, then we can no longer access that site.




Should We Flush DNS Cache Manually every time?

Actually no. The DNS cache will clear itself out from time to time without our intervention. That’s because the DNS cache saves a component called TTL, or time to live.


This specifies a period of time (in seconds) in which the DNS record for a site remains valid. Within this time period, any queries to the website are answered from the local cache without querying the DNS server. Once the TTL expires, the entry will be removed from the cache.



When Should We Flush DNS Cache Manually?

There are three main reasons for this.

  • Troubleshooting connectivity issues

  • Troubleshooting and/or resolving DNS spoofing (e.g. DNS cache poisoning) issues

  • Resolving stale content issues (e.g. if a website has moved servers)




How to check DNS Cache?

We can check the DNS cache based on our system.

  • Window - The process for viewing our DNS cache entries in Windows is pretty simple. Simply open the command prompt and enter the following command: ipconfig /displaydns.

  • Mac - open the Console app, select the device from the left sidebar and enter: any:mdnsresponder into the search bar. Next, open the command line and enter the following command: sudo killall -INFO mDNSResponder. We should then be able to go back to the console app and see the list of cached DNS records.

  • chrome - we can also check our DNS cache entries on certain browsers. We can enter: chrome://net-internals/#dns into our address bar which will return our browser's current list of cached DNS records.




How to Flush DNS Cache?

We can use the following command to flush DNS cache.

  • Windows - Open the command prompt or click Run when we open start menu. Then, enter the following command: ipconfig /flushdns. If the command succeeds, we will receive the following message "Successfully flushed the DNS Resolver Cache.".

  • Mac - Open the command line interface or Terminal and enter the following command: sudo killall -HUP mDNSResponder. We may need to enter the administrator password. If the command succeeds the system will not return any output.

  • Chrome - navigate to chrome://net-internals/#dns and click the "Clear Host Cache" button.



13 views
udemylinux.png

Join our newsletter! Get a free cloud server!  Never miss a post!

Thanks for submitting!