Flushing the DNS cache on macOS

Every so often macOS holds onto a DNS answer longer than it should — you’ve just repointed a domain, switched VPNs, or fixed a broken record, and your Mac is still confidently resolving the old one. The fix is a one-liner:

sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder

It’s really two separate flushes chained together, because macOS caches DNS answers in two different places depending on the OS version:

  • dscacheutil -flushcache clears the Directory Service cache — the layer that backs dscacheutil -q host lookups and, on older macOS releases, most of what actually cached your DNS answers.
  • killall -HUP mDNSResponder sends a HUP signal to mDNSResponder, the daemon that does the actual DNS (and Bonjour/mDNS) resolution on modern macOS. A HUP tells it to reload rather than crash, which in practice clears its internal cache.

Which one actually matters has shifted across macOS versions, and Apple doesn’t document it cleanly — so rather than remember which release needs which command, running both covers you regardless of what you’re on. The semicolon (rather than &&) matters a little here too: it runs the second command whether or not the first “succeeded,” which is what you want, since dscacheutil -flushcache doesn’t reliably signal failure even when there’s nothing to flush.

You’ll be prompted for your password (possibly twice, if sudo‘s credential cache has already expired between the two commands). There’s no output on success — it just quietly works.

Make it a one-word command

If you find yourself reaching for this more than once, drop a function in your ~/.zshrc (or ~/.bashrc):

flush-dns() {
    sudo dscacheutil -flushcache
    sudo killall -HUP mDNSResponder
    echo "DNS cache flushed."
}

Reload your shell config, and flush-dns is a real command from then on.

$ flush-dns
DNS cache flushed.

WordPress and DreamHost: Perfect Duo

Leave a Reply

Your email address will not be published. Required fields are marked *