How to Clear the DNS Cache

Updated 

5 min read

DNS cache is a temporary database that stores information about previous DNS lookups. In other words, whenever you visit a website, your OS and web browser will keep a record for the domain and the corresponding IP address. This eliminates the need for repetitive queries to the remote DNS servers and allows your OS or browser to quickly resolve the website’s URL.

However, in some situations like troubleshooting network issues or after changing DNS resolvers, you will need to flush the DNS cache. This will clear the cached DNS entries and perform a subsequent lookup to resolve the domain based on newly configured DNS settings.

This guide provides instructions on how to flush the DNS cache on different operating systems and web browsers.

Clear/Flush DNS Cache on Windows

The process of clearing the DNS cache is the same for all Windows versions. You need to open the command prompt with administrator privileges and run ipconfig /flushdns.

Windows 10 and Windows 8

To clear the DNS cache in Windows 10 and 8, perform the following steps:

  1. Type cmd in the Windows search bar.
  2. Right-click on Command Prompt and click Run as administrator. This will open up the Command Prompt window.

  3. On the command line, type the following line and press Enter:

    ipconfig /flushdns

    On success, the system will return the following message:

    Windows IP Configuration
    
    Successfully flushed the DNS Resolver Cache.

Windows 7

To clear the DNS cache in Windows 7, perform the following steps:

  1. Click on the Start button.
  2. Type cmd in the Start menu search text box.
  3. Right-click on Command Prompt and click Run as administrator. This will open up the Command Prompt window.
  4. On the command line, type the following line and press Enter:

    ipconfig /flushdns

    On success, the system will return the following message:

    Windows IP Configuration
    
    Successfully flushed the DNS Resolver Cache.

Clear/Flush DNS Cache on Linux

On Linux, there is no OS-level DNS caching unless a caching service such as Systemd-Resolved, DNSMasq, or Nscd is installed and running. The process of clearing the DNS cache is different depending on the Linux distribution and the caching service you’re using.

Systemd Resolved

Most modern Linux distributions such as Ubuntu 18.04 are using systemd resolved service to cache DNS entries.

To find out whether the service is running use the following command:

sudo systemctl is-active systemd-resolved.service

If the service is running, the command will print active. Otherwise you will see inactive.

To clear the Systemd Resolved DNS cache, type:

sudo systemd-resolve --flush-caches

On success, the command doesn’t return any message.

DNSMasq

Dnsmasq is a lightweight DHCP and DNS caching nameserver.

If your system is using DNSMasq as a caching server, to clear the DNS cache you need to restart the Dnsmasq service:

sudo systemctl restart dnsmasq.service

Or

sudo service dnsmasq restart

Nscd

Nscd is a caching daemon, and it is the preferred DNS caching system for most of RedHat-based distributions.

If your system is using Nscd, to clear the DNS cache, you need to restart the Nscd service:

sudo systemctl restart nscd.service

Or

sudo service nscd restart

Clear/Flush DNS Cache on macOS

The command to flush cache in macOS is slightly different depending on the version you’re running. The command must be executed as a user with system administrator privileges (sudo user).

To clear the DNS cache in macOS, perform the following steps:

  1. Open the Finder.
  2. Go to Applications > Utilities > Terminal. This will open up the Terminal window.
  3. In the command line, type the following line and press Enter:

    sudo killall -HUP mDNSResponder

    Enter your sudo password, and hit Enter again. On success, the system doesn’t return any message.

For earlier versions of macOS, the command to flush cache is different.

macOS version 10.11 and 10.9

sudo dscacheutil -flushcache
sudo killall -HUP mDNSResponder

macOS version 10.10

sudo discoveryutil mdnsflushcache
sudo discoveryutil udnsflushcaches

macOS version 10.6 and 10.5

sudo dscacheutil -flushcache

Clear/Flush Browser DNS Cache

Most modern Web browsers have a built-in DNS client to prevent repetitive queries each time the website is visited.

Google Chrome

To clear Google Chrome’s DNS cache, perform the following steps:

  1. Open a new tab and type chrome://net-internals/#dns in Chrome’s address bar.
  2. Click the “Clear host cache” button.

If that doesn’t work for you, try to clear the cache and cookies.

  1. Open the “Clear browsing data” dialog window with CTRL+Shift+Del.
  2. Choose a time range. Select “All time” to delete everything.
  3. Check the “Cookies and other site data” and “Cached images and files” boxes.
  4. Click the “Clear data” button.

This method should work for all Chrome-based browsers, including Chromium, Vivaldi, and Opera.

Firefox

To clear Firefox’s DNS cache, perform the following steps:

  1. In the upper right-hand corner, click on the hamburger icon to open Firefox’s menu:
  2. Click on the ⚙ Options (Preferences) link.
  3. Click the Privacy & Security or Privacy tab on the left.
  4. Scroll down to the History section and click on the Clear History... button.
  5. Choose a time range to clear. Select “Everything” to delete everything.
  6. Select all boxes and click “Clear Now”.

If that doesn’t work for you, try the following method and temporally disabled the DNS cache.

  1. Open a new tab and type about:config in Firefox’s address bar.
  2. Search for network.dnsCacheExpiration, temporally set the value to 0 and click OK. Afterward, change back the default value and click OK.
  3. Search for network.dnsCacheEntries, temporally set the value to 0 and click OK. Afterward, change back the default value and click OK.

Conclusion

You have learned how to clear or flush DNS cache on Windows, Linux, and macOS operating systems.

Linux and macOS users can use the dig command to query and troubleshoot DNS issues.

If you have any questions or feedback, feel free to leave a comment.