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 is the domain you are troubleshooting.

So here is what you can do when you type 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

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.