Creating DNS records at the command line

by Ed Fisher on 2008-08-12

in Infrastructure

Given a number of records that need to be added to DNS, we can create a file with the necessary information, and then run a cmd to read the data in the file and create the necessary records in DNS. The following assumes that all records are to be created in the same zone.

  1. Create a CSV file with no header. The three columns should include only the following…
    NodeName,RRType, RRData

    For example, if you wanted to create an A record for server1 at 1.2.3.4, and a CNAME for fp1 that resolves to the FQDN server1.example.com, your file would look like this…

    server1,A,1.2.3.4
    fp1,CNAME,server1.example.com

  2. The following command line will do the trick. If using Vista or 2008, run this from an Administrative cmd prompt.

    for /f “tokens=1-3 delims=,” %G IN (list.txt) do dnscmd serverfqdn /recordadd zonefqdn %G %H %I

To break this down, “tokens=1-3″ means to use all three columns.
“Delims=,” just means that the delimiting character in the file is a comma.
“%G” sets the first variable…you could have used any letter or number you want as long as you stay in order for the rest.
“list.txt” is of course the name of the CSV file you are going to use.
do dnscmd serverfqdn /recordadd zonefqdn %G %H %I executes the command against the DNS server serverfqdn (you could use the ip.addr)
“zonefqdn” means to use the zone’s fqdn, eg. example.com

If you have multiple zones you wish to manage in one file, make the first column zonefqdn, and add %J at the end of the cmd-line.

Hopefully this will help someone else out…if not, I expect I will need to refer to this again many times over the next few months!

You might also enjoy:

  1. Creating DHCP reservations at the command line
  2. howto://Use SPF records to combat domain spoofing
  3. Creating an ISO in ESX from a mounted CD/DVD
  4. net user command reference and examples

{ 1 comment… read it below or add one }

Anonymous 2009-02-18 at 08:02

Leave a Comment

Previous post:

Next post: