dns

How to Clear Your DNS Cache

Last modified: September 19, 2024


Overview

Your DNS cache stores the locations (IP addresses) of web servers that contain web pages which you have recently viewed. If the IP address of a web server that stores a web page changes, you will not be able to access that web page again until your DNS cache updates.

Your DNS cache updates automatically. However, if you encounter a large number of HTML 404 error codes, you may need to clear your DNS cache manually. After you clear your DNS cache, your computer will automatically query all new nameservers you interact with for the IP addresses of their web servers, then cache the new information.

How to clear your DNS cache

Windows®

To clear your DNS cache if you use Windows, perform the following steps:

  1. Click Start or the Windows icon.
  2. In the search text box, enter cmd.
  3. Right-click Command Prompt and select Run as Administrator.
  4. Run the following command:
    ipconfig /flushdns

If the command succeeds, the system returns the following message:

Windows IP configuration successfully flushed the DNS Resolver Cache.

For more information about the ipconfig command, read Microsoft’s ipconfig documentation.

macOS®

To clear your DNS cache if you use macOS X version 10.10.4 or above, perform the following steps:

Warning:

To run this command, you must know the computer’s administrator account password.

  1. Click Applications.
  2. Click Utilities.
  3. Click Terminal.
  4. Run the following command:
    sudo killall -HUP mDNSResponder

If the command succeeds, the system does not return any output.

ChromeOS

To clear your DNS cache if you use ChromeOS, perform the following steps:

  1. Open a new Chrome tab.
  2. Enter the following address:
    chrome://net-internals
  3. Hit the Enter key.
  4. From the menu, select DNS.
  5. Click the Clear host cache button.

If the command succeeds, the system will perform any DNS lookups again.

Ubuntu®

To clear your DNS cache if you use Ubuntu, run the following command:

sudo resolvectl flush-caches

If the command succeeds, it will return results with an empty cache.

Non-Ubuntu Linux®

To clear your DNS cache if you use a Linux-based operating system that is not Ubuntu (for example, CloudLinux™ or AlmaLinux OS), run the following command:

systemctl restart nscd

If the command succeeds, the system does not return any output.

How to edit your /etc/hosts file

Some server development environments, like MAMP, can cause DNS conflicts by preventing you from clearing addresses in your operating system’s /etc/hosts file. If you experience a DNS caching error while using one of these environments, you must delete the conflicting IP address’ line from your /etc/hosts file manually.

To manually edit your /etc/hosts file, perform the following steps:

Note:
  • If you are using Windows, you must perform these steps with administrator privileges.
  • If you are using macOS, you must know the computer’s administrator account password.
  1. Open the /etc/hosts file with your preferred text editor. Your file will resemble the following example, where 192.0.2.0 is the IP address your system tries to access when you type example.com into your web browser’s address bar:

    10.0.0.0 localhost
    192.0.2.0 example.com
    8.8.8.8 google.com

  2. Delete the lines that contain outdated or malfunctioning IP addresses.

  3. Save the file.

  4. Clear the DNS cache to apply the changes.

Additional Documentation