- Scripting DNS
- Manually Installing DNS Zones Using dnscmd.exe
- Summary
Manually Installing DNS Zones Using dnscmd.exe
Just as you can do a hands-off install of DNS with sysocmgr.exe, you can also script the creation and configuration of DNS zones with dnscmd.exe. This executable is part of the Windows 2000 Support Tools located on the Windows 2000 CD. To install the tools, double-click \support\tools\2000RKST.MSI. This will load the Windows 2000 Support Tools Setup Wizard. This installs several marvelous tools, including dnscmd.exe, the Active Directory Replication Monitor. The unattend.doc mentioned earlier in the chapter is also located in these files but must be manually extracted from the deploy.cab file located in the \support\tools folder of the CD. These tools are not to be confused with the Resource Kit tools, another incredible product with a wealth of documentation and specialized tools.
The dnscmd tool is very well documented in the Tools Help that installs with the Support Tools. We will look at several examples that will allow us to build a working DNS infrastructure from scratch. This tool could be used in conjunction with sysocmgr to create a completely hands-off DNS installation. The basic dnscmd syntax is shown in Listing 1.
Listing 1
DnsCmd <ServerName> <Command> [<Command Parameters>]
The parameters allowed in dnscmd are as varied as DNS itself. We will look at the minimum commands necessary to build a functioning DNS. The following examples assume that you have just finished installing DNS manually through Control Panel or by using sysocmgr. In other words, DNS is installed and running, but no zones have been created.
The first thing we have to do is create a zone. The code in Listing 2 will create a forward lookup zone called fis.local with a zone type of standard primary. Another interesting feature of dnscmd is the capability to represent the local server rather than hard-coding server names in the scripts, allowing the same script to be used on multiple servers.
Listing 2
dnscmd . /zoneadd fis.local /primary
Next you can install a reverse lookup zone by using the same command with different parameters. The code in Listing 3 creates a reverse lookup zone on the local server based on the 192.168.0.0 network address of zone type standard primary.
Listing 3
dnscmd . /zoneadd 0.168.192.in-addr.arpa /primary
After you have created the zones, you may want to configure them without having to use the DNS MMC snap-in. To configure zone fis.local created in Listing 2 to allow updates, execute the code in Listing 4.
Listing 4
dnscmd . /config mcp.local /AllowUpdate 1
Finally, to allow updates to the reverse lookup zone created in Listing 3, execute the code in Listing 5.
Listing 5
dnscmd . /config 0.168.192.in-addr.arpa /AllowUpdate 1
To get help with command-line syntax, you can execute dnscmd without any parameters, and it will fill the screen with online help, as shown in Listing 6.
Listing 6
USAGE: DnsCmd <ServerName> <Command> [<Command Parameters>] <ServerName>: . -- local machine using LPC IP address -- RPC over TCP/IP DNS name -- RPC over TCP/IP other server name -- RPC over named pipes <Command>: /Info -- Get server information /Config -- Reset server or zone configuration /EnumZones -- Enumerate zones /Statistics -- Query/clear server statistics data /ClearCache -- Clear DNS server cache /WriteBackFiles -- Write back all zone or root-hint datafile(s) /StartScavenging -- Initiates server scavenging /ResetListenAddresses -- Select server IP address(es) to serve DNS requests /ResetForwarders -- Set DNS servers to forward recursive queries to /ZoneInfo -- View zone information /ZoneAdd -- Create a new zone on the DNS server /ZoneDelete -- Delete a zone from DNS server or DS /ZonePause -- Pause a zone /ZoneResume -- Resume a zone /ZoneReload -- Reload zone from its database (file or DS) /ZoneWriteBack -- Write back zone to file /ZoneRefresh -- Force refresh of secondary zone from master /ZoneUpdateFromDs -- Update a DS integrated zone by data from DS /ZoneResetType -- Change zone type Primary/Secondary/DSintegrated /ZoneResetSecondaries -- Reset secondary\notify information for a zone /ZoneResetScavengeServers-- Reset scavenging servers for a zone /ZoneResetMasters -- Reset secondary zone's master servers /EnumRecords -- Enumerate records at a name /RecordAdd -- Create a record in zone or RootHints /RecordDelete -- Delete a record from zone, RootHints or Cache data /NodeDelete -- Delete all records at a name /AgeAllRecords -- Force aging on node(s) in zone <Command Parameters>: -- parameters specific to each Command dnscmd <CommandName> /? -- For help info on specific Command
Notice the last line of Listing 6. If you need more specific help with syntax for a command, you can type the specific command with a /? to get help with exactly that command. The code in Listing 7 shows the output from using this help feature.
Listing 7
dnscmd /zoneadd /? USAGE: DnsCmd <ServerName> /ZoneAdd <ZoneName> <ZoneType> [<Options>] <ZoneName> -- FQDN of zone <ZoneType>: /Primary /file <filename> -- standard file backed primary; MUST include filename. /Secondary <MasterIPaddress> [<MasterIPaddress>] ..] [/file <filename>] -- standard secondary, MUST include at least one master IP; filename is optional. /DsPrimary -- DS integrated primary zone <Options>: [/file <filename>] -- filename, invalid for DsPrimary [/load] -- load existing file; if not specified, non-DS primary creates default zone records [/a <AdminName>] -- zone admin email name; primary zones only Command completed successfully.