User Agents

Web browsers and everyday web tech, explained

Clear DNS Cache on Mac: Step-by-Step Guide for All macOS

· 6 min read · Cookies and Cache

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

Clearing your DNS cache on a Mac, also known as flushing the DNS, forces your computer to delete the local database of IP addresses it has stored for websites you have visited. When you type a URL into your browser, your Mac checks this local cache first to speed up the connection; however, if a website has moved to a new server or changed its IP address, your Mac may still be trying to use the old, outdated information. This results in "Page Not Found" errors, 404 messages, or the inability to connect to a specific site even though your internet connection is otherwise stable. By flushing the DNS, you ensure that your system requests the most current IP address from the DNS server, resolving connectivity issues and ensuring you reach the correct destination.

What You'll Need

  • A Mac running macOS (this guide covers versions from High Sierra through Sonoma and Sequoia).
  • Administrator privileges on the computer (you will need to enter your password to authorize the command).
  • An active internet connection to verify the results after the flush.
  • Access to the Terminal application, which is pre-installed on every Mac.

Step-by-Step

  1. Close your web browsers: While not strictly required for the command to work, closing Chrome, Safari, Firefox, or Edge ensures that the browser's own internal DNS cache doesn't interfere with the system-level flush. This provides a clean slate for testing the connection.
  2. Open the Terminal application: You can find Terminal in two ways. First, you can press Command + Space to open Spotlight Search, type "Terminal," and press Enter. Alternatively, open a Finder window, navigate to the Applications folder, open the Utilities subfolder, and double-click the Terminal icon.
  3. Enter the flush command: Depending on your version of macOS, the command may vary slightly, though modern versions (macOS Big Sur, Monterey, Ventura, and Sonoma) use a standardized string. Type the following command exactly as written: sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder.
  4. Execute the command: Press the Enter key. Because the command begins with sudo (superuser do), the system requires administrative authorization to modify system-level caches.
  5. Enter your administrator password: The Terminal will prompt you for your password. Note that as you type your password, no characters, asterisks, or dots will appear on the screen. This is a standard security feature of the Unix-based Terminal. Type your password blindly and press Enter.
  6. Verify completion: Unlike many apps, the Terminal will not give you a "Success" message or a pop-up window. If the cursor simply returns to a new, blank line with your username, the command has executed successfully.
  7. Restart your browser: Re-open your web browser and attempt to visit the website that was previously giving you trouble. The browser will now be forced to perform a fresh DNS lookup.

Common Mistakes

One of the most frequent errors users make is mistyping the command. The Terminal is extremely sensitive to syntax; a missing semicolon, an extra space, or a lowercase letter where an uppercase one is required will result in a "command not found" error. Always double-check the spelling of mDNSResponder, as the capitalization of the 'DNS' and 'R' is critical for the system to recognize the process.

Another common mistake is the "blind password" confusion. New Terminal users often believe their keyboard is broken or that the system has frozen because they cannot see the password as they type. This leads them to type the password multiple times or press Enter repeatedly, which triggers a "Sorry, try again" error. Remember that the lack of visual feedback is intentional.

Users also frequently forget that macOS is not the only place where DNS is cached. If you flush the system cache but continue to see the old version of a site, you might be dealing with a browser-level cache. For example, Google Chrome maintains its own internal DNS cache that is separate from the macOS system cache. If you only run the Terminal command, the browser may still be holding onto the old IP address.

Tips

To make this process faster in the future, you can create a simple shell script or an alias in your .zshrc file. By adding a line like alias flushdns="sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder", you can simply type flushdns in the Terminal instead of remembering the long string of commands every time.

If you are a web developer or managing a domain migration, consider using a public DNS provider like Google DNS (8.8.8.8) or Cloudflare (1.1.1.1). These providers often propagate changes faster than local ISP DNS servers, reducing the frequency with which you need to manually flush your cache.

When testing if a DNS flush worked, use a "Private" or "Incognito" window. This disables most browser extensions and ignores certain local cookies that might be redirecting you to a cached version of a page, giving you a more accurate representation of whether the DNS resolution is actually functioning.

Troubleshooting

If you receive a "Permission Denied" error after entering your password, it means the account you are logged into does not have administrator rights. You must switch to an admin account or have an administrator enter their credentials to execute sudo commands.

If the command runs without error but the website still won't load, the issue may be "DNS Propagation." When a website owner changes their DNS records, it takes time for those changes to spread across every server globally. This can take anywhere from a few minutes to 48 hours. In this case, flushing your local cache won't help because the DNS server your Mac is asking for information from hasn't received the update yet.

In cases where the Terminal command seems to hang or doesn't return the prompt, try restarting the Mac entirely. A full system reboot clears the temporary system caches and restarts the mDNSResponder process from scratch, achieving the same result as the manual command.

If you suspect the problem is with your router rather than your Mac, try restarting your modem and router. Many routers maintain their own DNS cache. If the router is holding onto an old IP address, it will serve that incorrect address to your Mac regardless of how many times you flush the local cache on your computer.

Frequently Asked Questions

Will flushing the DNS cache delete my passwords or history?

No. Flushing the DNS cache only removes the temporary map of domain names to IP addresses. It does not affect your browser history, saved passwords, cookies, or any personal files on your hard drive.

Is it safe to flush the DNS cache frequently?

Yes, it is completely safe. There are no negative side effects to flushing your DNS. The only minor drawback is that the very first time you visit a site after a flush, it may take a fraction of a second longer to load because the Mac has to fetch the IP address from the server again.

Do I need to do this every time I restart my Mac?

No. DNS cache is persistent across some sessions but is often cleared or refreshed during a full system reboot. You only need to perform a manual flush when you are experiencing specific connectivity issues or after a known DNS change has occurred.

Why is my password not showing up in Terminal?

This is a security feature of the macOS Terminal (and Linux/Unix systems). It prevents people looking over your shoulder from seeing how many characters are in your password. The system is recording your keystrokes even though nothing is displayed.

What is the difference between the system cache and the browser cache?

The system cache is managed by macOS and affects every application that accesses the internet. The browser cache is specific to the app (like Chrome or Safari) and stores images, scripts, and sometimes its own DNS records to speed up page rendering.