Are you interested in our Early Access Program (EAP)? This program allows you to preview code, test in your lab and provide feedback prior to General Availability (GA) release of all Infoblox products. If so, please click the link here.

API & Integration, DevOps,NetOps,SecOps

Reply

Adding a PTR record to Infoblox server with a Powershell script

Techie
Posts: 5
3793     0

Hi all,

     new to this forum and fairly new to Infoblox.  Have been getting familiar with all things Infoblox over the last few months after many years as a Mainframe specialist.

 

From eamples I've found in this forum and other places I'm got a Powershell script woirking that adds a Host record to the Infoblox server and the corersponding A record to a Windows 2016 DNS server.

 

I'm now try to get the script to add a PTR record to the Infoblox server as it will manage the reverse zone lookup while the A record will reside on the Win DNS server.

 

My code is below and I'm not sure that I have the data defined correctly for the PTR record as when I run it I get this response from the Infoblox server:

 

Invoke-RestMethod : The remote server returned an error: (400) Bad Request.
At C:\Users\Administrator\documents\powershell scripts\Addhostp.ps1:93 char:24
+ ... $request = Invoke-RestMethod -Uri $uri -Method Post -Body $json -Con ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRe
quest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Com
mands.InvokeRestMethodCommand

 

Any help for a newbie appreciated.

 

    process {
        $apiVersion = 2.10
        $uri = "https://$GridServer/wapi/v$apiVersion/record:ptr"

        if ($PSBoundParameters.ContainsKey('CreateInDNS')) {
            $dns = $true
        } else {
            $dns = $false
        }

# Add the A record to the Windows DNS server

        Add-DnsServerResourceRecordA -Name $HostName -ZoneName $DNSZone -IPv4Address $IPv4Address

        $data = @{
            ipv4addrs = @(
                @{ipv4addr = $IPv4Address}
            )
            ptrdname = $HostName
            comment = $Comment.Trim()
            view = 'default'
            configure_for_dns = $dns
        }
        $json = $data | ConvertTo-Json

# Add the PTR record to the Infoblox server

        if ($PSCmdlet.ShouldProcess($Hostname, 'Add InfoBlox record host')) {
            $request = Invoke-RestMethod -Uri $uri -Method Post -Body $json -ContentType 'application/json' -Credential $Credential
            return $request
        }

    }

Re: Adding a PTR record to Infoblox server with a Powershell script

Adviser
Posts: 179
3794     0

Hi,

 

The body for your PTR record should look something like this.

{
      "name":"2.10.10.10.in-addr.arpa",
      "ptrdname":"server1.info.com",
      "ipv4addr":"10.10.10.2",
      "comment":"Test Comment",
       "view":"default"
}

So, your data variable should look like:

$data =  @{
     name = "2.10.10.10.in-addr.arpa"
     ptrdname = "server1.info.com"
     ipv4addr = "10.10.10.2"
     comment = "Test Comment"
     view = "default"
 }

Hope this helps,

Thanks and Regards,

Krishna

Re: Adding a PTR record to Infoblox server with a Powershell script

Techie
Posts: 5
3794     0

Thaaks very much for your help.  I've got the script working now.

 

Cheers,

 

Frank

Re: Adding a PTR record to Infoblox server with a Powershell script

Guru
Posts: 20
3794     0

Just out of curiousity, why add an A/PTR pair when adding a Host record would do the same thing.

 

Otherwise, when you go to delete the A record, you might leave the PTR as an orphan.

Re: Adding a PTR record to Infoblox server with a Powershell script

Techie
Posts: 5
3794     0

Yes I agree with you that there is a potential for an orphan record as you mention.  However in this case, it was a client requirement, based on their network setup.  In their environment, the A record is in fact held on a Windows sServer DNS server, and the reverse lookup zone on the Infoblox server, which is why only the PTR record was to be added there.

 

Cheers,

 

Frank

Re: Adding a PTR record to Infoblox server with a Powershell script

Guru
Posts: 20
3794     0

OK, great! You said the magic words: “Customer requirement”. I run into a lot of people in my job who have never heard of a host record, and are simply unaware of its role.

Showing results for 
Search instead for 
Did you mean: 

Recommended for You