10.6. Registering DNS Records or Flushing the DNS Cache

Problem

You want to register a server'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 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

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

Get Windows Server Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.