The Evolution of Flushing DNS Cache in Mac OS X

By Paul Heinlein | Oct 24, 2014

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:

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.

[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!