How to Automatically Clear Your Mac’s DNS Cache Using the Terminal

The Domain Name System (DNS) is the phonebook of the internet. When you type digitash.com into Safari, a DNS server translates that human-readable name into the exact string of IP address numbers needed to connect to our servers. To speed up web browsing, macOS stores (caches) these IP addresses locally on your hard drive.

However, if a website recently migrated to a new server, or if you are a web developer actively updating DNS records for a client, your Mac’s outdated local cache will stubbornly continue routing you to the old, broken IP address. You will see an error page while the rest of the world sees the live website.

To force your Mac to fetch the absolute latest routing information from the global internet, you must manually flush the local DNS cache using the Terminal.

The Universal Command (macOS Sierra to macOS Sonoma)

Apple has a notorious history of completely changing the background networking daemon that handles DNS every few years (switching between mDNSResponder, discoveryd, and back again). Because of this, the command to flush the cache has changed radically depending on what version of macOS you were running.

Fortunately, since the release of macOS 10.12 (Sierra) all the way up through the latest modern iterations of macOS, Apple has stabilized the network architecture. There is now one single, universal command.

Step 1: Open Terminal

  1. Open the Terminal app (found in Applications > Utilities, or by pressing Cmd+Space and searching for Terminal).

Step 2: Flush the Cache

  1. Copy and paste the following command exactly as written:
    sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder
  2. Press Return.
  3. Because this command restarts a core background system process (using sudo), Terminal will prompt you for your Mac login password. Type it in and press Return. (Note: The cursor will not move while you type your password. This is a normal security feature. Just type it blindly and hit Return).

How the Command Works

This single line actually executes two entirely separate commands back-to-back (separated by the semicolon):

  • sudo dscacheutil -flushcache: This aggressively clears the local directory service cache, which holds temporary lookup data.
  • sudo killall -HUP mDNSResponder: This sends a “Hang Up” (HUP) signal to the Multicast DNS daemon, effectively restarting the networking process that handles the actual IP resolution without requiring you to reboot your entire computer.

Step 3: Clear Your Browser Cache (Optional but Recommended)

Even if you successfully flushed the operating system’s DNS cache using the terminal, your specific web browser (especially Google Chrome) often maintains its own, entirely separate internal DNS cache.

If the terminal command didn’t fix your routing issue, you must clear the browser’s cache as well:

  • Safari: Go to the top menu bar, click Safari > Settings > Advanced, and check “Show features for web developers.” Then click the new “Develop” menu in the top bar and select Empty Caches.
  • Chrome: Type chrome://net-internals/#dns into your address bar, press Enter, and click the Clear host cache button.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.