Now that we've covered the DNS installation and configuration commands, we'll show you a short batch script that automates the initial setup of a secondary name server. This script performs the following tasks:
The only other utility used in the script is the sleep command, which is available in the Resource Kit. The sleep command is used to allow time for the changes initiated by each command to be committed.
Here is the script:
@echo off :: IP address of primary master server set PRIMARY_MASTER_IP=22.214.171.124 :: Forward-mapping zone to add to this server set FWD_ZONE=fx.movie.edu :: IP address of this server set SERVER_IP=10.50.23.7 echo Installing the DNS Server service . . . sysocmgr /i:%windir%\inf\sysoc.inf /u:c:\dns_install.txt :: The sleep command is part of the Resource Kit sleep 5 echo Adding a zone . . . dnscmd /zoneadd %FWD_ZONE% /Secondary %PRIMARY_MASTER_IP% sleep 5 echo Configuring this server to use a forwarder . . . dnscmd /resetforwarders %PRIMARY_MASTER_IP% sleep 5 echo Adding an A record for this server in %FWD_ZONE% dnscmd %PRIMARY_IP% /recordadd %FWD_ZONE% %COMPUTERNAME% A %SERVER_IP% sleep 5 echo Performing a zone transfer dnscmd /zonerefresh %FWD_ZONE% echo Done
As you can see, the script isn't terribly complex. The @echo off line turns off printing of each command as it is run. You may want to comment this out if you need to debug the script. Commented lines in batch scripts are designated by :: at the beginning of the line.
The rest of the code runs the commands to perform the steps we outlined earlier. We used the set command to initialize some variables that we use throughout the script. The echo command was used to print some status messages. The output from each command is also displayed.
This example script may not be applicable in your environment, but it should give you an idea of how easy it is to create simple batch scripts to automate the installation and configuration of your name servers. If you're interested in learning more about using scripts to manage DNS, see Chapter 14.