Registering DNS Records or Flushing the DNS Cache

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 reregister 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

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 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 reregister DNS records for all IP addresses configured on the system. The DHCP Client (Dhcp) service does the DNS reregistration, so if that service is disabled, the /registerdns option won’t work (even if all addresses are statically configured).