Forum Discussion
Matt_100070
Oct 20, 2011Nimbostratus
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?...
Matt_100070
Nov 15, 2011Nimbostratus
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
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects