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 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¬† on OSX, and get a completely different IP address to that returned by dig 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!


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


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”