Archive | DNS RSS for this section

iSiek’s forum has been launched

 

I would like to announce you that iSiek’s forum about Microsoft Windows services has been launched!

iSiek's forum

iSiek’s forum

I hope you would participate in building new IT community on this forum. I hope we would be able to help each other.

You are invited! I encourage you to register your account for free and start posting your issues or try to help others.

Just some simple forum’s rules

  1. Forum is free of charge. It is maintained from ads.
  2. To contribute in community, free registration is required
  3. Write posts in English
  4. Check forums if similar problem does not exist
  5. Use appropriate forum to post issue
  6. Do not spam
  7. Use external services to attach images/logs and place only link to them
  8. Be polite and do not use vulgarism
  9. If you do not want to help, do not answer

Be a part of this new community and make family atmosphere here.

I hope we will make this IT world better!

Forum address is http://kpytko.pl/forum

Author: Krzysztof Pytko

DNS bulk PTR records creation

 

My previous article was about bulk DNS records creation in forward lookup zone. This time we will focus on the same activity but in reverse lookup zone. In my opinion this kind of task is much more frequently used that the previous on. You may ask, why? Because in regular basis when you create host (A) record in forward lookup zone you don’t care about pointer (PTR) record in reverse lookup zone. This may happen due to 3 scenarios:

  • You really don’t need PTR record(s) ūüôā
  • You have not checked “Create associated pointer (PTR) record” when adding host record

Option for pointer (PTR) record auto creation

  • ¬†You have checked above option but DNS reverse lookup zone does not exist

Reverse lookup zone does not exist

So, one of these cases may lead you to bulk PTR records creation in the future when you realize that you need this kind of record(s). I will try to simply show you, how to do that very quickly using the least administrative effort because using DNS Management console is not very convenient and fast method (you need to create each records separately by hand).

I will show you how to do that using simple scripts based on:

  • Windows DNScmd command
  • Using DNSShell module for Windows PowerShell (really great module)
  • Using native DNS cmd-lets in PowerShell 3.0

Windows DNScmd command is by default available on Windows Server 2008/2008R2 server where DNS role has been installed. To use it on Windows Server 2003, you need to install Support Tools from server’s CD#1

DNSShell module needs to be downloaded separately from Chris blog who is REAL genius in DNS topic. His module for PowerShell is really great and very helpful.

Windows PowerShell 3.0 DNS cmd-lets are available in Windows 8 and Windows Server 2012 and are new feature added by Microsoft to manage DNS server.

PowerShell 3.0 can be also installed on Windows 7/2008/2008R2 for more information about that, please check my another article “Windows Management Framework 3.0 for Windows Server¬†2008/2008R2”

DNScmd

Before we start preparing script for bulk DNS records creation, let’s check if appropriate reverse lookup zone(s) exist(s). This is mandatory to have reverse lookup zone existing in other case PTR (pointer) records won’t be created! When zone does not exist, you need to create it first before you can start using script for bulk records creation.

After we verified zone existence we can start to creating records. But before that¬†let’s see how DNScmd syntax looks for single pointer (PTR) record. After that we would know which parameters should be inserted into input file for the script.

Note! To get help for DNScmd command you need to specify /? after its name or after any switch you want to get information

Now, we will prepare proper syntax to add single pointer (PTR) record into DNS zone. For that we need to know:

  • DNS server name
  • DNS zone name (reverse lookup zone name)
  • IP address
  • host name

proper syntax to create pointer (PTR) record is:

dnscmd ServerName /RecordAdd DNSReverseZoneName IPAddress RecordType FQDNHostName
 

Below you can find an example syntax

dnscmd %LOGONSERVER% /RecordAdd 1.168.192.in-addr.arpa 100 PTR testHost.testenv.local

DNScmd command execution

instead of %LOGONSERVER% system variable, you can use DNS server name (if all  your DCs are DNS servers too, you can sinply use %LOGONSERVER%, in other case, you need to type DNS server name manually)

As you can see in DNS Management console, new record has been created

DNS record verification

We have complete syntax and now, we can create a script to create many DNS records in short time. First of all, we need an input file containing all required data. To create that file we need put in a flat text file 2 or 3 values:

  • an octet of IP Address for which we want to add PTR record
  • host Fully-Qualified Domain Name
  • optionally reverse lookup zone name (if we want to create PTR records for multiple zones)

An example input file for script (2 values and the same zone)

