Clearing DNS cache in Mac OS X

When one visits a website (domain name) the resolved IP address of the website gets cached. Now, if you are the one who plays with the site’s Name Servers then probably you would have faced the situation where the older IP address gets cached and so you are sent to the old website on subsequent attempts. Most of the times since the Name Servers take time to propagate its all the more confusing. It’s happened to me twice and so here I post this note to help troubleshoot the issue.

Consider example.com is the domain you are troubleshooting.

So here is what you can do when you type example.com in the address bar of the browser and the old website shows:

First make sure that your name servers have been updated appropriately in your domain’s control panel.

Clear the browser cache:

This is the simplest to clear. Hit ‘Apple+R’ to clear the cache in Safari. Try visiting the site again. Stop if it works fine.

Clear the system level cache:

$ lookupd -flushcache in OS X 10.4 and
$ dscacheutil -flushcache in OS 10.5.

Now, clear the browser cache and try again. Stop if it works fine and write me a comment below :).

Override ISP level chache: If its still not cleared off then it means that its been cached at the ISP’s side. You can take a look at the output of the ‘dig’ command.

$ dig example.com

Take note of the various sections therein. The IP Address (ANSWER SECTION) and name servers (AUTHORITY SECTION) should be listed correctly. If not, which means the lookup has been cached at the ISP’s side name servers mentioned in /etc/resolv.conf.

To override this you would need to edit the /etc/hosts file directly.

Append an entry ‘ ‘ to the file.

Now, reload the Netinfo db.

$ sudo niload -v -m hosts . < /etc/hosts

Clear the above two caches and try again. Stop if it works and write me a big good thank you note. I saved you a lot of time ;)

If you still haven't got it to work then you can try one last thing. Send a HUP to the lookupd process.


$ ps auxw | grep lookupd
root 325 0.0 0.1 29204 1444 ?? Ss 5:56PM 0:00.25 /usr/sbin/lookupd
$ sudo kill -HUP 325

Check again while you keep your fingers crossed. If it works perfect, I have saved your day ;). Write me a Thank you email :).

The last thing did the trick for me. Once before 'Clearing the system level cache' was good enough.

Hope this helps someone to save some productive hours.

9 Replies to “Clearing DNS cache in Mac OS X”

  1. Hi and thank you – that did it. Frustrating that I have been trying to sort this out for a day or two – wished I had come across your website earlier.

    Once again huge thanks.

    Rich

  2. It helped to resolve the issue in my case by removing DNS servers in the modem system preferences:
    Netowrk > Modem > TCP/IP > DNS Servers (optional).

    To check dns cache at provider:

    dig @name.server.my.provider.com http://www.example.com

    alan

  3. Hi,

    thanks, i have done first 2 steps and nothing, i know that it is isp prob thanks to the lookup, but i cant find a hosts file on my computer. How do i find and edit the hosts one, please email me, thanks so much!

  4. I’m having the same problems (OSX 10.5.5), but I don’t seem to have ‘niload’ and ‘lookupd’ on my system.

    Any suggestion what to do in this case ?

Comments are closed.