Friday, August 31, 2012

my vendors don't listen or bulk ms-dns add script

Sigh. I specified that all my DHCP passed-out addresses need to have an A name and a PTR record. Apparently someone wasn't listening, or half-listened, as when I went to do whatever I do, my hosts were showing up sans-name. Oh man. Maybe they got tired typing. There is an easier way to create bulk DNS records.

Let's just say my hosts need this format:

dhcp-101.testorama.vendor.local  10.0.10.101
dhcp-102.testorama.vendor.local  10.0.10.102

Now, vendor.local is my forward lookup zone, and testorama is the domain.

First off, I need an input file with my particulars all separated by commas (csv files are fun).

HOSTNAME,ZONE,IP_ADDRESS

Within my DNS structure, a hostname is the host's name plus domain. Domains can be their own zones... but in my case, this is not so.

For the above a line in my input file called input.txt would look like:

dhcp-101.testorama,vendor.local,10.0.10.101

On the DNS server, or on a host on which you permission to edit DNS entries and have DNS tools installed (for the lovely dnscmd command) issue:

for /f "tokens=1-3 delims=," %a in (input.txt) do dnscmd  /RecordAdd %b %a A %c

to create A records .

Issue:

for /f "tokens=1-3 delims=," %a in (input.txt) do for /f "tokens=1-4 delims=." %e in ("%c") do dnscmd  /RecordAdd %g.%f.%e.in-addr.arpa. %h PTR %a.%b

for PTR records.

For A & PTR record deletions, because you made a mistake, by say, having a digit flip...

for /f "tokens=1-3 delims=," %a in (input.txt) do dnscmd  /RecordDelete %b %a A /f

for /f "tokens=1-3 delims=," %a in (list.txt) do for /f "tokens=1-4 delims=." %e in ("%c") do  do dnscmd  /RecordDelete %g.%f.%e.in-addr.arpa. %h PTR /f
sometimes your dns admins will not have separate zones for various subnets. in the above example, 10.0 is it. to remedy that, just change the variables in your PTR script:

Issue:

for /f "tokens=1-3 delims=," %a in (input.txt) do for /f "tokens=1-4 delims=." %e in ("%c") do dnscmd  /RecordAdd %f.%e.in-addr.arpa. %h PTR %a.%b

No comments: