13.4 An Installation and Configuration Batch Script

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:

  1. Installs the DNS Server service using sysocmgr

  2. Adds a zone called fx.movie.edu using dnscmd

  3. Configures the server to use a forwarder using dnscmd

  4. Adds an A record for the name of the new server in the fx.movie.edu zone on the primary master server using dnscmd

  5. Performs a zone transfer from the primary master server to receive the latest updates using dnscmd

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
:: Forward-mapping zone to add to this server
set FWD_ZONE=fx.movie.edu
:: IP address of this server

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