What is DNS cache and how do I clear it? Print

  • dns, dns cache, troubleshooting
  • 127

A DNS cache is temporary storage holding recently resolved domain names and their IP addresses, so that the same domain does not have to be looked up again for every request. It makes browsing faster, and it is also why a DNS change you have just made appears not to have worked.

Where DNS answers are cached

  • Your browser — its own short-lived cache.
  • Your operating system — a system-wide resolver cache.
  • Your internet provider's resolver — and this one you cannot clear.

You can clear the first two. The third expires on its own, according to the TTL of the record.

When clearing helps

After changing a domain's records or nameservers, if a site still opens from the old server. Clearing your local caches lets you see the change; it does nothing for anyone else. If the site is still wrong afterwards, the answer is simply time — see How long does DNS propagation take?

Windows

  1. Open the Start menu and search for Command Prompt.
  2. Right-click it and choose Run as administrator.
  3. Run:
ipconfig /flushdns

A successful run reports:

Successfully flushed the DNS Resolver Cache.

macOS

sudo dscacheutil -flushcache
sudo killall -HUP mDNSResponder

Both commands are needed; run them together.

Linux

Which command applies depends on what your distribution uses.

With systemd-resolved, as on current Ubuntu and Debian:

sudo resolvectl flush-caches

With nscd, if it is installed:

sudo systemctl restart nscd

With dnsmasq:

sudo systemctl restart dnsmasq

If none of these exists, your system probably has no local caching resolver, and there is nothing to clear — queries go straight out each time.

Browsers

Chrome keeps its own DNS cache, separate from the system's. Open chrome://net-internals/#dns and use Clear host cache. Other Chromium-based browsers have the same page under their own scheme.

Firefox clears its DNS cache when restarted.

Checking what DNS actually returns

Rather than judging by whether a site opens, query DNS directly. These commands bypass the browser entirely:

dig example.com +short
nslookup example.com

To see what a public resolver returns rather than your provider's cached copy:

dig @1.1.1.1 example.com +short

If the public resolver returns the new address and your own still returns the old one, the change is fine and you are waiting on your provider's cache.

Site content, not DNS

If the domain resolves to the right server but the page still shows old images, styles or text, that is not DNS. Clear the browser cache, or open the site in a private window. Sites behind a CDN or with server-side caching may also need their own cache cleared.

If the correct address is returned everywhere but the site still does not work, the DNS side is done — open a ticket from your client area with the domain name.


Was this answer helpful?

« Back