Quick Tip - Flushing DNS Cache

Date December 16, 2007

When testing deployment of sites or updating IP addresses in /etc/hosts , sometimes it’s useful to force a DNS cache flush. Sometimes, a stale DNS entry can remain cached and a site will appear to be down when it’s really not. It’s easier to flush the cache than wait and wait for it to expire on its own, which can take upwards of 24 hours, depending on settings.

Here’s how to do it with Windows, Mac OSX, and Linux.

Windows

In Windows, flush the DNS cache using the ubiquitous ipconfig command from the Run dialog box, or from a shell.

ipconfig /flushdns

Mac OSX

In 10.4 and earlier, DNS cache is handled by lookupd. Leopard (10.5) replaces it with dscacheutil. Execute the following in a terminal to clear your DNS cache.

# 10.4 and earlier:
$ sudo lookupd -flushcache


# Leopard (10.5) and later:
$ sudo dscacheutil -flushcache

Linux

Some distributions run a caching nameserver in the background out of the box while some do not. To clear the cache if you have such a daemon running, simply restart the service. Location may vary by distro, but here are two possibilities:

#sudo /etc/init.d/nscd restart
or
#sudo /etc/rc.d/nscd restart
or possibly
# service nscd restart

One Response to “Quick Tip - Flushing DNS Cache”

  1. sundar said:

    Some unixes/linuxes do not cache DNS (I believe it’s by default that they don’t cache dns entries, but may be wrong on that). You only need to flush the DNS cache on linuxes if nscd is installed.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>