Oct 17, 2023 5 min read

How to Clear (Flush) the DNS Cache on Windows, MacOS, and Linux

Clear (Flush) the DNS Cache on Windows, MacOS, and Linux with our step-by-step tutorial. The DNS cache stores historical DNS lookups temporarily.

Clear (Flush) the DNS Cache on Windows, MacOS, and Linux
Table of Contents

Introduction

Before we begin talking about how to clear (flush) the DNS Cache on Windows, MacOS, and Linux, let's briefly understand – What is DNS cache ?

The DNS cache is a temporary database that keeps track of past DNS lookups. To put it another way, anytime you visit a website, your operating system and web browser will store a record of the domain and its IP address. This removes the need for repeated DNS server queries and allows your OS or browser to quickly determine the website's URL.

However, flushing the DNS cache is necessary in some cases, such as debugging network difficulties or switching DNS resolvers. This will remove the cached DNS entries and do a subsequent lookup using the freshly configured DNS settings to resolve the domain.

In this tutorial, you will clear (flush) the DNS Cache on Windows, MacOS, and Linux. We will also address a few FAQs on how to clear (flush) the DNS Cache on Windows, MacOS, and Linux.

Advantages of DNS cache

  1. Faster domain name resolution: DNS cache reduces lookup time by storing previous queries, resulting in quicker response times.
  2. Bandwidth usage reduction: Cached results reduce network traffic by minimizing the need for repeated DNS queries.
  3. Improved network performance: Quick retrieval from the cache enhances overall network performance and user experience.
  4. Enhanced security: DNS cache can help detect and prevent certain types of malicious attacks, such as DNS hijacking.
  5. Offline accessibility: Some DNS cache servers can continue resolving domain names even when the device is not connected to the internet.

Clear/Flush DNS Cache on Windows

All Windows versions have the same procedure for clearing the DNS cache. You must run ipconfig /flushdns from a command prompt with administrator access.

Windows 10 and Windows 8

Follow these instructions to remove the DNS cache in Windows 10 and 8:

  1. In the Windows search bar, type cmd.

2. Right-click Command Prompt and select Run as administrator from the context menu. The Command Prompt window will appear.

3. Type the following line on the command line and hit Enter:

ipconfig /flushdns

The system will return the following message if it is successful:

Output

Windows IP Configuration

Successfully flushed the DNS Resolver Cache.

Windows 7

To clear the DNS cache in Windows 7, go through the procedures below:

  • To begin, press the Start button.
  • In the Start menu search box, type cmd.
  • Right-click Command Prompt and select Run as administrator from the context menu. The Command Prompt window will appear.
  • Type the following line on the command line and hit Enter:
ipconfig /flushdns
  • The system will return the following message if it is successful:
Output

Windows IP Configuration

Successfully flushed the DNS Resolver Cache.

Clear/Flush DNS Cache on Linux

Unless a caching service such as Systemd-Resolved, DNSMasq, or Nscd is installed and running, there is no OS-level DNS caching on Linux. Depending on the Linux distribution and the caching service you're using, cleaning the DNS cache is done differently.

Systemd Resolved

To cache DNS entries, most recent Linux distributions, such as Ubuntu 18.04, use the systemd resolved service.

Use the following command to see if the service is up and running:

sudo systemctl is-active systemd-resolved.service

The command will print active if the service is running. If you don't, you'll see inactive.

Type the following command to clear the systemd-resolved-dns-cache:

sudo systemd-resolve --flush-caches

The command returns no message if it succeeds.

DNSMasq

Dnsmasq is a DHCP and DNS caching nameserver with a small footprint.

If your system uses DNSMasq as a caching server, you'll need to restart the Dnsmasq service to remove the DNS cache:

sudo systemctl restart dnsmasq.service

Or

sudo service dnsmasq restart

Nscd

Nscd is a caching daemon that is used by most RedHat-based distributions as their DNS caching solution.

If your system runs on Nscd, you'll need to restart it to remove the DNS cache:

