Evolution of Flushing MacOS DNS Cache

I recently updated both my work and home Macs to OS X 10.10, aka Yosemite. As with most OS upgrades, little changes have accompanied the marquee upgrades. In particular, Yosemite has yet another way to flush the local DNS cache.

Most folks will never need to do that particular operation, but it comes in handy for DNS adminstrators who want to test recent changes.

Here’s the evolution of how this gets done in OS X:

  • Big Sur, Monterey
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder
  • Sierra, High Sierra, Mojave, Catalina
sudo killall -HUP mDNSResponder
  • Yosemite:
sudo discoveryutil udnsflushcaches
  • Lion, Mountain Lion, Mavericks:
sudo killall -HUP mDNSResponder
  • Leopard, Snow Leopard:
sudo dscacheutil -flushcache
  • Tiger and earlier:
sudo lookupd -flushcache

Verifying the empty cache

I ran a bunch of DNS lookups using the host command-line utility and checked in on the state of discoveryd’s unicast-DNS cache. Then I flushed the cache and looked again. Note that discoveryutil is not shipped with post-2015 MacOS releases.

[bash ~]$ sudo discoveryutil udnscachestats
  
UDNS Cache Stats: Ext Resolver on en5
UDNS Cache Stats: Resolver domain [default], type Unicast, ifIndex 13, port 0, timeout 30, A yes, AAAA yes, serviceID 0, scope None, order 0
  server(s) 8.8.8.8, 8.8.4.4
  search domain yourdomain.com
UDNS Cache Stats: Cached 670 of 5000, table size 256, hash coverage 0.58, max miss depth 16, avg miss depth 1.32, reclaims 0
Cached records after aging 479
  
[bash ~]$ sudo discoveryutil udnsflushcaches
[bash ~]$ sudo discoveryutil udnscachestats
  
UDNS Cache Stats: Ext Resolver on en5
UDNS Cache Stats: Resolver domain [default], type Unicast, ifIndex 13, port 0, timeout 30, A yes, AAAA yes, serviceID 0, scope None, order 0
  server(s) 8.8.8.8, 8.8.4.4
  search domain yourdomain.com
UDNS Cache Stats: Cached 0 of 5000, table size 256, hash coverage 0.00, max miss depth 0, avg miss depth 0.00, reclaims 0
Cached records after aging 0

The first statistics show a cache of 479 records, but after the flush the cache shows 0 entries. Huzzah!

Mac  Howto