How to Flush DNS Cache in OS X Yosemite with discoveryutil

Some Mac users may encounter situations where they need to flush DNS cache in OS X for a name server to resolve properly, or for some DNS address change to become noticed by their individual computer. This is particularly relevant for system administrators, network admins, and web developers, but there are certainly situations where other users may need to dump and reset DNS caches too, like if a user has modified the /etc/hosts file and they need the changes to take effect without rebooting the Mac.

Longtime Mac users will know that resetting DNS cache has changed in nearly every version of Mac OS X, and OS X Yosemite is no different, likely due to the discoveryd replacing mDNSResponder, and then switching back to mDNSResponder yet again. Regardless, flushing DNS cache in Yosemite remains a terminal command, but it differs slightly depending on the exact release you are using of the OS, and it actually allows you to clear either Multicast DNS or Unicast DNS, or both. You’ll probably want to clear both for good measure if you’re trying to reset all DNS caches on the Mac.

Clear DNS Cache in OS X Yosemite 10.10.4 & OS X 10.10.5

From OS X 10.10.4 moving onward to 10.10.5, including 10.11, Apple has ditched discoveryd and has replaced it (or rather, reverted back to) mDNSResponder. Thus, to clear DNS caches in OS X Yosemite 10.10.4, and 10.11 El Capitan, and presumably onward, the command string is as follows:

Longtime Mac users may recall that command string is basically what worked in the release prior to Yosemite. With that said, earlier versions of OS X Yosemite before 10.10.4 will use a different command string discussed below.

You’ll need to use the Terminal to reset cache, you can find the Terminal app in /Applications/Utilities/ or launch it with Spotlight. To completely clear all DNS caches in the latest version of OS X, target both MDNS (Multicast DNS) and UDNS (Unicast DNS) with two different commands.

Clear MDNS Cache

sudo discoveryutil mdnsflushcache

Hit return and enter the admin password when requested.

Clear UDNS Cache

sudo discoveryutil udnsflushcaches

Again, hit return and enter the admin password when requested. Note that caches is plural with the latter command, a subtle but important syntax difference.

Flush and Reset All DNS Caches in OS X Yosemite

You can also string the above two commands together if you want, the following will even verbally announce when the caches have been cleared:

Indeed MDNS and UDNS caches are different, but I’ve found that for functional DNS cache to actually clear in OS X Yosemite both commands are necessary. It’s entirely possible that you only need to clear one or the other for your own needs.

Checking DNS Cache Details in OS X Yosemite

If you are changing or are going to change DNS, and you want to see some details about what is currently cached, you can use the following commands:

Get UDNS cache statistics:

sudo discoveryutil udnscachestats

You can also retrieve specifics about multicast DNS cache with the following:

sudo discoveryutil mdnscachestats

Both of these will offer details as to the number of DNS entries are cached, offering a report that should look like this:

UDNS Cache Stats: Cached 962 of 1750

If you run those commands before and after running the flushcache variations, you’ll find they should be reset to 0 entries cache, like so:

MDNS Cache Stats: lo0: Cached 0 of 2000

How do you know if it changed?

After you’ve flushed cache, if you want to determine if a name server or IP has actually changed you can use the ‘dig’ command with the URL like so:

dig osxdaily.com

dig is similar to nslookup, except that it has better output and a few more details included, included query time, the set DNS server used to access the domain, and a timestamp, all of which can be valuable when troubleshooting name server issues. By the way, if the query time for this shows up as sluggish, you should use a tool like namebench to find a faster DNS server for you, often Google DNS or OpenDNS.

Know of another DNS cache trick for the latest versions of OS X? Let us know in the comments.

It’s good to note the venerable Unix host, dig, and nslookup commands use different resolver mechanisms than most of OS X. When troubleshooting I usually compare with ping which gives the same results as the gui apps.

I use VPNs to customer sites daily, and often need to debug the VPN sites local DNS not being used.
When I find the DNS resolver works by testing with the host command, I cross check the same host with ping. If the results are not alike, it’s time to flush the DNS cache.

On a side note, the equivalent procedure with DNS flushing used to work for all hosts in a remote vpn site in previous releases, but now I find I need to flush the cache more than once to get multiple hosts working. I sure hope Appe will settle on the architecture to use for resolver and put more effort in stabilizing it 😄

Thank you for this post very “to the point”. It is extremely helpful to myself who has really no knowledge of these things past os 9.. I checkout long ago. Thanks for making a simple copy paste situation. Appreciated!

If you’re using OS X 10.10.4 or later you will use the new command, which is the old command but working again in the latest release. Apple ditched discoveryd and switched back to mDNSResponder (LOL). Thus here is the command to flush caches in 10.10.4 or newer:

Is there a way to create a shortcut to automatically do this when I need to rather than finding the code in notes , opening up terminal and going the through the process. Just converting over from a windows O/S and I have a shortcut on my desktop to do this, just learning how the macbook air works though so need a bit of friendly advice

Thanks for the info but i too get the same error . Error not resolved …

The server at monkeygodgame.com can’t be found, because the DNS lookup failed. DNS is the network service that translates a website’s name to its Internet address. This error is most often caused by having no connection to the Internet or a misconfigured network. It can also be caused by an unresponsive DNS server or a firewall preventing Google Chrome from accessing the network.

This website and third-party tools use cookies for functional, analytical, and advertising purposes. By continuing to browse the site, closing this banner, scrolling this webpage, or clicking a link, you agree to these cookies. You can review our privacy policy for additional information.I AcceptPrivacy Policy