sudo systemctl restart nscd.service

Or

sudo service nscd restart

Clear/Flush DNS Cache on macOS

Depending on whatever version of macOS you're using, the command to flush cache differs slightly. The command must be run by a user who has system administrator permissions (sudo user).

Perform the following steps to remove the DNS cache on macOS:

  • Open the Finder.
  • To go to Terminal, go to Applications > Utilities > Terminal. This will launch the Terminal window.
  • Type the following line in the command prompt and click Enter:
sudo killall -HUP mDNSResponder

Enter your sudo password and then press Enter once more. The system does not send a message if the operation is successful.

The command to flush cache in prior versions of macOS is different.

Versions 10.11 and 10.9 of macOS

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

The built-in DNS client in most recent Web browsers prevents repeating queries each time the domain is accessed.

Google Chrome

Perform the following steps to remove Google Chrome's DNS cache:

  • In Chrome's address bar, type chrome:/net-internals/#dns in a new tab.
  • To clear the host cache, click the "Clear host cache" button.
    If it doesn't work, try deleting your cache and cookies.
  • CTRL+Shift+Del brings up the "Clear browsing data" dialog box.
  • Select a time frame. To remove everything, select "All time."
  • Select "Cookies and other site data" and "Cached pictures and files" from the drop-down menus.
  • Select "Clear data" from the drop-down menu.

All Chrome-based browsers, including Chromium, Vivaldi, and Opera, should operate with this strategy.

Firefox

Perform the following steps to clear Firefox's DNS cache:

  • To open Firefox's menu, click the hamburger icon in the upper right-hand corner:
  • Click on the ⚙ Options (Preferences).
  • On the left, select the Privacy & Security or Privacy tab.
  • Click the Clear History... option after scrolling down to the History section.
  • To clear, select a time range. To erase everything, select "Everything."
  • Click "Clear Now" after selecting all boxes.

If it doesn't work, try disabling the DNS cache temporarily with the following way.

  • In Firefox's address box, open a new tab and type about:config.
  • Find network.dnsCacheExpiration, adjust the value to 0 for now, and click OK. After that, adjust the value back to the default and click OK.
  • Look for the network.dnsCacheEntries file. Set the value to 0 for the time being, then click OK. After that, adjust the value back to the default and click OK.

FAQs to Clear (Flush) the DNS Cache on Windows, MacOS, and Linux

Why should I clear my DNS cache? 

Clearing the DNS cache resolves issues like outdated or incorrect DNS entries, allowing your system to query and access the most up-to-date information for domain names.

Does clearing DNS cache impact internet speed? 

Clearing the DNS cache generally improves internet speed by avoiding potential delays caused by outdated or incorrect DNS entries.

Is it necessary to clear DNS cache regularly? 

Clearing the DNS cache is usually not required unless you encounter specific DNS-related issues. It is an effective troubleshooting step for resolving DNS-related problems.

Can clearing DNS cache affect my browsing history or saved data? 

Clearing DNS cache does not affect browsing history or saved data, as it solely focuses on DNS resolutions and does not interfere with your browser's local data.

Will clearing the DNS cache log me out of websites or online accounts?

Clearing DNS cache does not log you out of websites or online accounts since it primarily relates to resolving domain names and not affecting user sessions or authentication.

Are there any alternative ways to clear DNS cache on Windows or MacOS? 

Yes, alternative methods include using third-party DNS management tools or restarting your computer, which can also help clear the DNS cache.

Does clearing DNS cache impact my network settings or configurations? 

Clearing DNS cache solely removes the cached DNS entries and does not affect network settings or configurations on your operating system.

Conclusion

On Windows, Linux, and macOS, we've demonstrated how to empty or flush DNS cache.

The dig command on Linux and macOS can be used to query and troubleshoot DNS issues.

If you have any queries, please leave a comment below and we’ll be happy to respond to them.

Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to DevOps Tutorials - VegaStack.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.