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 = test.org
(same as parent)          Mail Exchanger (MX)     [10] mymailserver.test.org

So you want an MX record for test.org that sends traffic to mymailserver.test.org

The DNSCMD to do this would be:
DNSCMD mydnsserver.test.org /RecordAdd test.org @ MX 10 mymailserver.test.org

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 = test.org
hq                              Mail Exchanger (MX)    [10] myhqmailserver.test.org


You want mail sent to hq.test.org to be handled by myhqmailserver.test.org

The DNSCMD to do this would be:
DNSCMD mydnsserver.test.org /RecordAdd test.org hq MX 10 mymailserver.test.org

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 sql1.test.org and want to give it a cname of bigserver.test.org, here is the DNSCMD to do that:
dnscmd mydnsserver.test.org /RecordAdd test.org sql1 CNAME bigserver.test.org

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

2 comments:

cdw2000 said...

Very useful blog. Do you plan to continue blogging?

Amy said...

Yes--i need to continue blogging this stuff. It helps me remember what the heck I figured out at work.

But as I'm sure you know, the busier you get, the harder it is to carve off the time to documment (blog) the things you figured out. and worse, this bites you later when you have to recreate the wheel of discovery because you forgot to write it all down the first time and then it happens again. And you have to figure it out again.

But the bottom line is that I really need to start posting more regularly here....