Skip to content
INSIGHTS & GUIDES · NETCLOUD24

How to Add and Update DNS A and PTR Records with PowerShell

Read the article ↓
Editorial illustration: How to Add and Update DNS A and PTR Records with PowerShell

An A record resolves a host name to an IPv4 address; a PTR record resolves an address back to a name. They are separate DNS objects, so changing one does not prove that the other is correct. This procedure covers a controlled change on Windows DNS Server.

Confirm record ownership and the authoritative zones

Identify the forward zone, authoritative DNS server, current address and the reverse zone that owns the address. Some records are maintained by DHCP or a domain-joined computer. A manual edit to a dynamically managed record may be overwritten at the next registration. Confirm who owns the change before proceeding.

For public addresses, reverse DNS is commonly managed by the address provider. Creating a PTR record on an internal DNS server does not change internet-visible reverse DNS. Request the public PTR change from the responsible provider when that is the actual requirement.

Inspect and save the existing values

Use the DnsServer module from a suitably delegated administrative session. Save the existing data and TTL before changing anything. These examples use a nonproduction documentation address and an example internal zone.

Get-DnsServerResourceRecord -ComputerName 'DC01' -ZoneName 'corp.example' -Name 'app01'
Resolve-DnsName app01.corp.example -Server DC01

Add a new A record and its PTR

Create the reverse lookup zone first if you administer it and the approved design requires it. The CreatePtr switch attempts to create the corresponding reverse record; the reverse zone must exist and permissions must allow the operation.

Add-DnsServerResourceRecordA -ComputerName 'DC01' -ZoneName 'corp.example' -Name 'app01' -IPv4Address '192.0.2.40' -CreatePtr

Change an existing address without discarding its other properties

Retrieve the specific existing record, clone it and change its IPv4 value. A name may have multiple A records, so inspect the result before selecting a record to edit. Do not blindly update the first object in a multi-address service.

$old = Get-DnsServerResourceRecord -ComputerName 'DC01' -ZoneName 'corp.example' -Name 'app01' -RRType A
# Continue only after verifying that $old identifies the intended single record.
$new = $old.Clone()
$new.RecordData.IPv4Address = [System.Net.IPAddress]::Parse('192.0.2.41')
Set-DnsServerResourceRecord -ComputerName 'DC01' -ZoneName 'corp.example' -OldInputObject $old -NewInputObject $new

Verify both directions and the application

Query the authoritative server first, then test from representative clients. Cached answers can remain until their original TTL expires. Check the old and new reverse addresses separately, because updating the forward record does not automatically remove every obsolete PTR.

For a controlled /24 reverse zone, a PTR for 192.0.2.41 belongs under the label 41 in 2.0.192.in-addr.arpa. Other reverse delegations can use a different structure; follow the actual zone design rather than assuming every network is a /24.

Resolve-DnsName app01.corp.example -Type A -Server DC01
Resolve-DnsName 192.0.2.41 -Type PTR -Server DC01

Rollback and common mistakes

Restore the original A and PTR values if the application does not function through the new address. Account for cached answers during both the change and rollback. Check load balancers, certificates, firewall rules and application bindings independently; a successful DNS lookup is only one part of a working migration.

For syntax details, see Microsoft’s DNS record creation reference and PTR record reference.


Was this answer helpful?

« Back
Contact

Write to us

Do you have questions about our services or need a quote? Write to us and we will respond as soon as possible.

Contact form

Fields marked * are required.