Skip to main content

How to flush DNS cache

What is DNS cache?

DNS cache stores the IP addresses of visited sites on the local computer so that they load faster next time. Instead of doing a long DNS lookup, the system answers the queries with DNS records from the temporary DNS cache.

The DNS cache contains so-called resource records (RRs), which are:

  • Resource data (or rdata);
  • Record type;
  • Record name;
  • TTL (time to live);
  • Class;
  • Resource data length.

When you might need to clear the cache

You regularly get a 404 error. For example, the website was transferred to another server, and its IP address has changed. To make the browser open the website from the new IP address, you need to remove the cached IP from the DNS cache.

You want to improve your privacy.

You want to protect yourself from hacker attacks and viruses. When the DNS cache is corrupted, your browser may redirect you to an IP address of a malicious website that an attacker inserted in your computer’s DNS records.

How to flush DNS cache on different OSs

macOS

To clear the DNS cache on macOS, open the Terminal (you can find it by using the Spotlight search — to do that, press Command+Space and type Terminal) and enter the following command:

sudo killall -HUP mDNSResponder

On macOS Big Sur 11.2.0 and macOS Monterey 12.0.0, you may also use this command:

sudo dscacheutil -flushcache

After that, enter your administrator password to complete the process.

Windows

To flush DNS cache on your Windows device, do the following:

Load the Command Prompt as an administrator. You can find it in the Start Menu by typing command prompt or cmd. Then type ipconfig/flushdns and press Enter.

You will see the line Successfully flushed the DNS Resolver Cache. Done!

Linux

Linux does not have OS-level DNS caching unless a caching service such as Systemd Resolved, DNSMasq, BIND or Nscd is installed and running. The process of clearing the DNS cache depends on the Linux distribution and the caching service used.

For each distribution you need to start a terminal window. Press Ctrl+Alt+T on your keyboard and use the corresponding command to clear the DNS cache for the service your Linux system is running.

To find out which DNS resolver you're using, command sudo lsof -i :53 -S.

Systemd Resolved

To clear the Systemd Resolved DNS cache, type:

sudo systemd-resolve --flush-caches

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

DNSMasq

To clear the DNSMasq cache, you need to restart it:

sudo service dnsmasq restart

Nscd

To clear the Nscd cache, you also need to restart the service:

sudo service nscd restart

BIND

To flush the BIND DNS cache, run the command:

rndc flush

Then you will need to reload BIND:

rndc reload

You will get the message that the server has been successfully reloaded.

Android

The easiest way to clear your DNS cache on your Android device is to turn the Airplane mode on and off. You can enable/disable the Airplane Mode in the Quick Settings pane.

A hard reboot can also help flush the DNS cache for your device. In order to do that, press and hold the power button for at least 20 seconds. It will (usually) force your device to reboot manually and the DNS cache will be cleared.

Another option is to reset the network settings of your device in the Settings app. Open Settings > System > Advanced > Reset options > Reset network settings and tap Reset Settings to confirm.

Note: by doing that, you will lose connections to Wi-Fi routers and other specific network settings, including DNS servers customizations. You will need to reset them manually.

iOS

There are different ways to clear the DNS cache on your iPad or iPhone.

The simplest way is to activate the Airplane mode (for example, in the Control Center or in the Settings app) and to deactivate it again. The DNS cache will be flushed.

Another option is to reset the network settings of your device in the Settings app. Open General, scroll down, find Reset and tap on Reset Network Settings.

Note: by doing that, you will lose connections to Wi-Fi routers and other specific network settings, including DNS servers customizations. You will need to reset them manually.