One of my clients wanted to switch from using his ISP's DNS server to using his own server. He had registered approximately 30 domain names. I developed a way to use the Dnscmd and For commands to add all the primary zones, each with identical, custom properties, in one command. I manually created the zone for the main domain, yourdomain.com, because that domain had many unique records and properties.
I extracted the dnscmd.exe file from the Windows 2000 Service Pack 2 (SP2) \support\tools folder's support.cab file to the new DNS server's \%systemroot%\system32 folder. Next, in the DNS server's \%systemroot%\system32\dns folder, I created the batch file that Listing 1, page 14, shows. This batch file uses the Dnscmd command to create a zone and the associated records and properties.
The code at callout A in Listing 1 creates the primary zone, with %1 representing the zone name. The code at callout B modifies the Start of Authority (SOA) record; the /RecordAdd command simply replaces or writes over the existing SOA record. The code at callout C causes the name servers' Fully Qualified Domain Names (FQDNs) and IP addresses to appear on the zone properties' Name Server tab. The client wanted a host record in all zones for the domain name to point to the Web server's load-balanced IP address; the code at callout D accomplishes this task. The client also wanted the www.zone_name alias to point to the Web server; the code at callout E accomplishes this task. The code at callout F adds a mail server record. Finally, the code at callout G sets the security for zone data transfer to the secondary servers; this command is equivalent to selecting the options Allow zone transfers and Only to servers listed on the Name Servers tab on the zone properties' Zone Transfer tab.
You can open a command prompt, go to \%systemroot%\system32\dns, and enter
for every zone you want to create. Alternatively, you can use the For command to add all the zones with one command. Create a text file such as the one that Listing 2 shows. Place this file in the \%systemroot%\system32\dns folder. Go to a command prompt, and in \%systemroot%\system32\dns, enter
do ZoneAdd %i
to add all the zones in the domain_name_list file. Alternatively, you can run the batch file that Listing 3 shows.
On a secondary name server, you would use the same domain_name_list.txt file. The ZoneAdd.bat file would have only one line:
where 192.168.4.4 is the master DNS server's IP address. You would then run the same For command on the secondary name server to add all the secondary zones.