100 testHost01.testenv.local
101 testHost02.testenv.local
102 testHost03.testenv.local
103 testHost04.testenv.local
104 testHost05.testenv.local

of example input file with 3 values

105 testHost06.testenv.local 1.168.192.in-addr.arpa
106 testHost07.testenv.local 1.168.192.in-addr.arpa
107 testHost08.testenv.local 2.168.192.in-addr.arpa
108 testHost09.testenv.local 2.168.192.in-addr.arpa
109 testHost10.testenv.local 3.168.192.in-addr.arpa

and save this as i.e. newPTR.txt on C-Drive

Now, you can use below script to create many DNS records (case with 2 values in file)

for /f "tokens=1-2" %i in (c:newPTR.txt) do dnscmd %LOGONSERVER% /RecordAdd 1.168.192.in-addr.arpa %i PTR %j

Bulk DNS pointer records created

and you can verify that in DNS Management console

DNS records verification

and now, code for the case with 3 values in file

for /f "tokens=1-3" %i in (c:newPTR.txt) do dnscmd %LOGONSERVER% /RecordAdd %k %i PTR %j

Bulk DNS records created

and you can verify that in DNS Management console once again

DNS records verification

DNSShell module for PowerShell

As I mentioned at the beginning of this article, this is separate module which needs to be downloaded. You can simply download it from

http://www.indented.co.uk/index.php/2010/04/16/dnsshell-zone-and-server-cmdlets/

When you download it, you have to extract content into one of the following locations:

  • %HOMEPATH%DocumentsWindowsPowerShellModules
  • %WINDIR%SYSTEM32WindowsPowerShellv1.0Modules

PowerShell modules path

and import this module before the first use

Import-Module DNSShell

to list all available cmd-lets use

help *DNS*

Importing DNSShell module and list all available cmd-lets

From now, you have all cmd-lets available. Let’s start to create single host record in DNS using New-DNSRecord cmd-let

To be able to create pointer (PTR) record using DNSShell, you need:

  • DNS zone name (reverse lookup zone name)
  • an octet of IP Address for which we want to add PTR record
  • host name

You will find general syntax below

New-DNSRecord -Name AnOctet -RecordType PTR -ZoneName ReverseZoneName -HostName HostFQDN

and short example

New-DNSRecord -Name 100 -RecordType PTR -ZoneName 1.168.192.in-addr.arpa -HostName testHost01.testenv.local

New-DNSRecord example

and you can see command’s result in DNS Manager

DNS record veryfying

So, now we can create a script to automatically create many DNS records. As for PowerShell is better to use CSV file format instead of flat text file, I would suggest to prepare an example here. CSV file requires a header for each attribute, we need 2 or 3 attributes to accomplish that.

An example CSV file for 2 values

octet,hostName
100,testHost01.testenv.local
101,testHost02.testenv.local
102,testHost03.testenv.local
103,testHost04.testenv.local
104,testHost05.testenv.local

An example CSV file for 3 values

octet,hostName,zoneName
105,testHost06.testenv.local,1.168.192.in-addr.arpa
106,testHost07.testenv.local,1.168.192.in-addr.arpa
107,testHost08.testenv.local,2.168.192.in-addr.arpa
108,testHost09.testenv.local,2.168.192.in-addr.arpa
109,testHost10.testenv.local,3.168.192.in-addr.arpa

Save this file as newPTR.csv on C-Drive and use below script to create DNS records

for 2 values

Import-Module DNSShell
Import-CSV c:newPTR.csv | %{
New-DNSRecord -Name $_."octet" -RecordType PTR -ZoneName 1.168.192.in-addr.arpa -HostName $_."hostName"
}

PowerShell script

and verify results in DNS Manager

DNS records veryfying

and one more case with 3 values in CSV file

Import-Module DNSShell
Import-CSV c:newPTR.csv | %{
New-DNSRecord -Name $_."octet" -RecordType PTR -ZoneName $_."zoneName" -HostName $_."hostName"
}

PowerShell code

and verify in DNS Manager if they were created

DNS records verifying

Native DNS cmd-lets in PowerShell 3.0

This is new feature and can be only used with PowerShell 3.0 which is available in Windows 8 and Windows Server 2012 (or in other Windows versions as it was mentioned at the beginning of this article). There are variety of DNS cmd-lets to manage DNS server and one of  them is Add-DNSServerResourceRecordPTR and we will use it in this article.

