Sponsored Links

If you are a network administrator, web developer or a system administrator of Mac, you may face a necessary situation to flush DNS cache on Mac OS X. Especially if you want a name server to resolve rightly or a change in DNS address to be detected by your individual system.

Besides the above reasons, if you have altered the /etc/ hosts file and you need the modifications to take effect minus rebooting the Mac, then you may find it necessary to dump and reset DNS caches.

Sponsored Links

How to Flush DNS in Mac OS X

Resetting DNS cache is not the same in each version of Mac OS X. If you are a Mac user for a longer period, you may know that this process in OS X Yosemite is similar to some other older versions. This is probably due to the discoveryd replacing mDNSResponder, and then switching back to mDNSResponder yet again. Despite the change, flushing DNS cache remains a terminal command in Yosemite, but there is a little difference depending on the exact version of the OS you are using. You get to clear either Unicast DNS or Multicast DNS, or both. If you are attempting to reset all DNS caches on the Mac, then you may have to consider clearing both as a proper measure.

How to Clear DNS Cache in Mac OS X Yosemite or El Capitan

From OS X 10.10.4 onwards, with the inclusion of 10.11, Apple has discarded discoveryd and has substituted it with mDNSResponder. As a result, to flush DNS caches in OS X Yosemite and Mac OS X El Capitan, and most likely future releases, following is the command string:

sudo dscacheutil -flushcache;sudo killall -HUP mDNSResponder; say cache flushed

Sponsored Links

Using the above command clears all DNS caches for OS X 10.10.4 and onwards.

Being a Mac user for a longtime, you may remember that this command string essentially is what worked in the release preceding Yosemite. However, the releases of OS X Yosemite previous to 10.10.4 will employ different command string as mentioned below

How to Clear DNS Caches in Mac OS X Yosemite or El Capitan

To reset cache you need to use the Terminal. Find the Terminal app in /Applications/Utilities/ or open it with Spotlight. Target both UDNS (Unicast DNS) and MDNS (Multicast DNS) with two different commands to fully flush all DNS caches in the most recent version of OS X.

Clear MDNS Cache

sudo discoveryutil mdnsflushcache

Press return key and enter the admin password when asked.

Clear UDNS Cache

sudo discoveryutil udnsflushcaches

Another time, press return key and enter the admin password when asked. In the second command the caches is plural, a small but crucial syntax variation.

How to Flush and Reset All DNS Caches in OS X Yosemite

If desirable it is also possible to string the two commands together. The following command will announce out loud when you clear the caches:

sudo discoveryutil mdnsflushcache;sudo discoveryutil udnsflushcaches;say flushed

Without a doubt MDNS and UDNS caches are different, but you can figure that both commands are required for functional DNS cache to really clear in OS X Yosemite. For your own requirements if you only need to clear one or the other, it is fully possible.

It is noteworthy that OS X Yosemite has moved on from mDNSResponder. Thus, you need not kill the mDNSResponder process to refresh DNS caches as in earlier versions of Mac OS X.

In case you are using earlier version of OS X like Mavericks, Mountain Lion, or Lion, then the commands to flush DNS will be different. Below we have mentioned Terminal commands for the earlier versions on Mac OS X, have a look.

How to flush DNS cache in OS X Mavericks, Mountain Lion, and Lion

The command below will facilitate you to reset the DNS cache in OS X v10.9.5 and earlier:

sudo killall -HUP mDNSResponder

If you are using Mac OS X Snow Leopard, then the Terminal commands for the same are below, check it out.

How to flush DNS cache in Mac OS X Snow Leopard

Just copy paste the command given below to reset the DNS cache in OS X v10.6 through v10.6.8:

sudo dscacheutil -flushcache

How to Check DNS Cache Details in OS X El Capitan or Yosemite

While you are changing DNS, if you want to know about what is cached at the time, you can use the commands as follows:

Get UDNS Cache Statistics

sudo discoveryutil udnscachestats

Additionally you can recover details about multicast DNS cache with the following command:

sudo discoveryutil mdnscachestats

Both the above mentioned commands offer information such as the number of DNS entries cached, providing an account of details in the following way:

UDNS Cache Stats: Cached 1250 of 1900

If you run the commands before and after executing the flushcache variations, you will discover that they must be reset to 0 entries cache, just like given below:

MDNS Cache Stats: lo0: Cached 6 of 7500

How Do You Know If Change Has Occurred

Once you clear the cache, if you wish to know whether the IP or name server has really changed, make use of the ‘dig’ command with the URL as given below:

dig igeeksblog.com

Sponsored Links

dig and nslookup are quite similar, but with the exception that dig gives better result by including additional information. It provides details like the set DNS server used to access the domain, a timestamp and the included query time, all these details are useful when troubleshooting name server problems. If the query time in the result is sluggish, you must use a tool named namebench to get a faster DNS server, commonly OpenDNS or Google DNS.

Previous articleHow to Use Gray Background in Safari on Mac OS X El Capitan
Next articleAirDrop Not Working on Mac OS X Yosemite, How to Fix It?
Dhvanesh Adhiya is our editor-in-chief and reviewer who takes care of iGeeksBlog.com. He is passionate for wonderful apps that change the way your iPhone interacts in your life.
  • Monkey God

    Your commands helped me lot to solve my issue .