How to clear the DNS cache in Mac OSX, Windows and Linux

Print Friendly, PDF & Email

If you are developing websites, then the chances are at some time or other you have been driven crazy when you have updated the DNS for a client’s website only to find that your web browser is returning an error, or serving the default Apache webpage.

So, you go and check the DNS out using something like MyIPTest.com only to find that everything appears to be correct.

The confusion can be further compounded by the fact that some tools rely on the operating system’s cache (as do web browsers), while others fetch fresh results. For example, you can ping domain.com on OSX, and get a completely different IP address to that returned by dig domain.com a

This is because sometimes, the operating system’s cache doesn’t update quickly enough, because the TTL values stored within it haven’t yet timed out – so it sees no reason to go and fetch new results – not while the cached IP is reachable.

So, that’s the why – here’s the how!

Running these commands generally require admin privileges, so you may need to precede them with the sudo command, and use the root/admin password.

Mac OSX Prior to 10.5.1 (Leopard)

lookupd -flushcache

Mac OSX 10.5.1 and later (Including 10.6.x Snow Leopard)

dscacheutil -flushcache

You can obtain a full list of all entries in the cache using

dscacheutil -cachedump -entries

But this still won’t reveal the cached IP addresses – just the host names. If anyone knows how to get the cached IP addresses, let me know!

Linux

Depending on your flavour of Linux you may have nscd (Name Service Cache Daemon) installed. However Linux also comes without a client DNS cache (Ubuntu for one!) – so if you have problems, it may be the cache in your browser. Firefox has a cache manager plugin to enable you to see where things are going wrong.

To flush the DNS cache from nscd , restart the nscd daemon.

/etc/init.d/nscd restart

Windows

ipconfig /flushdns

also :

ipconfig /displaydns will show you the contents of the cache

You can also turn off the OS’s client cache by running this command, but it will start at next boot unless you disable it in the Service Manager.

net stop dnscache

Tags: , ,

One Response to “How to clear the DNS cache in Mac OSX, Windows and Linux”

  1. Tom Mason March 28, 2011 at 10:59 am #

    Another good tip is to use OpenDNS servers instead of your ISPs nameservers.

    It’s a 1 minute job to change them on your computer, or if you are more advanced you can change them on your router to give all your computers OpenDNS automatically.

    Once changed over you can check the DNS in their Cache, and if you’ve updated DNS records and they haven’t updated then you can force an update on their system!

    http://www.opendns.com/support/cache/

Leave a Reply

Bot test * Time limit is exhausted. Please reload the CAPTCHA.