DNS request are usually cached, that’s good as it help to speeds up the lookups within the same host but sometimes we will want to clear the cache so it don’t hold the values that are no longer valid or we edited hosts file to block or redirect hosts or IP. To clear DNS cache in Mac OSX, we can do it with the help of Terminal.
Mac OSX 10.9
Open up the application called “Terminal”
Type this command:
dscacheutil -flushcache
To reload DNS type this command:
sudo killall -HUP mDNSResponder
For older versions of OS X go here.
For new OS X 10.10 Yosemite go here.
If you need to edit hosts file go here.
Vicenzo Moderata says
Hello,
When I do the command, for example,
dig http://www.google-analytics.com
I get the response:
http://www.google-analytics.com. 71217 IN CNAME www-google-analytics.l.google.com.
www-google-analytics.l.google.com. 156 IN A 201.17.31.88
The number 156 means that this entry still has 156 seconds of live in the cache.
When I do the command mencioned in your article, to flush the cache, and do the dig again, the number does not start to count again….
If the cache was flushed, it wasn’t suppose to start to count from 300 again???
Kind regards,
Vicenzo
iHash says
No You are wrong. This TTL is from DNS server and not from your mac. Every DNS server is having set their own TTL usually 300 seconds.
Try this command to get your DNS cache list “sudo dscacheutil -cachedump”, but it was reported by many users that this command is not always working on Mavericks.
Katie Overbeek says
After I follow these instructions it prompts me to enter my password, but will not let me type it out. Unsure what to do?
iHash says
Just type password and press enter.
Bryant says
Is there any other way to flush dns? When Terminal asks for my password it doesn’t accept my keychain admin password.
Milan says
Are you typing correct password? You need admin password of your mac. For sudo commands you need admin rights.
You can try with Onyx app it`s having option to clear DNS cache (Cleaning > Internet > Delete: DNS Cache).
Bryant says
I used my admin password with no result: old page came up after repeated tries. And just now got this on attempting to open page: HTTP Status 500: org.apache.tiles.impl.CannotRenderException: JSPException including path ‘head.jsp’.with a screen full of code. I also tried the Onyx leaning option. I tested the site on another computer and it works fine.
Thanks for your response!
Bryant says
umm.. Onyx CLEANING option.
Bryant says
I used Onyx again, and this time in the cleaning, I added the “bash” file to the list of checked items. It worked. Don’t have any idea what the bash file is, but the word appeared at the top of the terminal window, so I gave it a shot.
asd says
good stuff
Alex says
I also had the same problem as Bryan and my password