Friday, February 26, 2010

DNS, DNSCMD and Junk like that

I like to use DNSCMD to slam in a lot of DNS records (in bulk) when we're tearing down or moving zones around. I generally use a batch file wrapper around it, to parse a text file with my DNS record information, like host names and IPs.

Today, I had the challenge of taking a little over a hundred host, MX, and CName records and shoving them into a new setup. And I had the devil of a time getting the syntax right.

Looked all over the web and really didn't find that much info that was helpful to me, particularly with the CName and MX records. Loads out there about Host "A" records, though.
Here is Microsoft's idea of help with DNSCMD:

dnscmd [ServerName] /recordadd ZoneName NodeName RRType RRData

Adding MX Records with DNSCMD
This was much trickier than I expected. I ended up with two forms of the command.
Form 1 (Same as Parent)
You use this when the the name for the mail handler is the same as the zone name.  If you look in your DNS console, you'd see this represented as:
DNS Zone =
(same as parent)          Mail Exchanger (MX)     [10]

So you want an MX record for that sends traffic to

The DNSCMD to do this would be:
DNSCMD /RecordAdd @ MX 10

The command is color coded so you can see how it all lines up with the information in DNS.

Form 2
You use this form when the name for the mail handler is different from the zone name. If you look in your DNS console, you'd see this represented as:
DNS Zone =
hq                              Mail Exchanger (MX)    [10]

You want mail sent to to be handled by

The DNSCMD to do this would be:
DNSCMD /RecordAdd hq MX 10

Again, it's color coded so you can see how the elements align. Assuming you can see the colors. :-)

Adding a CName record
In some ways, this is easier to understand than the MX. You have an alias for another server that you want to poke into DNS.
Again, you have your three elements, those being: the zone where your server lives, the name of the server, and the alias/cname you want to assign it.

Let's say you have and want to give it a cname of, here is the DNSCMD to do that:
dnscmd /RecordAdd sql1 CNAME

It's color coded, too.
Hope this made some sort of sense.
That's it for now. Have a great evening.