What is DNS cache?

The DNS is the world’s address book that makes possible the current Internet. It is a well-recognized name system that connects domain names and IP addresses. The system is decentralized thanks to the DNS delegation, and it is separated into various DNS zones, but it is still very busy. To lower the traffic, we use a method of saving temporary DNS records called DNS cache.

​DNS cache explained.

The DNS cache is a type of cache memory (temporary) that devices and DNS resolvers have that contains all previously used DNS records of the queried domain names. Those records have the IP addresses of the domain names and their subdomains, data for their services, information about their email server, verification and authentication information, etc. The data will be saved inside this DNS cache, based on the TTL (Time to Live) value that each DNS record has.

​How can DNS cache save time and Internet bandwidth?

Let’s follow one DNS query and see how the DNS cache can save time.

Each time a client visits a domain name, it needs to get the A or AAAA records for it.

  1. First, it will check its own DNS cache. There is a file on each computer that saves previously visited domain names for the time TTL defines. If it is there, the site will be visited without any DNS query to a DNS resolver.
  2. If it is not inside the computer’s DNS cache, a query will be made to a DNS resolver (like the one in your Internet service provider ISP). If it has it inside, it will return the answer, and the client can visit the site without any more waiting. If no, it will start a long searching for the answer starting from the Root, then the TLD servers, and finally the domain name’s authoritative server.
  3. The good thing is that again, after the right DNS records are found, they will stay inside the DNS cache of the DNS resolver and the DNS cache of the client’s computer too.

The DNS resolver of an ISP will save DNS records of all visited domain names, of all clients that asked it for an answer. That way, there is a better chance to have it inside the cache memory the next time a client asks for a domain name.

​Can you delete the DNS cache?

Yes, you can delete it. However, there is a different process depending on your OS and your browser that could have another separate DNS cache. Let’s see how to do it.

​Windows

  1. Open the Command Prompt or Windows PowerShell and write this command – ipconfig /flushdns.
  2. You will see a confirmation message that the DNS was flushed successfully.

​macOS

  1. Open the Terminal and write this command – sudo killall -HUP mDNSResponder. Then put in your password and press the Enter.
  2. Done.

​Linux (Ubuntu 20.04 LTS)

  1. Open the Terminal and write this command – sudo systemd-resolve –flush-caches. Then put in your sudo password and press the Enter.
  2. Done.

​Google Chrome (on Edge or Opera works similarly)

  1. Copy this text chrome://net-internals/#dns. Paste it into your address bar and press Enter.
  2. On the page that it loads find Host resolver cache and click on Clear host cache.
  3. Done.

​Safari 

  1. Go to Preferences and then Advanced. There find Show develop menu in menu bar. 
  2. There, find Develop and then Empty Caches.
  3. Restart your browser, and you are done.