Trust me. We’re still dealing with regexes – just in a roundabout (and vaguely practical) way. This is a pretty comprehensive listing of how to go about flushing DNS caches while using regexes to show where similar methods deviate.

Why do we want to clear DNS caches exactly?

There are a number of reasons to clearDNScaches, though I believe these are the most common:

Anintranetservice has anprivate (internal) IP address when on the company network but it has a public IP address for outside access. When you try to access that service from outside after accessing it from inside, there’s a chance that you would have cached the private (inaccessible) IP. A good long-term solution is to make the service inaccessible except viaVPN. A simpler solution is to leave work at work. 😛

An internet service or web site changes their DNS settings and your desktop/laptop is looking at the “old” setting. In this case, the new setting has not yetpropagated. Hosting Admins come across this case very often.

Privacy: If someone can track your DNS history then it wouldn’t be too hard to figure out which web sites you’ve been viewing. Though the individual pages you’ve viewed can’t be tracked in this way, the hostnames, such as “dogma.swiftspirit.co.za” or “google.com” will be in the DNS cache, likely in the order you first accessed each site. There are better ways to do this though. One example is to use a Tor network for all DNS requests.

Flushing Windows’ DNS cache, from command prompt:

Evidence suggests that prior toWindows 2000, WindowsOS’s didn’t cache DNS results. Theipconfigcommand, run from the command prompt, was given some control over the DNS cache and has remained roughly the same since.

To get to the prompt if usingVistaas non-Admin: Start -> Programs -> Accessories -> Right-click “Command Prompt” -> Run As Administrator

Otherwise: Start -> Run -> [cmd ] -> [ OK ]

ipconfig /flushdns

It is also possible to clear the cache in Windows byrestartingthe “DNS Client” or “Dnscache” service.

What have we here? As perpart 1, thevertical barindicates that either “lookupd” OR “dscacheutil” are acceptable. Theparenthesisindicate that thevertical baronly applies to the “lookupd|dscacheutil” portion of the expression. Thus, the ” -flushcache” is not optional and must be included in the command in order for it to work. Note that these commands produce no output unless there is an error.

Use dscacheutil if you’re using Mac OS X 10.5 (Leopard) or later.

Mac OS X:

lookupd -flushcache

Mac OS X Leopard:

dscacheutil -flushcache

There is also a GUI tool, DNS Flusher, which automatically uses the correct command available.

Flushing Linux/Unix’ DNS cache, from shell prompt:

N.B.If you don’t already have eitherbind (with caching lookup enabled), nscd, or dnsmasq installed and running on your *nix-based desktop/server, you are probablynot caching DNS at alland there is nothing to flush. In that case you will be utilising your DNS server for every web request, probably slowing your web experience.* If so, I recommend at least installing nscd as it is the easiest to set up. **

Flushing nscd’s cache

As with the Mac OS command, this produces absolutely no output unless there is an error:

(|sudo )(|/usr/sbin/)nscd -i hosts

Usesudoif you’re not alreadyroototherwise the first selection is blank.

Specify /usr/sbin/ if nscd is not already within the “path”. If your distribution has nscd in a strange place, locate it first:

locate -r bin/nscd$

Notice that the above “bin/nscd$” is itself a regular expression. 🙂

Using nscd, invalidate the “hosts” cache, logged in as a user:

sudo nscd -i hosts

Using nscd, invalidate the “hosts” cache, logged in as root:

nscd -i hosts

Using nscd, invalidate the “hosts” cache, logged in as root, specifying the full path:

/usr/sbin/nscd -i hosts

Flushing bind’s cache

To flush bind’s cache, we issue a command viarndc. Use sudo if you are not already root:

Restarting the cacheing services also works!

That’s starting to get difficult to read. *** Luckily I’ve explained in detail:

As with the previous command, use sudo if you’re not already root.

The second selection has the first option “service “. This applies mainly to Red Hat/CentOS and Fedora systems.

The “/etc/(rc\.d|rc\.d/init\.d|init\.d)/” needs to be expanded further. This is for most other systems. Generally, the rc.d is for if you’re using a BSD-style init system (for example: Arch Linux, FreeBSD, or OpenBSD). The best way to know for sure which command to use is to ‘locate’ the correct nscd ordnsmasqpath. Most Unix flavours, even Solaris, use nscd:

locate -r \.d/nscd$ ; locate -r \.d/dnsmasq$ ; locate -r \.d/rndc$

The last choice is between “bind”, “nscd”, and “dnsmasq”. This depends entirely on which is installed and in use.

The last of the pattern, ” restart”, is the instruction given to the daemon’s control script.

Arch, using dnsmasq, restarting the cache daemon, logged in as root:

/etc/rc.d/dnsmasq restart

Arch, using nscd, restarting the cache daemon, logged in as user:

sudo /etc/rc.d/nscd restart

CentOS / Red Hat, using nscd, restarting the daemon, as root:

service nscd restart

Flush Mozilla Firefox’s internal DNS cache:

Mozilla Firefoxkeeps its own DNS cache for performance. Firefox 2 would cache only 20 entries for up to 60 seconds. The default setting as of Firefox 3 appears to be 512 entries for up to 60 minutes which seems much more reasonable for every-day browsing. If your desktop has a built-in cache (which most now do) then the cache here is actually redundant. I’m not aware of any other browsers that implement DNS caching.

I’ve found a few solutions for when you need to clear the cache. It seems there are many ways to do this however these are the easiest, which I’ve put into order of preference.:

Manually do what DNS Cache does: set the following 2 about:configoptions “network.dnsCacheExpiration” and “network.dnsCacheEntries” to 0 and then back to the default.

I had a bad cached record and I cleared my browser’s cache. But its still giving me the wrong info. What gives?

Because of how DNS propagation works, you preferably need to flush the DNS onallDNS hosts between yourself and the “authoritive” host, starting with the host closest to the authoritive host (furthest away from your browser).

As an example, if you have a router that is caching DNS, reset the router’s cache before restarting the DNS cache of your operating system, and onlythenshould you clear the cache in Firefox. The reason is that even if you only clear your OS and Firefox’s caches, your desktop is still going to ask the router for itsbadrecord anyway.

What if my DNS server is a server on the net outside my control?

You could try temporarily using a different nameserver, possibly even a publiclyopenserver. OpenDNS shows some good information on how to do this. If you’d like, you should also be able to get relevant information from your own ISP regarding their resolving DNS servers. A local example (South Africa) isSAIXwhichliststheir resolving DNS servers.

* Likely the reason why Firefox has a DNS cache built-in ****** “((pacman|yaourt) -S|emerge|(yum|aptitude|apt-get) install) nscd” and then ensure that the service is added to the startup scripts. Refer to your distribution’s installation documentation. *** I’m looking for a syntax highlighting plugin that can work with regex**** I’ve read statements that restarting the network(ing|) service also clears the DNS cache however I haven’t seen any evidence that this is true. If anyone has a example where this is true, please provide me with the details.