Forum Discussion

Matt_100070's avatar
Matt_100070
Icon for Nimbostratus rankNimbostratus
Oct 20, 2011

Management ViewZone and PTR records

This might be a dumb question but I've been racking my head on it for the majority of the afternoon and being a newbie to powershell I wanted to ask what the best way was to use the add_ptr() method? I was trying to instantiate an item of the ViewZone type like:

 

 

 

[$iControl.ManagementViewZone]$viewzones = (Get-F5.iControl).ManagementViewZone

 

but everytime I go to assign the view_names or the zone names it fails. Sorry if this is lacking any details, I've read over the documentation on the api page but I can't seem to get it to work. Can someone give me some advice?

 

1 Reply

  • Alright, so after working on this for a while, I think I got this to the point that it works. It doesn't look pretty, and I might not have everything quite right, but the below script creates a zone and a set of PTRs for reverse dns, in the same zone. I also developed a script to obtain the list of dns records of a given viewzone.

     

     

    add zone and resource records

     

    add-pssnapin iControlSnapin

     

    $ic = Initialize-f5.icontrol -hostname F5DEVICE -Credentials (Get-Credential)

     

     

    initialize static values

     

    $TTL = "7200"

     

    $PTRTTL = "86400"

     

    $REFRESH = "10800"

     

    $NSRECORD = "IN NS"

     

    $PTRRECORD = "IN PTR"

     

    $SOARECORD = "IN SOA"

     

    $EXPIRE = "604800"

     

    $NEGATIVETTL = "8640"

     

    $RETRY = "3600"

     

    $INADDR = ".in-addr.arpa."

     

    serial number value needs to be built, we'll use the current datetime value and build a serial based off of that

     

    $a = Get-Date

     

    [string]$SERIAL = [string]$year + [string]$month + [string]$day + [string]$hour

     

    [string]$hostmaster = "hostmaster"

     

    [string]$domain = ".subdomain.domain.com."

     

    [string[]]$nameservers = @("nameserver01", "nameserver02")

     

     

    build raw record objects

     

    [string[]] $ips = @()

     

    [string] $octet1 = Read-Host "First Octet"

     

    [string] $octet2 = Read-Host "Second Octet"

     

    [string] $octet3 = Read-Host "Third Octet"

     

    [string]$reverseip = $octet3 + "." + $octet2 + "." + $octet1

     

     

    build raw record objects

     

    $record1 += $reverseip + $INADDR + " " + $TTL + " " + $NSRECORD + " " + $nameservers[0] + $domain

     

    $record2 += $reverseip + $INADDR + " " + $TTL + " " + $SOARECORD + " " + $nameservers[1] + $domain + " " + $hostmaster + $domain + " " + $SERIAL + " " + $REFRESH + " " + $RETRY + " " + $EXPIRE + " " + $NEGATIVETTL

     

    $record3 += $reverseip + $INADDR + " " + $TTL + " " + $SOARECORD + " " + $nameservers[2] + $domain + " " + $hostmaster + $domain + " " + $SERIAL + " " + $REFRESH + " " + $RETRY + " " + $EXPIRE + " " + $NEGATIVETTL

     

     

    note each entry in the records object is a separate record, so the $records array must have at least two objects in it!!!

     

    [string[]]$standard1 = $record2, $record1

     

    [string[]]$standard2 = $record1, $record2, $record3

     

     

    build all the ptr records (255 of them)

     

    for ($i =0; $i -lt 256; $i++)

     

    {

     

    [string]$value = [string]$i + "." + $reverseip + $INADDR + " " + $PTRTTL + " " + $PTRRECORD + " host-" + $octet1 + "-" + $octet2 + "-" + $octet3 + "-" + $i + ".ptr" + $domain

     

    $standard1 += $value

     

    }

     

     

    build the text for the records object we will use to propagate all of the records

     

    [string[][]]$records = @($standard1, $standard2)

     

     

    build a masterBool object to let the zone object know if we want to sync the ptrs

     

    $masterBool = @()

     

    for ($c = 0; $c -lt 259; $c++)

     

    {

     

    $masterBool += $false

     

    }

     

     

    build our zone object

     

    $boguszone = New-Object -TypeName iControl.ManagementZoneInfo

     

    $boguszone.view_name = "external"

     

    $boguszone.zone_name = $reverseip + $INADDR

     

    $new_zi_zonetype = [iControl.ManagementZoneType] "Master"

     

    $boguszone.zone_type = $new_zi_zonetype

     

    $options = @("allow-update {

     

    localhost;

     

    };")

     

    $boguszone.option_seq = $options

     

    $boguszone.zone_file = "db.external." + $reverseip + $INADDR

     

     

    add our zone object to the F5

     

    (Get-F5.iControl).ManagementZone.add_zone_text($boguszone, $records, $masterBool)

     

     

    kill the icontrol object

     

    $ic = $null