ProblemYou want to register a system's DNS records dynamically or flush the local DNS cache. SolutionUsing a command-line interfaceThe 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 DiscussionThe 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 AlsoMS 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" |