question

RisingFlight-7863 avatar image
0 Votes"
RisingFlight-7863 asked AndreasBaumgarten commented

Create Reverse DNS records

Hi Experts

i have few servers which dont have reverse dns records.
for example. server1 and server2 have forward lookup records. i.e server1@contoso.com pointing to 192.168.5.20, server2@contoso.com pointing to 192.168.5.21
but these servers dont have reverse dns records.

  1. How do i create reverse DNS records for these servers using powershell.

  2. i have servers list in the below format, how do i import the csv file and create reverse dns records

88791-dnsdns.jpg


windows-server-powershellwindows-dhcp-dns
dnsdns.jpg (14.1 KiB)
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @ RisingFlight-7863 ,

Did the answer work for you? Are there any additional questions to this topic?

If you found the answer helpful, it would be great if you please mark it "Accept as answer". This will help others to find answers in Q&A

----------
Regards
Andreas Baumgarten

0 Votes 0 ·
AndreasBaumgarten avatar image
0 Votes"
AndreasBaumgarten answered AndreasBaumgarten edited

Hi @ RisingFlight-7863 ,

you can give this a try (not tested by myself). Use the script on your own risk.

 $file = "server.csv"
 Import-Csv -Path $file | foreach {
     $name = (($_.IPAddress).Split("."))[3]
     # Modify the -ZoneName to your needs (name of the reverse lookup zone in DNS)
     # Modify the PtrDomainName domain part to your needs (contoso.com)
     Add-DnsServerResourceRecordPtr -Name "$name" -ZoneName "0.168.192.in-addr.arpa" -AllowUpdateAny -TimeToLive 01:00:00 -AgeRecord -PtrDomainName "$_.HostName.contoso.com"
     }


(If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

Regards
Andreas Baumgarten



5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

RisingFlight-7863 avatar image
0 Votes"
RisingFlight-7863 answered AndreasBaumgarten commented

will the below script work for me

95385-i.jpg



 $ServerName = "MyDomainController" 
 $domain = "contoso.com" 
 Import-Csv C:\temp\Records.csv | ForEach-Object { 
 #Def variable 
 $Computer = "$($_.HostName).$domain" 
 $addr = $_.IP -split "\." 
 $rzone = "$($addr[1]).$($addr[0]).in-addr.arpa" 
 #write-host $rzone
 #Create Dns entries 
 dnscmd $Servername /recordadd $domain "$($_.HostName)" A "$($_.IPAddress)" 
 #Create New Reverse Zone if zone already exist, system return a normal error 
 #dnscmd $Servername /zoneadd $rzone /primary 
 #Create reverse DNS 
 dnscmd $Servername /recordadd $rzone "$($addr[3]).$($addr[2])" PTR $HostName
 }

i.jpg (14.0 KiB)
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @RisingFlight-7863 ,

your approach looks like you are using a /16 subnet mask (first 2 octets defining the net and the last 2 octets are for hosts)?

Is there any reason why you are using dnscmd instead of PowerShell cmdlets Add-DnsServerResourceRecordA and Add-DnsServerResourceRecordPtr ?
https://docs.microsoft.com/en-us/powershell/module/dnsserver/add-dnsserverresourcerecorda?view=windowsserver2019-ps
https://docs.microsoft.com/en-us/powershell/module/dnsserver/add-dnsserverresourcerecordptr?view=windowsserver2019-ps

if this is a question you should just give it a try ;-)

will the below script work for me


(If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

Regards
Andreas Baumgarten

0 Votes 0 ·