Recipe 12.6. Registering DNS Records or Flushing the DN Cache


Problem

You want to register a system's DNS records dynamically or flush the local DNS cache.

Solution

Using a command-line interface

The following command displays the contents of the local DNS cache:

> ipconfig /displaydns

And this clears that cache:

> ipconfig /flushdns

The following command causes the local host to re-register its DNS records via dynamic DNS:

> ipconfig /registerdns

Using VBScript
' This code flushes the local DNS cache.  There are no scripting ' interfaces designed to do this so I have to shell out and run ' the ipconfig /flushdns command. strCommand = "ipconfig /flushdns" set objWshShell = WScript.CreateObject("WScript.Shell") intRC = objWshShell.Run(strCommand, 0, TRUE) if intRC <> 0 then    WScript.Echo "Error returned from running the command: " & intRC else    WScript.Echo "Command executed successfully" end if ' This code registers DNS records for the local host.  There are  ' no scripting interfaces designed to do this so I have to shell  ' out and run the ipconfig /registerhdns command. strCommand = "ipconfig /registerdns" set objWshShell = WScript.CreateObject("WScript.Shell") intRC = objWshShell.Run(strCommand, 0, TRUE) if intRC <> 0 then    WScript.Echo "Error returned from running the command: " & intRC else    WScript.Echo "Command executed successfully" end if

Discussion

The Windows operating system maintains a name resolution cache of DNS records that the system has queried. This cache is maintained in memory and speeds up future requests for the same record. Each record has an associated time-to-live value. This setting informs clients of the maximum amount of time to cache that particular record. After the time-to-live period expires, Windows removes the record from its cache.

The Windows name resolution cache is maintained by the DNS Cache (DnsCache) service. You can prevent records from being cached by stopping this service (and disabling it if you never want records to be cached again). If you are getting strange results when querying DNS, you may want to view the local DNS cache just to see if you are accessing locally cached records instead of what is current on the DNS Server.

The /registerdns option of ipconfig attempts to dynamically re-register DNS records for all IP addresses configured on the system. The DHCP Client (Dhcp) service does the DNS re-registration, so if that service is disabled, the /registerdns option won't work (even if all addresses are statically configured).

See Also

MS KB 245437, "How to Disable Client-Side DNS Caching in Windows," MS KB 264539, "Dynamic DNS Updates Do Not Work if the DHCP Client Service Stops," and MS KB 318803, "How to Disable Client-Side DNS Caching in Windows XP and Windows Server 2003"



Windows XP Cookbook
Windows XP Cookbook (Cookbooks)
ISBN: 0596007256
EAN: 2147483647
Year: 2006
Pages: 408

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