Skip to content
Tricks & Tips Search the site/

How to flush the DNS cache on a Mac

The Terminal command that clears the DNS cache on macOS 27, how to check that it worked, and what to try when a site still won't load.

Updated Beginner friendlyAbout 2 minutes

The quick answer

Open Terminal, paste sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder, press Return and type your Mac login password. Nothing shows on screen while you type the password. That's normal.

Your Mac then forgets the website addresses it had saved and looks them up fresh. That fixes a site that still goes to its old address after a DNS change, or won't load because of an old saved lookup. If it doesn't, clear your browser's own DNS cache, restart your router or switch to a public DNS server.

Your progress 0 of 3 steps complete
0 of 3

When a website won’t load on your Mac but works on your phone, or your Mac still goes to an old server after a DNS change, flushing the DNS cache is one of the first things to try. Your Mac keeps the addresses of sites it has looked up for a while, so it doesn’t have to ask a DNS server every time. Clearing that saved list makes it ask again.

How to flush the DNS cache on a Mac

To flush the DNS cache on a Mac, run one command in Terminal and enter your administrator password. These steps are for macOS 27. The mDNSResponder part of the command is the one Apple has documented since OS X Yosemite 10.10.4.

Step 1: Open Terminal

Press Command-Space, type Terminal and press Return. You can also find it in Finder under Applications > Utilities > Terminal.

Step 2: Run the flush command

Copy this line, paste it into Terminal and press Return:

sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder

The semicolon runs the two commands one after the other, and sudo runs them with administrator rights, which the mDNSResponder part can’t do without.

Step 3: Enter your password

When Terminal shows Password:, type the password you use to log in to your Mac and press Return.

The cursor won’t move and no dots appear while you type. sudo hides the password on purpose, so just type it and press Return. On a work Mac or a child’s account you may need someone with an admin account to do this.

Now quit your browser, open it again and reload the site.

What the command does and doesn’t fix

Flushing makes your Mac forget the internet addresses it has saved for website names, so the next visit asks a DNS server again.

DNS is what turns a name like example.com into the numeric address of the server behind it. Your Mac keeps each answer for a time set by the DNS server. So when a site moves to a new server, or you change the DNS records for your own domain, your Mac can keep going to the old address until that time runs out. Flushing ends the wait.

Each half of the command clears one cache: dscacheutil -flushcache empties the Directory Service cache, and killall -HUP mDNSResponder tells mDNSResponder, the background process that handles DNS lookups on a Mac, to drop the replies it has saved. Apple’s own instructions for OS X 10.10.4 and later use only the second half, so running both just makes sure.

Your Mac’s cache is only the first stop, though. Flushing won’t help when the site is actually down, when your Wi-Fi or internet is out, or when the old address is still saved on your router or your internet provider’s DNS server.

How to tell if it worked

Ask your Mac which address it now has for the site, then ask a public DNS server and compare the two.

This asks your Mac, through the same lookup your apps use:

dscacheutil -q host -a name example.com

Put your site’s name in place of example.com. On our Mac it printed this, plus a similar block of IPv6 addresses:

name: example.com
ip_address: 172.66.147.243
ip_address: 104.20.23.154

This asks Cloudflare’s public DNS server directly with dig, which skips your Mac’s cache:

dig @1.1.1.1 example.com +short

If both show the same addresses, your Mac is up to date. If your Mac shows an old address and dig shows the new one, flush again or restart the Mac. A mismatch on a big site doesn’t prove much, though, because big sites can hand out different addresses to different DNS servers. It matters when you know which address is the new one, for example after changing your own domain’s records.

If your Mac keeps showing an address that dig never does, look at the hosts file with cat /etc/hosts. A line there with that site’s name overrides DNS, and flushing won’t remove it.

Clear your browser’s DNS cache

Chrome and Firefox keep their own DNS caches on top of your Mac’s, so if a site still goes to the old address after the Terminal flush, clear those too.

  • Chrome: type chrome://net-internals/#dns in the address bar and click Clear host cache. If that’s not enough, chrome://net-internals/#sockets has a Flush socket pools button that drops connections Chrome still has open. Chrome warns that this may break pages with active connections.
  • Firefox: type about:networking#dns in the address bar and click Clear DNS Cache.
  • Safari: there’s no DNS button, so quit Safari with Command-Q and open it again. If the page itself still looks old, turn on Safari > Settings > Advanced > Show features for web developers, then choose Develop > Empty Caches.

What to try when flushing doesn’t help

When the old address survives a flush, it’s usually saved somewhere past your Mac, so work outward from the router.

Restart your router. Open Apple menu > System Settings > Network, click your network service, such as Wi-Fi, click Details, then DNS. If the server listed is your router’s local address, such as 192.168.1.1, your router handles lookups for your home and routers can run a small caching DNS server of their own, such as dnsmasq. A restart empties it. Unplug it, plug it back in, then flush your Mac again. If the list shows public addresses instead, skip this.

Switch to a public DNS server. If the old answer is stuck at your internet provider, ask a different server. In the same DNS screen, click + under DNS Servers and add 1.1.1.1 and 1.0.0.1 (Cloudflare) or 8.8.8.8 and 8.8.4.4 (Google Public DNS). Those servers don’t share your provider’s saved answers, and you can remove them again later. On macOS Monterey 12 and earlier, the setting is in System Preferences > Network > Advanced > DNS.

Ask the public DNS server to refresh. If you changed the DNS records for your own website, Google’s Flush Cache page and Cloudflare’s Purge Cache page let you clear one domain from their caches.

Check for a VPN. A VPN can give your Mac its own DNS servers. Run scutil --dns to see every DNS server macOS is using, or turn the VPN off and try the site again.

If sites load but just feel slow, DNS is rarely the problem. Test your internet speed with networkQuality instead.

If something does not work

Does restarting a Mac clear the DNS cache?

Yes. Apple says that if your Mac isn't using the latest DNS entries, restarting it updates its cached information. The Terminal command does the same thing without closing your apps.

Is it safe to flush the DNS cache?

Yes. It only throws away saved address lookups, and your Mac fetches them again the next time you open a site. Your browsing history, cookies, passwords and files are not touched.

How often should I flush DNS on a Mac?

Only when a site misbehaves. Your Mac keeps each answer only for as long as the DNS server allows and then looks it up again by itself, so there is no reason to flush on a schedule.

Why does Terminal say I can't use sudo?

Only administrator accounts can use sudo. If you're logged in as a standard user, Apple's Terminal guide says to switch with su followed by an administrator's user name, enter that person's password, and run the command from there.

Will flushing DNS make my internet faster?

No. It doesn't change your connection speed, and the first visit to each site afterwards needs a fresh lookup. It only helps when a saved answer is wrong.

Sources

Keep exploring

Search tricksandtips.net