Tutorials UPDATED: 21 October 2022

How to Flush the DNS Cache in Windows, Mac or Linux

Tassos Antoniou

6 min read
Image for How to Flush the DNS Cache in Windows, Mac or Linux

Have you ever experienced the scenario where you visit a page and the content you see seems outdated or partially missing or even no content at all? If so, then during troubleshooting, one of the things you should check is whether the culprit for these problems is your device DNS cache.

You’re perhaps aware that your browser might ‘cache’ content (save content so it’s easier and faster to retrieve in the future) but did you also know that your computer/laptop does the same? Today we will show you how to clear/flush the DNS cache that is stored on your computer whether you run Windows, are working on a Mac or run a Linux Distribution System.

So, before we get stuck in, let’s quickly take a more detailed look at what DNS caching is exactly.

Why DNS Cache Exists

As you may already know, the Domain Name System (DNS) is essentially an address book that matches domain names to the IP of the server that holds the website’s content. So when you are visiting a website, the DNS converts the domain name to the corresponding IP address(es) so that the browser can render the correct resources.

The diagram below shows how the domain is converted to a computer-friendly IP format and returns the website content.

It can take a while for this process to run and send a response. That is why DNS cache is included in each step of the lookup process and the operating system DNS cache is one of them. This way, when the user revisits a website, instead of looking up the information and following the process of looking up an IP address via the DNS system (as per the diagram) the browser will simply retrieve the information from cache and return the results. This can significantly speed up the process of loading websites.

Why flush the DNS Cache on your Operation System?

There are several reasons why you might want to flush your operating system DNS cache.

Although the DNS on your system should (in theory) update when required (for example a website moves to a new IP address), this doesn’t always happen. Because of this you could end up either seeing outdated content, or, getting a 404 error. This can be seriously frustrating!

Flushing your DNS cache can also come in handy when developing a website or setting its domain name records. This is when DNS cache can cause conflicts and prevent you from viewing the correct content or the whole site.

Also, If you do not want to use the incognito mode browsers offer, you can still keep your search private by flushing the DNS cache. If you do this, as well as clear your cookies, the information stored about the websites you visit will be deleted.

Host your website with Pressidium

60-DAY MONEY BACK GUARANTEE

SEE OUR PLANS

One last issue worth noting is called DNS Spoofing (also known as DNS cache poisoning). This is a form of computer hacking where someone gains access to your DNS cache and redirects the name server to an incorrect result record, like another IP address. This means you could unwittingly end up browsing a site that isn’t the site you thought it was. Clearly this has security implications as you could be tricked into entering login credentials or parting with other information useful to a hacker. By regularly clearing your DNS cache you reduce the likelihood of falling victim to this particular type of hacking attack.

Your DNS cache will normally be set to automatically expire after a period of time but manually flushing this on occasion does help ensure this process is fully carried out. It’s also a good step to undertake when you find yourself having issues connecting to a website (after you’ve ruled out obvious causes like internet connectivity!).

There are no real downsides to flushing your cache, bar perhaps a slight time penalty when you first visit websites. This ‘lag’ will probably be barely noticeable however and, as the site gets cached, isn’t something you’ll experience the second time you visit the same site.

How to flush the DNS Cache on Windows 10

Here are the steps you have to follow to clear the DNS cache on a Windows 10 Operating System.

Step One: Open a DOS command window. To do this, click the search icon and type “run” (or hold the Windows button and press R)

Step Two: In the popup Run window that will appear type “cmd” without the quotes and press Enter. A command prompt window should now be opened in front of you.

The last thing you have to do is type the following command and then press Enter:

ipconfig /flushdns

That’s it. Your DNS cache is now flushed.

How to flush the DNS Cache on a Mac

Depending on the version of macOS you’re using, the process of flushing DNS cache may differ.

Clear DNS cache on the latest macOS versions

For macOS version 10.11 or above, open the terminal and enter the command below:

sudo killall -HUP mDNSResponder

Then you will be asked to enter your password, and after you do that’s it. Your DNS cache should now be clear.

Clear DNS cache on old macOS versions

For old versions, the command varies on each version:

OS X Mavericks:

sudo killall -HUP mDNSResponder

OS X Yosemite:

sudo discoveryutil udnsflushcaches

Mac OS X Snow Leopard, Mac OS X Leopard:

sudo dscacheutil -flushcache

Mac OS X Tiger:

lookupd -flushcache

NOTE: You can check what macOS version you are running by clicking on the ‘apple’ icon at the top-left corner and pressing the “About This Mac” option.

How to flush the DNS Cache on Linux Distributions

Before clearing the DNS cache on a Linux distribution, you need to make sure that systemd-resolved is active. To check this, enter the following command in a terminal window:

sudo systemctl is-active systemd-resolved

If “active”, then you can proceed and enter the command to flush the DNS cache.

Now, if you are using Ubuntu, this is what should be entered:

sudo systemd-resolve --flush-caches

You won’t get a confirmation message that the DNS was successfully cleared. The way to check is by running the following command:

sudo systemd-resolve --statistics

If the process has been successful you will see the “Current Cache Size” is 0.

If however you are not using Ubuntu, then insert the following command:

sudo /etc/init.d/dns-clean start

Conclusion

Flushing the DNS cache isn’t something you’ll have to do very often but it can be a quick way to resolve unexpected website browsing issues. As you can see from the above, it’s a pretty quick process no matter your operating system!

Host your Website with Pressidium!

View our price plans

OUR READERS ALSO VIEWED:

Building a CI/CD Workflow – Automatically Deploying a WordPress Theme with GitHub Actions

Streamline your WordPress deployment process using GitHub Actions and a CI/CD workflow. Automatically build and deploy a WordPress theme to your Pressidium WordPress site.
Konstantinos Pappas
Konstantinos Pappas
22 min read

Types of Cross-Site Scripting (XSS) Attacks

In this article, on XSS attacks we're going to deep dive cross-site scripting examples to better understand how these types of attacks work.
Tassos Antoniou
Tassos Antoniou
6 min read

5 Best Tips For Web Developers When Coding For eCommerce Websites

So how can you become a successful web developer when coding for ecommerce websites? Check out this article to find out!
Daryl Bush
Daryl Bush
7 min read

WordPress and Cross-Site Scripting (XSS)

Cross-site scripting (XSS) attacks are a common types of website attack seen across the internet. Find out how to protect your website!
Tassos Antoniou
Tassos Antoniou
7 min read
SUBSCRIBE