Add-DNSServerResourceRecordPTR cmd-let

To create pointer (PTR) record using this cmd-let you need:

  • DNS zone name (reverse lookup zone name)
  • an octet of IP Address for which we want to add PTR record
  • host name

And now for a practice, we will create single DNS record using Add-DNSServerResourceRecordPTR

Add-DNSServerResourceRecordPTR -ZoneName DNSReverseZoneName -Name octet -PTRDomainName hostName

according to above general syntax, let’s create pointer record

Add-DNSServerResourceRecordPTR -ZoneName 1.168.192.in-addr.arpa -Name 100 -PTRDomainName testHost01.testenv.local

PowerShell 3.0 DNS record creation

and as in previous methods, just verify  if DNS record was created

DNS record verification

So, now the last part. We need to prepare script for multiple records creation. As we would need to use CSV file as in previous method (DNSShell module for Windows PowerShell), we will reuse it. An example CSV file is below

for 2 values

octet,hostName
100,testHost01.testenv.local
101,testHost02.testenv.local
102,testHost03.testenv.local
103,testHost04.testenv.local
104,testHost05.testenv.local

and for 3 values

octet,hostName,zoneName
105,testHost06.testenv.local,1.168.192.in-addr.arpa
106,testHost07.testenv.local,1.168.192.in-addr.arpa
107,testHost08.testenv.local,2.168.192.in-addr.arpa
108,testHost09.testenv.local,2.168.192.in-addr.arpa
109,testHost10.testenv.local,3.168.192.in-addr.arpa

and save this as newPTR.csv file on C-Drive. When you do that, use below code for pointer (PTR) records creation

PowerShell 3.0 code for CSV with 2 values

Import-CSV c:newPTR.csv | %{
Add-DNSServerResourceRecordPTR -ZoneName 1.168.192.in-addr.arpa -Name $_."octet "-PTRDomainName $_."hostName"
}

PowerShell 3.0 code

and DNS Manager view to prove that record were created

DNS Manager and newly created DNS records

and the last part with PowerShell 3.0 for DNS, code for CSV file with 3 values

Import-CSV c:newPTR.csv | %{
Add-DNSServerResourceRecordPTR -ZoneName $_."zoneName" -Name $_."octet "-PTRDomainName $_."hostName"
}

just to be sure if records were created, let’s check each reverse lookup zone to verify that

DNS Manager and newly created DNS records

That’s all!

<<< Previous part

Author: Krzysztof Pytko

DNS bulk host (A) records creation

 

Sometimes we need to create many DNS records in a short time. Using DNS Management console is not very convenient and fast method because you need to create each records separately by hand. I will show you how to do that using simple scripts based on:

  • Windows DNScmd command
  • Using DNSShell module for Windows PowerShell (really great module)
  • Using native DNS cmd-lets in PowerShell 3.0

Windows DNScmd command is by default available on Windows Server 2008/2008R2 server where DNS role has been installed. To use it on Windows Server 2003, you need to install Support Tools from server’s CD#1

DNSShell module needs to be downloaded separately from Chris blog who is REAL genius in DNS topic. His module for PowerShell is really great and very helpful.

Windows PowerShell 3.0 DNS cmd-lets are available in Windows 8 and Windows Server 2012 and are new feature added by Microsoft to manage DNS server.

PowerShell 3.0 can be also installed on Windows 7/2008/2008R2 for more information about that, please check my another article “Windows Management Framework 3.0 for Windows Server¬†2008/2008R2”

DNScmd

Before we start preparing script for bulk DNS records creation, let’s see how DNScmd syntax looks for single host (A) record. After that we would know which parameters should be inserted into input file for the script.

Note! To get help for DNScmd command you need to specify /? after its name or after any switch you want to get information

Now, we will prepare proper syntax to add single host (A) record into DNS zone. For that we need to know:

  • DNS server name
  • DNS zone name
  • host name
  • IP address

proper syntax to create host (A) record is:

dnscmd ServerName /RecordAdd DNSZoneName HostName RecordType IPAddress

Below you can find an example syntax

dnscmd %LOGONSERVER% /RecordAdd testenv.local test01 A 192.168.1.101

DNScmd command execution

instead of %LOGONSERVER% system variable, you can use DNS server name (if all  your DCs are DNS servers too, you can sinply use %LOGONSERVER%, in other case, you need to type DNS server name manually)

