How to Flush DNS Cache in Mac OS X

Mar 21, 2008 - 13 Comments

Flush DNS Cache in Mac OS X Whether you’re a systems administrator or a web developer, or anything in between, chances are you’ll have to flush your DNS cache every once in a while to get things straightened out server-side, or even just for testing certain configurations.

Flushing your DNS cache in Mac OS X is actually really easy, but there are actually several different commands to use, and you will find the commands are unique to different versions of OS X. We’ve got you covered regardless of what version of Mac OS X you’re running, from OS X 10.10, OS X 10.9, all the way back to 10.4. So find your version of OS X, open your Terminal, and follow the appropriate directions below to get started.


Remember, each of these commands must be entered into the command line, by way of the Terminal applications (found in /Applications/Utilities/ in all version of Mac OS X). Launch that app first and then you can just copy and paste the commands in if you’d like.

Clearing DNS Cache in OS X 10.10 Yosemite

Running the latest version of OS X? Clearing DNS caches in OS X Yosemite has changed again, split into MDNS and UDNS or combined like we’ll use below, here’s the command that is needed:

sudo discoveryutil mdnsflushcache;sudo discoveryutil udnsflushcaches;say flushed

You can read much more about resetting and flushing DNS cache in OS X Yosemite here if you’re interested.

Flush DNS in OS X 10.9 Mavericks

Rere is how to flush the DNS cache in 10.9:

dscacheutil -flushcache;sudo killall -HUP mDNSResponder

You will need to enter the admin password for this task to complete. If you notice, it combines killing mDNSResponder with the standard dscacheutil, making it a two step process to first, flush cache, then reload the DNS handling in OS X so that the changes take effect.

Flushing DNS Cache in OS X Lion (10.7) and OS X Mountain Lion (10.8)

Launch Terminal and enter the following command, you will need to enter an administrative password:
sudo killall -HUP mDNSResponder
Note the dscacheutil still exists in 10.7 and 10.8, but the official method to clear out DNS caches is through killing mDNSResponder. You can also find that process running in Activity Monitor.

One helpful trick if you find yourself flushing the DNS frequently is to setup an alias for that command string in your .bash_profile or in the profile of your shell of choice. A simple bash alias for flushing cache could be this:

alias flushdns='dscacheutil -flushcache;sudo killall -HUP mDNSResponder'

Save that into .bash_profile, then typing “flushdns” would prevent having to use the full command string in the future.

Flush DNS Cache in Mac OS X 10.5, Mac OS X 10.6

Launch Terminal and issue the following command:
dscacheutil -flushcache
All done, your DNS has been flushed. On a side note, the dscacheutil is interesting in general and worth taking a look at, try the -statistics flag instead for some stats.

Flush DNS in Mac OS X 10.4 Tiger, & 10.3

Type the following command in the Terminal:
lookupd -flushcache

That’s it, that’s all there is to it. Now your DNS settings should be as you intended them to be, which you can easily verify with various networking tools like http, ping, nslookup, traceroute, curl, or whatever else is appropriate to your specific situation.

If you find something isn’t working and DNS does not appear to have changed, verify the version of OS X you’re running and use the appropriate commands for the latest version. If you’re still having problems after that, try a different machine ideally on a different network (like a cell phone) to verify that it’s not an issue with the remote server.

Enjoy this tip? Subscribe to the OSXDaily newsletter to get more of our great Apple tips, tricks, and important news delivered to your inbox! Enter your email address below:

Related articles:

Posted by: Paul Horowitz in Command Line, How to, Mac OS X, Tips & Tricks

13 Comments

» Comments RSS Feed

  1. Cherooo says:

    thank you very much for this article, I wanted to ask you please how can erase our dns cache?

  2. carset says:

    Does this function still work? I’ve changed my nameservers on a site I own and it’s been hours and I’m still getting the old results… I’ve tried flushing the dns and it’s still not working.

    • htech says:

      Changing Name Servers requires a propagation time as network data centers need to re-cache your change. It usually takes about an hour, but can be up to about 24 hours depending on your location and service provider

    • aaron says:

      If you can log into a remote machine (ssh) you could check from there. So a VPS or even a dreamhost/hostgator account with SSH access. Or you could use your phone or another computer in your house.

  3. logicalnot says:

    As of today, the command works perfectly. Thank you.

  4. Mike says:

    Once I enter the command into Terminal, does any confirmation script appear to confirm the cache has been cleared?

  5. […] a Mac you may need to follow this up with flushing DNS cache, so open the Terminal and type the […]

  6. Al Varnell says:

    I’ve heard this does not work in Lion and that you must use the following, instead:

    sudo killall -HUP mDNSResponder

  7. okcomputer says:

    Works Great on Lion. Cleared an issue I had with multiple hostnames

  8. […] You can verify your hosts modifications immediately with ping, Safari, or any other network app. Changes take effect immediately though some adjustments may need to be accompanied by a DNS flush. […]

  9. Kev McGowan says:

    Apple have removed the RSS reader from the current version of Mavericks/Safari, so now the RSS feeds from torrent websites no longer work; is there any way to re-enable the RSS reader within Safari?

  10. iFXBR says:

    Script for all OS version:

    #!/bin/bash
    export OS=`sw_vers | grep ‘ProductVersion:’ | grep -o ‘[0-9]*\.[0-9].’`
    echo DNS Flush Cache
    case $OS in
    10.9.|10.8.|10.7.) dscacheutil -flushcache; sudo killall -HUP mDNSResponder ;;
    10.6.|10.5.) dscacheutil -flushcache ;;
    10.4.|10.3.) lookupd -flushcache ;;
    esac
    echo Done!

  11. johnny99 says:

    love the alias shortcut. how could I set this up in Automator to run at start-up? thanks!

Leave a Reply

 

Shop for Apple & Mac Deals on Amazon.com

Subscribe to OSXDaily

Subscribe to RSS Subscribe to Twitter Feed Follow on Facebook Subscribe to eMail Updates