How to clear your DNS cache in 5 minutes

Man using laptop in office
(Image credit: Unsplash / Anthony Riera)

Each time you type a new web address into your browser’s address bar, your device connects to a DNS Server to translate its simple human-readable name into a machine-readable IP address, so you can connect to your web server of choice.

Many modern devices and operating systems store the IP addresses of the sites you visit in a special DNS cache to help you access them faster in future. 

Problems occur when things start to go stale. Perhaps the website in question has updated its IP address or maybe they’ve added a new server to which you can connect even faster. This can cause web pages to load slowly, or sometimes not all. 

Bad actors like hackers will sometimes target your DNS cache. This is known as ‘DNS poisoning’ and is very dangerous : if, for instance, you typed in the website address of your bank, a hacker could redirect you instead to a copycat ‘phishing’ website. 

DNS settings 

Even if you’re not worried about slow web pages or being targeted by cybercriminals, you may want to update your DNS settings. Public DNS servers such as those offered by Google and Cloudflare are often much faster than those offered by your ISP, and they can filter out harmful links.

If you sign up with one of the best VPN services (and reliable free VPN providers), they will also supply their own DNS servers. This is because if you connect to a VPN but continue to use the DNS servers supplied by your ISP, anyone monitoring your connection can see which websites you’re visiting, as well as what services you’re using, such as Netflix. This is known as DNS leak

If you’re considering subscribing to a VPN or updating your DNS settings, you should always “flush” your DNS cache first to clear out any old web data. This is not only better for your privacy. It will stop pages from failing to load properly using the new DNS servers.

Clearing your DNS caches isn’t hard to do but to make sure your settings are updated, you need to do it on each device and browser you use.

How to clear your DNS cache 

There’s very little risk in clearing your DNS cache but as always when making any system-wide change to your system, make sure to save and close any open files, as well as run backups before you start.

Windows

If you’re using Microsoft Windows, clearing the DNS cache is very simple. Simply boot to the desktop, enter “CMD” into the search box to run the Command Line Utility and run:

ipconfig /flushdns

You’ll see a confirmation message to say this has been done.


macOS

If you’re running a Mac, it’s more complicated. In each case you’ll need to boot to your macOS desktop, open Spotlight and search for ‘Terminal’. But the commands you need to enter are slightly different depending on which version of macOS you’re running.

For versions of macOS12 (Sierra) and later run the command:

sudo killall -HUP mDNSResponder;sudo killall mDNSResponderHelper;sudo dscacheutil -flushcache

For OS X 10.10 (Yosemite) run:

sudo dscacheutil -flushcache;sudo killall -HUP mDNSResponder

For OSX Lion, Mountain Lion and Mavericks, run:

sudo killall -HUP mDNSResponder

If you don’t feel comfortable using the Terminal, MacKeeper also has a feature to clear the macOS DNS cache .


Linux

There are many different ‘flavors’ of Linux and it would take too long to provide instructions for how to clear your cache here. However if you’re using a recent version of Ubuntu or one of its variants like Linux, simply open the ‘Terminal’ app and type:

sudo resolvectl flush-caches 

For Red Hat Linux and it’s variants open Terminal and run:

service nscd restart


iOS/iPadOS

If you have an iPhone or iPad, the DNS cache clears itself each time the device restarts or is placed in “flight mode”. Enable flight mode or turn your iOS device off, wait 30 seconds, then reconnect.


Android

Android devices like mobile phones and tablets don’t have a built-in way to clear the DNS cache but you can get round this by installing Chrome on your device, then following the instructions for clearing the cache below.

How to clear browser DNS cache

Just in case you were thinking this was too easy, some browsers also store their own cache to help with faster loading times. These can also become corrupted or be exploited, so make sure to clear them out at the same time you clear the main DNS cache on your computer or mobile device. 

Microsoft Edge

Open Microsoft Edge and click on the three-dot menu at the top right and choose ‘History’. Next choose ‘Clear Browsing Data’. A new window will open. Use the “Time Range” dropdown menu to select “All Time”. Make sure that the tickbox “Cookies and other site data” is checked, then click “Clear Now.”


Safari

With the Safari browser open, click Safari > Preferences. Next, click the ‘Advanced’ tab and check ‘Show Develop Menu’. Click the new ‘Develop’ option in the menu bar, then ‘Empty caches’.

Google Chrome

Open Chrome and type this into the address bar:

chrome://net-internals/#dns

This accesses Chrome settings. Just click the “Clear host cache” button to flush out your old DNS data.


Opera

Like Google Chrome, the Opera browser is based on Chromium, so the steps you need to go through are very similar. Just open the browser and type this into the address bar:

opera://net-internals/#dns

As with Chrome, just click on “Clear host cache” to flush your old DNS settings.


Firefox

Click the Firefox menu icon at the top right of your browser window, then go to “History > Clear Recent History”. Under the “Time range to clear” dropdown menu, choose “Everything,” then click OK. 

DNS clearance 

Clearing out your DNS cache is a great way to improve connection speeds and stay safe from hackers. It also makes it more likely if you’re updating your DNS settings that your devices and installed browsers will work right away.

If you’re still experiencing slow loading times after connecting to a VPN and using their DNS servers, see our guide How to speed up a VPN when you’re not already using one of the fastest VPNs

Nate Drake is a tech journalist specializing in cybersecurity and retro tech. He broke out from his cubicle at Apple 6 years ago and now spends his days sipping Earl Grey tea & writing elegant copy.