Recipe13.14.Clearing the DNS Cache


Recipe 13.14. Clearing the DNS Cache

Problem

You want to clear the DNS cache. The DNS cache contains resource records that are cached for a period of time in memory so that repeated requests for the same record can be returned quickly. There are two types of DNS cache. One pertains to the resolver on any Windows client (servers and workstations), and the other to the cache used by DNS Server. Clearing the cache is useful after you've made a change to DNS and you want the client resolver or DNS Server not to use the previously cached entry.

Solution

To flush the client resolver cache, use the following command:

> ipconfig /flushdns

To flush the DNS Server cache, use any of the following solutions:

Using a graphical user interface

  1. From the Administrative Tools, open the DNS snap-in (dnsmgmt.msc).

  2. Connect to the DNS Server you want to modify. In the left pane, right-click on DNS and select Connect to DNS Server. Select The following computer and enter the target server name. Click OK.

  3. Right-click on the server and select Clear Cache.

Using a command-line interface

The following command clears the server cache:

> dnscmd <ServerName> /clearcache

Using VBScript
' This code clears the DNS Server cache. ' ------ SCRIPT CONFIGURATION ------ strServer = "<ServerName>"   ' e.g., dc1.rallencorp.com ' ------ END CONFIGURATION ---------     set objDNS = GetObject("winmgmts:\\" & strServer & "\root\MicrosoftDNS") set objDNSServer = objDNS.Get("MicrosoftDNS_Server.Name="".""") set objDNSCache  = objDNS.Get("MicrosoftDNS_Cache.ContainerName=""..Cache""" & _                               ",DnsServerName=""" & objDNSServer.Name & _                               """,Name=""..Cache""") objDNSCache.ClearCache WScript.Echo "Cleared server cache"

Discussion

The client resolver cache is populated whenever you perform a lookup on a workstation or server: for example, with the nslookup command. You can view this cache by running ipconfig /displaydns from a command line. This cache is maintained by the DNS Client service (dnscache), so another way of flushing the cache is to restart that service.

The second type of cache is only for DNS Servers. It contains a copy of records the DNS Server has sent to clients when resolving queries. You can view this cache by browsing the Cached Lookups folder for a server in the DNS snap-in. This folder is not shown by default, so you'll need to select Advanced from the View menu.

With both the client and server cache, the records are removed from the cache after the record's Time To Live (TTL) value expires. The TTL is used to age records so that clients and servers have to rerequest them at a later point and receive any changes that may have been made.



Windows Server Cookbook
Windows Server Cookbook for Windows Server 2003 and Windows 2000
ISBN: 0596006330
EAN: 2147483647
Year: 2006
Pages: 380
Authors: Robbie Allen

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net