As you can see in DNS Management console, new record has been created

DNS record verification

We have complete syntax and now, we can create a script to create many DNS records in short time. First of all, we need an input file containing all required data. To create that file we need put in a flat text file 2 values:

  • host name
  • IP address

An example input file for script

test01 192.168.1.101
test02 192.168.1.102
test03 192.168.1.103
test04 192.168.1.104
test05 192.168.1.105

and save this as i.e. newHosts.txt on C-Drive

Now, you can use below script to create many DNS records

for /f "tokens=1-2" %i in (c:newHosts.txt) do dnscmd %LOGONSERVER% /RecordAdd testenv.local %i A %j

Bulk DNS host records created

and you can verify that in DNS Management console

DNS records verification

DNSShell module for PowerShell

As I mentioned at the beginning of this article, this is separate module which needs to be downloaded. You can simply download it from

http://www.indented.co.uk/index.php/2010/04/16/dnsshell-zone-and-server-cmdlets/

When you download it, you have to extract content into one of the following locations:

  • %HOMEPATH%DocumentsWindowsPowerShellModules
  • %WINDIR%SYSTEM32WindowsPowerShellv1.0Modules

PowerShell modules path

and import this module before the first use

Import-Module DNSShell

to list all available cmd-lets use

help *DNS*

Importing DNSShell module and list all available cmd-lets

From now, you have all cmd-lets available. Let’s start to create single host record in DNS using New-DNSRecord cmd-let

To be able to create host (A) record using DNSShell, you need:

  • DNS zone name
  • host name
  • IP address

You will find general syntax below

New-DNSRecord -Name HostName -RecordType A -ZoneName DNSZoneName -IPAddress IPAddress

and short example

New-DNSRecord -Name test01 -RecordType A -ZoneName testenv.local -IPAddress 192.168.1.101

New-DNSRecord example

and you can see command’s result in DNS Manager

DNS record veryfying

So, now we can create a script to automatically create many DNS records. As for PowerShell is better to use CSV file format instead of flat text file, I would suggest to prepare an example here. CSV file requires a header for each attribute, we need only 2 attributes to accomplish that

HostName,IPAddr
 test01,192.168.1.101
 test02,192.168.1.102
 test03,192.168.1.103
 test04,192.168.1.104
 test05,192.168.1.105

Save this file as newHosts.csv on C-Drive and use below script to create DNS records

Import-Module DNSShell
Import-CSV c:newHosts.csv | %{
New-DNSRecord -Name $_."HostName" -RecordType A -ZoneName testenv.local -IPAddress $_."IPAddr"
}

PowerShell script

and verify results in DNS Manager

DNS records veryfying

Native DNS cmd-lets in PowerShell 3.0

This is new feature and can be only used with PowerShell 3.0 which is available in Windows 8 and Windows Server 2012. There are variety of DNS cmd-lets to manage DNS server and one of  them is Add-DNSServerResourceRecordA and we will use it in this article.

Add-DNSServerResourceRecordA cmd-let

To create host record using this cmd-let we need to have prepared:

  • DNS zone name
  • host name
  • IP address

And now for a practice, we will create single DNS record using Add-DNSServerResourceRecordA

Add-DNSServerResourceRecordA -ZoneName DNSZoneName -Name HostName -IPv4Address IPAddress

according to above general syntax, let’s create host record

Add-DNSServerResourceRecordA -ZoneName testenv.local -Name test01 -IPv4Address 192.168.1.101

PowerShell 3.0 DNS record creation

and as in previous methods, just verify  if DNS record was created

DNS record verification

So, now the last part. We need to prepare script for multiple records creation. As we would need to use CSV file as in previous method (DNSShell module for Windows PowerShell), we will reuse it. An example CSV file is below

HostName,IPAddress
test01,192.168.1.101
test02,192.168.1.102
test03,192.168.1.103
test04,192.168.1.104
test05,192.168.1.105

and save this as newHosts.csv file on C-Drive. When you do that, use below code for host (A) records creation

Import-CSV c:newHosts.csv | %{
 Add-DNSServerResourceRecordA -ZoneName testenv.local -Name $_."HostName" -IPv4Address $_."IPAddress"
 }

Script output

and DNS Manager view to prove that record were created

DNS Manager and newly created DNS records

This time, that’s all!

Next part >>>

Author: Krzysztof Pytko