PowerShell DnsServer module (4/5)
Part 4 of the DnsServer module covers cleanup and change: removing zones, records and delegations, zone scopes, policies, root hints and DNSSEC keys, the Restore/Resume cmdlets, and the first Set- cmdlets (server, cache, forwarders, diagnostics, DNSSEC settings, DoH). Windows examples come from Microsoft Learn; the lab is BIND 9 in Docker.
244.1 Delegation and what removing it does
- Step 1
1.Client asks Parent DNS (contoso.com) for www.west05.contoso.com
- Step 2
2.Before: parent returns a referral from the west05 NS record
- Step 3
3.Client asks Child DNS -> 192.168.64.55
- Step 4
4.Remove-DnsServerZoneDelegation deletes the west05 NS in the parent
- Step 5
5.Same query via the parent -> NXDOMAIN
- Step 6
6.Direct query to Child DNS still -> 192.168.64.55 (zone alive)
Removing a delegation does NOT delete the child zone
244.2 Remove-DnsServerZone and Remove-DnsServerZoneDelegation
Remove-DnsServerZone "western.contoso.com" ` -PassThru -Verbose Remove-DnsServerZoneDelegation ` -Name "contoso.com" ` -ChildZoneName "west05" -PassThru -Verbose- Remove-DnsServerZone removes any zone type: primary, secondary, stub or conditional forwarder.
- It asks for confirmation by default; -Force skips the prompt.
- Delegation: -Name = parent zone, -ChildZoneName = child (both required).
- -NameServer removes only that server from the delegation; without it the whole delegation goes.
244.3 Lab: delzone, nsupdate delete, delete NS
rndc addzone western.contoso.com \ '{ type primary; file "/var/bind/western.contoso.com.db"; };'dig @192.168.64.20 www.western.contoso.comrndc delzone western.contoso.comdig @192.168.64.20 www.western.contoso.com$ dig @192.168.64.20 www.western.contoso.com A;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 4373;; flags: qr aa rd; QUERY: 1, ANSWER: 1, AUTHORITY: 0www.western.contoso.com. 300 IN A 192.168.64.66$ rndc delzone western.contoso.com(exit 0)$ dig @192.168.64.20 www.western.contoso.com A;; ->>HEADER<<- opcode: QUERY, status: REFUSED, id: 31891$ grep western named.log18:23:45.109 deleting zone western.contoso.com in view _default via delzone- After delzone the server no longer has the zone, so it answers REFUSED.
- Records are deleted with nsupdate 'update delete'; without the TSIG key the update is REFUSED.
server 192.168.64.10zone contoso.comupdate delete host01.contoso.com Asend# nsupdate -k /root/upd.key server 192.168.64.10zone contoso.comupdate delete west05.contoso.com NSupdate delete ns1.west05.contoso.com Asend# then: rndc flush (resolver cache)$ nsupdate (no key)update failed: REFUSED$ nsupdate -k /root/upd.keyupdate sent$ dig @192.168.64.10 host01.contoso.com A;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 49827contoso.com. 60 IN SOA dnssvr1.contoso.com. admin.contoso.com. 2026110902 3600 600 86400 60$ dig @192.168.64.10 www.west05.contoso.com A +norecurse;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 23376$ dig @192.168.64.20 www.west05.contoso.com A (child);; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 24232www.west05.contoso.com. 300 IN A 192.168.64.55244.4 Removing scopes, policies, RRL lists, instances, root hints
| Cmdlet | Key point |
|---|---|
| Remove-DnsServerZoneScope | -ZoneName + -Name required; the default scope cannot be deleted |
| Remove-DnsServerZoneTransferPolicy | With -ZoneName = zone-level policy; without = server-level |
| Remove-DnsServerResponseRateLimitingExceptionlist | -Name "SafeList1" |
| Remove-DnsServerVirtualizationInstance | -Name 8231; -RemoveZoneFiles also deletes its zone files |
| Remove-DnsServerRootHint | Without root hints the server resolves only its own zones |
Get-DnsServerZoneTransferPolicy ` -ZoneName "contoso.com" | Remove-DnsServerZoneTransferPolicy ` -ZoneName "contoso.com" -ForceRemove-DnsServerVirtualizationInstance -Name 8231 -Force -PassThruGet-DnsServerRootHint | Remove-DnsServerRootHintPS C:\> Remove-DnsServerZoneTransferPolicy -Name "InternalTransfers" -PassThruName ProcessingOrder IsEnabled Action---- --------------- --------- ------InternalTransfers 2 True IgnorePS C:\> Remove-DnsServerVirtualizationInstance -Name 8231 -Force -PassThruVirtualizationInstance FriendlyName Description---------------------- ------------ -----------8231 HostTenantPartition This virtualization instance hosts th...244.5 DNSSEC cleanup: keys, trust anchors, Key Master
- Remove-DnsServerSigningKey -ZoneName -KeyId: only for an unsigned / wrongly configured zone; it cannot remove an active key of a signed zone.
- Remove-DnsServerTrustAnchor -Name -Type DnsKey|DS; without -Type all matching anchors go.
- Reset-DnsServerZoneKeyMasterRole -KeyMasterServer moves the Key Master role; -SeizeRole when the old Key Master is down.
- Active keys are retired with a rollover so resolver validation does not break.
- Step 1
1.west01 starts on policy n244-ksk-zsk: KSK 37549 + ZSK 47633
- Step 2
2.Change the zone to dnssec-policy "n244-csk"
- Step 3
3.rndc reconfig
- Step 4
4.named creates a new CSK 39855 and signs with it
- Step 5
5.Old KSK and ZSK: Key has been removed from the zone, goal hidden
dnssec-policy "n244-ksk-zsk" { keys { ksk lifetime unlimited algorithm ecdsap256sha256; zsk lifetime unlimited algorithm ecdsap256sha256; };};dnssec-policy "n244-csk" { keys { csk lifetime unlimited algorithm ecdsap256sha256; };};zone "west01.contoso.com" { inline-signing yes; dnssec-policy "n244-csk"; };dnssec-policy: n244-cskkey: 47633 (ECDSAP256SHA256), ZSK Key has been removed from the zone - goal: hiddenkey: 39855 (ECDSAP256SHA256), CSK zone signing: yes - since Mon Nov 9 18:24:36 2026key: 37549 (ECDSAP256SHA256), KSK Key has been removed from the zone - goal: hidden- BIND trust anchors live in the trust-anchors block (static-key/static-ds stay trusted until removed; initial-key/initial-ds use RFC 5011). Removing = delete the entry + rndc reconfig.
244.6 Restore and Resume
| Cmdlet | What it does | BIND |
|---|---|---|
| Restore-DnsServerPrimaryZone | Reloads the zone from AD DS or the zone file | rndc reload <zone> |
| Restore-DnsServerSecondaryZone | Copies the zone again from its primary | rndc retransfer <zone> |
| Resume-DnsServerZone | Restarts resolution on a suspended zone | - |
244.7 Set-DnsServer, cache, EDNS, DS settings, client subnet
Get-DnsServer -CimSession 172.22.50.137 | Set-DnsServer -ComputerName 172.22.50.138 Set-DnsServerCache -MaxKBSize 10240 ` -MaxTTL 02.00:00:00 -MaxNegativeTtl 00.00:20:00 Set-DnsServerDsSetting ` -DirectoryPartitionAutoEnlistInterval 15.00:00:00 -PassThru Set-DnsServerClientSubnet ` -Name "AsiaSubnet" -Action ADD ` -IPv4Subnet 192.168.0.4/16 -PassThruName : AsiaSubnetIPV4Subnet : {10.10.0.1/8, 192.168.0.4/16}IPV6Subnet : {0db8::1/28}- Set-DnsServer overwrites the WHOLE configuration of the target from an input object (copy server to server).
- Set-DnsServerCache: -MaxKBSize (KB), -MaxTTL, -MaxNegativeTtl (NXDOMAIN TTL), -LockingPercent, -PollutionProtection.
- Set-DnsServerEDns: -CacheTimeout 00:30:00, -EnableProbes, -EnableReception.
- Set-DnsServerClientSubnet: -Action ADD|REMOVE|REPLACE is required.
244.8 Forwarders and conditional forwarders
- Set-DnsServerForwarder -IPAddress "10.0.0.1" OVERWRITES the server-level list (Add- appends).
- -Timeout: default wait is 5 seconds; -UseRootHint after forwarders; -EnableReordering $False.
- Set-DnsServerConditionalForwarderZone -Name "contoso.com" -ForwarderTimeout 15; also -MasterServers, -UseRecursion, -ReplicationScope.
244.9 Set-DnsServerDiagnostics and rndc querylog
- 37 options in groups: which packets (-SendPackets, -ReceivePackets, -TcpPackets, -UdpPackets), which content (-Queries, -Updates, -Answers, -FullPackets).
- Log file: -LogFilePath, -MaxMBFileSize, -EnableLogFileRollover, -EnableLoggingToFile; event log: -EventLogLevel.
- -All $True turns on everything except options like LogFilePath.
- BIND equivalent: rndc querylog on/off.
rndc querylog onrndc status | grep 'query logging'dig @192.168.64.10 www.contoso.com A +shortcat /var/log/named/query.logrndc querylog off$ dig @192.168.64.10 www.contoso.com A +short192.168.64.80$ cat /var/log/named/query.log18:24:48.051 client @0x7a6c1ff48340 192.168.64.30#57691 (www.contoso.com): query: www.contoso.com IN A +E(0)K (192.168.64.10)$ rndc querylog offquery logging is OFF244.10 DNSSEC zone settings, DoH and GlobalNames
Set-DnsServerDnsSecZoneSetting -ZoneName "west01.contoso.com" ` -EnableRfc5011KeyRollover $True -PassThru -Verbose Set-DnsServerEncryptionProtocol -EnableDoh $trueRestart-Service DNSVERBOSE: RFC5011KeyRollovers successfully set on server Server01.ZoneName : west01.contoso.comIsKeyMasterServer : TrueKeyMasterServer : Server01.west01.contoso.comDenialOfExistence : NSec3NSec3Iterations : 50DSRecordGenerationAlgorithm : {Sha1, Sha256}EnableRfc5011KeyRollover : TruePropagationTime : 2.00:00:00PS C:\> Set-DnsServerEncryptionProtocol -EnableDoh $trueWARNING: Modifying DOH setting will require restarting the DNS service.PS C:\> Restart-Service DNS- Set-DnsServerDnsSecZoneSetting (20 options): -DenialOfExistence NSec|NSec3, NSEC3 iterations/salt, DS/DNSKEY TTLs, -DistributeTrustAnchor.
- Set-DnsServerEncryptionProtocol: Windows Server 2025, -UriTemplate (max three), needs a DNS service restart.
- Set-DnsServerGlobalNameZone -Enable $True: resolves single-label names (just the short server name).
244.11 Common mistakes
- Believing that removing a delegation deletes the child zone: it only removes the parent's NS (and glue) records.
- Using Set-DnsServerForwarder to 'add' a forwarder: it replaces the whole list.
- Trying to Remove-DnsServerSigningKey an active key: retire it with a rollover instead.
- Enabling DoH and forgetting to restart the DNS service.
244.12 Interview tips
- Delegation removed: via the parent -> NXDOMAIN; direct to the child -> still answers.
- Removing an active DNSSEC key: roll it over; in BIND change the dnssec-policy and named sets the old key's goal to hidden.
- Add- appends vs Set- replaces (forwarders); Remove- asks to confirm unless -Force.
- Query logging: Set-DnsServerDiagnostics -Queries on Windows, rndc querylog in BIND.