DNSmacOScacheflush DNSlocal development

Flush DNS on Mac: commands by macOS version (2026)

Clear DNS cache on Mac in 30 seconds. Exact commands for Sequoia, Sonoma, Ventura, Monterey and earlier versions. Automation script included.

L

Locahl Team

·4 min read

You've modified your hosts file but the changes aren't taking effect? The culprit is almost always DNS cache. In this guide, we'll see how to flush DNS cache on Mac, why it's necessary, and how to automate this repetitive task.

What is DNS cache?

The role of DNS cache

Every time you visit a website, your Mac must resolve the domain name (like google.com) to an IP address. To speed up this process, macOS maintains a local cache of recent DNS resolutions.

This cache avoids contacting DNS servers for every request, which improves browsing speed. However, it can become an obstacle when:

  • You modify the hosts file
  • A site changes IP address
  • You're testing DNS configurations
  • You switch between development environments

When to flush DNS cache

Common situations requiring a DNS flush:

  • After any modification to /etc/hosts (see our guide to edit the hosts file)
  • After a DNS server change
  • When a site "doesn't work" for no apparent reason
  • During server migration testing
  • To resolve "DNS_PROBE_FINISHED_NXDOMAIN" errors

Simplify your hosts file management

Locahl lets you manage your hosts file visually, without touching the terminal. Automatic DNS flush, multiple environments, and backups included.

Commands by macOS version

The exact command varies slightly depending on your macOS version.

macOS Sequoia, Sonoma, Ventura, Monterey (15.x, 14.x, 13.x, 12.x)

sudo dscacheutil -flushcache && sudo killall -HUP mDNSResponder

This command combines two actions:

  • dscacheutil -flushcache: Flushes the Directory Service DNS cache
  • killall -HUP mDNSResponder: Restarts the mDNS daemon

macOS Big Sur (11.x)

sudo dscacheutil -flushcache && sudo killall -HUP mDNSResponder

macOS Catalina, Mojave, High Sierra (10.15, 10.14, 10.13)

sudo killall -HUP mDNSResponder

macOS Sierra, El Capitan (10.12, 10.11)

sudo killall -HUP mDNSResponder

OS X Yosemite (10.10)

sudo discoveryutil mdnsflushcache && sudo discoveryutil udnsflushcaches

Tip: To find your macOS version, click the Apple menu () > About This Mac.

Running the command step by step

Step 1: Open Terminal

  • Press Cmd + Space to open Spotlight
  • Type "Terminal"
  • Press Enter

Step 2: Run the command

For macOS Monterey and later:

sudo dscacheutil -flushcache && sudo killall -HUP mDNSResponder

Step 3: Enter your password

Terminal displays Password:. Type your administrator password (nothing appears) and press Enter.

Step 4: Verify success

If the command succeeds, you simply return to the command prompt with no error message.

To verify, test with ping:

ping myproject.local

Why hosts changes don't work without flush

DNS resolution order

When you type a domain in your browser:

1. Browser cache - Chrome, Firefox have their own cache 2. System DNS cache - Managed by mDNSResponder on Mac 3. Hosts file - /etc/hosts 4. External DNS servers - Your ISP or public DNS

If the domain is already in system cache (step 2), the hosts file (step 3) is never consulted!

Automating DNS flush

Create a Terminal alias

Add this line to your ~/.zshrc file:

alias flushdns="sudo dscacheutil -flushcache && sudo killall -HUP mDNSResponder && echo 'DNS cache flushed'"

Reload your configuration:

source ~/.zshrc

Now, simply type flushdns in Terminal.

Automated shell script

Create a flush-dns.sh file:

#!/bin/bash
sudo dscacheutil -flushcache
sudo killall -HUP mDNSResponder
echo "DNS cache flushed successfully"

Make it executable:

chmod +x flush-dns.sh

With Locahl (automatic)

