MacOS – Flush cache of DNS on macOS Sierra & High Sierra

dnshigh sierramacos

How to flush the cache of the DNS system on a macOS Sierra or High Sierra Mac?

I have seen discussion of the following, but am not sure if this is the modern approach. And I am not sure what each does exactly.

sudo dscacheutil -flushcache
sudo killall -HUP mDNSResponder

Best Answer

sudo dscacheutil -flushcache does nothing useful related to DNS cache entries - at least in non-LDAP environments and 10.9-10.13.

sudo killall -HUP mDNSResponder sends a hang up to mDNSResponder, launchd will restart the daemon and the DNS cache will be cleared as spillover effect.

This can easily be tested with the following command sequence:

sudo killall -INFO mDNSResponder

default 03:54:55.672826 +0200 mDNSResponder Cache size 282 entities; 189 in use (73 group, 29 multicast, 87 unicast); 2 referenced by active questions
default 03:54:55.694219 +0200 mDNSResponder Unicast Cache size 1769

sudo dscacheutil -flushcache
sudo killall -INFO mDNSResponder

default 03:55:52.148629 +0200 mDNSResponder Cache size 282 entities; 180 in use (79 group, 19 multicast, 82 unicast); 2 referenced by active questions
default 03:55:52.157180 +0200 mDNSResponder Unicast Cache size 1992

sudo killall -HUP mDNSResponder
sudo killall -INFO mDNSResponder

default 03:56:39.446829 +0200 mDNSResponder Cache size 282 entities; 8 in use (4 group, 0 multicast, 4 unicast); 2 referenced by active questions
default 03:56:39.466259 +0200 mDNSResponder Unicast Cache size 121

To get the results above open Console.app, choose your hostname in "Devices" and use a filter mDNSResponder & Cache size:

enter image description here