The Locahl app integrates DNS flushing automatically. Every time you modify a hosts entry, DNS cache is flushed without additional action.

Also flush browser cache

System DNS flush doesn't clear browser cache.

Chrome

1. Go to chrome://net-internals/#dns 2. Click "Clear host cache"

Firefox

1. Go to about:networking#dns 2. Click "Clear DNS Cache"

Safari

Develop menu > Empty Caches (Cmd + Option + E)

Troubleshooting

"Operation not permitted"

Cause: Insufficient permissions.

Solution: Use sudo and verify your account is an administrator.

"No matching processes"

Cause: The mDNSResponder process isn't running.

Solution: Restart it:

sudo launchctl kickstart -k system/com.apple.mDNSResponder

Changes still not taking effect

Check: 1. Browser cache cleared? 2. Active VPN using its own DNS? 3. Syntax error in hosts file? 4. Proxy configured?

Best practices

Create a routine

After each hosts file modification: 1. Save the file 2. Flush system DNS 3. Clear browser cache (if needed) 4. Test with ping

Use appropriate TLDs

  • .test: Recommended
  • .localhost: Always local
  • .local: Can conflict with Bonjour

Conclusion

Flushing DNS cache on Mac is a simple but essential operation. The command sudo dscacheutil -flushcache && sudo killall -HUP mDNSResponder should be part of your daily toolkit.

To eliminate this friction, tools like Locahl automate DNS flushing with every modification, allowing you to focus on your code.

Also readHow to edit the hosts file on Mac
Share this article
Available for macOS

Ready to simplify your workflow?

Stop wasting time with the terminal. Locahl lets you manage your hosts file in a few clicks, with automatic validation and no risk of errors.

  • Intuitive visual interface
  • Automatic DNS flush
  • Multi-environment management
  • Automatic backups
  • JSON Import/Export
Get Locahl - €9.99One-time payment, no subscription

Reader Reviews

4.7(3 reviews)
Chris P.

"The flushdns alias in .zshrc changed my life. I use it several times a day now."

September 25, 2025

Amanda F.

"Very useful to have commands by macOS version. I finally found the one that works for my Ventura."

November 30, 2025

Robert T.

"Complete article. I would have liked a section on browser DNS flush but otherwise perfect."

January 5, 2026

Frequently Asked Questions

How do I flush DNS cache on Mac?

Open Terminal and run: sudo dscacheutil -flushcache && sudo killall -HUP mDNSResponder. Enter your administrator password when prompted.

Why do I need to flush DNS cache?

DNS cache temporarily stores domain/IP associations. After modifying the hosts file or a DNS change, flushing the cache forces your Mac to use the new values.

Is the flush DNS command different for each macOS version?

Slightly. Since macOS Sierra (10.12), the standard command is: sudo killall -HUP mDNSResponder. For older versions, different commands are needed.

How do I know if the DNS flush worked?

Use the ping command with the affected domain to verify that the new IP address is being resolved.

Can I automate DNS flushing?

Yes, create an alias in your .zshrc file or use a tool like Locahl that integrates DNS flushing automatically.

Related Articles

6 min read
hosts fileDNSlocal development

Hosts file: definition, location, and syntax (2026 guide)

Master the hosts file in 5 minutes: location on Mac/Windows/Linux, syntax, use cases (local dev, ad blocking) and common mistakes to avoid. Updated January 2026.

L

Locahl Team

8 min read
Dockerhosts filemacOS

Using Hosts Files for Docker Development on Mac

Learn how to configure hosts files for Docker, docker-compose, and container networking. Map container services to local domains and streamline your Docker development workflow.

L

Locahl Team

11 min read
LaravelWordPresslocal development

Hosts File Setup for Laravel/WordPress Local Development

Complete guide to configuring hosts files for Laravel Valet, Herd, and WordPress local development. Learn custom domains (.test, .local), multisite configurations, and best practices.

L

Locahl Team