PowerShell DnsServer module (2/5)
Part 2 of the DnsServer module: secondary and stub zones, MX/PTR records, delegation and root hints, DNSSEC keys and trust anchors, response rate limiting, zone scopes, transfer policies and the Clear/Export maintenance cmdlets. Examples are from Microsoft Learn (the module is not installed on the office PC: Count 0) and the lab runs on BIND 9.
242.1 Secondary vs stub zone: how it works
- Step 1
1.dnssvr1 (192.168.62.10) holds the primary copy of western.contoso.com
- Step 2
2.Add-DnsServerSecondaryZone creates a read-only copy on dnssvr2
- Step 3
3.dnssvr2 sends an AXFR request to the primary
- Step 4
4.Primary transfers the whole zone (8 records)
- Step 5
5.Client asks dnssvr2 for www -> 192.168.62.50 (authoritative, aa flag)
A stub zone only asks for SOA + NS and keeps SOA, NS and glue A records
| Point | Secondary zone | Stub zone |
|---|---|---|
| Holds | Read-only copy of the whole zone | Only SOA, NS and glue A |
| Answers | All names, authoritatively | Only says which servers are authoritative |
| Cmdlet | Add-DnsServerSecondaryZone (8) | Add-DnsServerStubZone (11) |
| AD storage | No (file only) | Yes, -ReplicationScope / -DirectoryPartitionName |
| BIND | type secondary | type stub |
242.2 Zone cmdlets: secondary, stub, ConvertTo
- Secondary: -Name, -MasterServers 172.23.90.124, -ZoneFile; -NetworkId 10.1.2.0/24 for a reverse zone; -LoadExisting.
- Stub: the same options + -ReplicationScope Forest|Domain|Legacy|Custom.
- ConvertTo-DnsServerPrimaryZone: promote a secondary when the primary is gone for good (AD: -ReplicationScope Domain).
- ConvertTo-DnsServerSecondaryZone: the opposite direction, needs -MasterServers.
ConvertTo-DnsServerPrimaryZone ` -Name "west03.contoso.com" ` -ZoneFile "west03.contoso.com" ` -PassThru -Verbose -Force ConvertTo-DnsServerSecondaryZone ` -Name "0.0.10.in-addr.arpa" ` -MasterServers 172.23.90.124 ` -ZoneFile "0.0.10.in-addr.arpa.dns"VERBOSE: Convert west03.contoso.com zone to (file backed/AD integrated) DNS primary zone on DNS-11 server.ZoneName ZoneType IsAutoCreated IsDsIntegrated IsReverseLookupZone IsSigned-------- -------- ------------- -------------- ------------------- --------west03.contoso.com Primary False False False False242.3 Lab: type secondary and type stub
zone "western.contoso.com" { type secondary; primaries { 192.168.62.10; }; file "/var/bind/sec/western.contoso.com.db";};zone "sec.contoso.com" { type stub; primaries { 192.168.62.10; }; file "/var/bind/sec/sec.contoso.com.stub";};$ grep transfer named.log18:18:03.856 transfer of 'western.contoso.com/IN' from 192.168.62.10#53: Transfer completed: 1 messages, 8 records, 224 bytes, 0.012 secs (18666 bytes/sec) (serial 2026110901)$ dig @192.168.62.20 www.western.contoso.com A;; flags: qr aa rd; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1www.western.contoso.com. 3600 IN A 192.168.62.50$ cat /var/bind/sec/sec.contoso.com.stub (comments trimmed)sec.contoso.com IN SOA ns1.sec.contoso.com. admin.sec.contoso.com. (2026110903 ...) NS ns1.sec.contoso.com.$ORIGIN sec.contoso.com.ns1 A 192.168.62.10- The stub file has no www record: a stub only remembers who gives the answers.
242.4 MX and PTR records
Add-DnsServerResourceRecordMX -Preference 10 ` -Name "." -TimeToLive 01:00:00 ` -MailExchange "mail.contoso.com" ` -ZoneName "contoso.com"Add-DnsServerResourceRecordPtr -Name "17" ` -ZoneName "0.168.192.in-addr.arpa" ` -PtrDomainName "host17.contoso.com" ` -AllowUpdateAny -AgeRecord ` -TimeToLive 01:00:00- MX: which server receives mail for the domain; -Preference 0-65535, the lowest is tried first.
- -MailExchange must be an FQDN that has an A record.
- PTR: reverse lookup (IP -> name); -Name "17" is the host part of the IP inside the reverse zone.
- Reverse zone name = first three octets reversed + in-addr.arpa (62.168.192.in-addr.arpa).
- -AgeRecord lets the server scavenge the record later.
# client: nsupdate inputserver 192.168.62.10zone western.contoso.comupdate add western.contoso.com 3600 MX 10 mail.western.contoso.com.sendserver 192.168.62.10zone 62.168.192.in-addr.arpaupdate add 25.62.168.192.in-addr.arpa 3600 PTR mail.western.contoso.com.send$ dig @192.168.62.20 western.contoso.com MXwestern.contoso.com. 3600 IN MX 10 mail.western.contoso.com.$ dig @192.168.62.20 western.contoso.com SOA +shortns1.western.contoso.com. admin.western.contoso.com. 2026110902 3600 600 86400 900$ grep 'updating zone' named.log (dnssvr1)18:18:25.650 client 192.168.62.30#36727: updating zone 'western.contoso.com/IN': adding an RR at 'western.contoso.com' MX 10 mail.western.contoso.com.18:18:38.810 client 192.168.62.30#44545: updating zone '62.168.192.in-addr.arpa/IN': adding an RR at '25.62.168.192.in-addr.arpa' PTR mail.western.contoso.com.- After the update the primary raised the serial and sent NOTIFY; the secondary transferred immediately, so both show the same MX.
242.5 Delegation and root hints
Add-DnsServerZoneDelegation ` -Name "contoso.com" ` -ChildZoneName "west01" ` -NameServer "wserver.west01.contoso.com" ` -IPAddress 172.23.90.136 -PassThru Add-DnsServerRootHint ` -NameServer "root.contoso.com" ` -IPAddress 172.23.90.128- Delegation: the parent zone hands a child name (west01) to another DNS server.
- Root hints: the list a server uses to reach the root servers during recursion.
- BIND: zone "." { type hint; }. In the lab the hints file has only one lab root (192.168.62.10) and recursion is off, so nothing goes to the internet.
. 3600000 NS root.contoso.com.root.contoso.com. 3600000 A 192.168.62.10242.6 DNSSEC: signing keys, trust anchors, rollover
- Step 1
1.Add-DnsServerSigningKey adds a KSK and a ZSK to the zone
- Step 2
2.ZSK signs the records (RRSIG); KSK signs the DNSKEY set
- Step 3
3.Export-DnsServerDnsSecPublicKey writes Dsset-/Keyset- files
- Step 4
4.Parent zone stores the DS record of the child
- Step 5
5.Resolver has a trust anchor (Add-DnsServerTrustAnchor) and validates
- Step 6
6.Enable-DnsServerSigningKeyRollover changes keys on a RolloverPeriod
Add-DnsServerSigningKey ` -ZoneName "corp.contoso.com" ` -Type "KeySigningKey" -KeyLength 2048 ` -CryptoAlgorithm "RsaSha1NSec3" -PassThru Get-DnsServerResourceRecord ` -ZoneName "sec.contoso.com" ` -RRType "dnskey" -ComputerName DNS1 | %{ $_.RecordData | Add-DnsServerTrustAnchor -PassThru ` -Verbose -Name "sec.contoso.com" } Get-DnsServerSigningKey ` -ZoneName "DNSServer06.Contoso.com" | Enable-DnsServerSigningKeyRollover Export-DnsServerDnsSecPublicKey ` -ZoneName "Contoso.com" -DigestType "Sha1" ` -Path "\\MyDNSKeyShare\keys" -PassThruVERBOSE: Adding trust anchor for trust point sec.contoso.com of type DNSKEY on server Server01.TrustAnchorName TrustAnchorType TrustAnchorState TrustAnchorData--------------- --------------- ---------------- ---------------sec.contoso.com DNSKEY Valid [23600][DnsSec][RsaSha256]...VERBOSE: Adding trust anchor for trust point sec.contoso.com of type DNSKEY on server Server01.sec.contoso.com DNSKEY Valid [53180][DnsSec][RsaSha256]...| Option | Meaning |
|---|---|
| -Type KeySigningKey | ZoneSigningKey | KSK signs keys, ZSK signs records |
| -CryptoAlgorithm | RsaSha256, ECDsaP256Sha256, ... |
| -StoreKeysInAD $true | Keep the keys in AD DS |
| -RolloverPeriod / -InitialRolloverOffset | Gap between rollovers / delay of the first |
| -DnsKey/-DS/-ZoneSignatureValidityPeriod | Signature validity of DNSKEY, DS and other records |
| Disable-DnsServerSigningKeyRollover -KeyId -ZoneName | Stop automatic rollover |
- BIND lab: dnssec-policy default + inline-signing yes, and named creates the keys and signatures itself.
- rndc dnssec -status showed one ECDSAP256SHA256 CSK (key 18381) doing both KSK and ZSK jobs.
$ rndc dnssec -status sec.contoso.comdnssec-policy: defaultkey: 18381 (ECDSAP256SHA256), CSK published: yes key signing: yes zone signing: yes No rollover scheduled$ dig www.sec.contoso.com A +dnssec +nocryptowww.sec.contoso.com. 3600 IN A 192.168.62.60www.sec.contoso.com. 3600 IN RRSIG A 13 4 3600 20261123072505 20261109171758 18381 sec.contoso.com. [omitted]$ dig www.western.contoso.com A +dnssecwww.western.contoso.com. 3600 IN A 192.168.62.50242.7 Response Rate Limiting (RRL)
- Step 1
1.Attacker spoofs the victim IP and sends many identical queries
- Step 2
2.Without RRL the server's answers flood the victim
- Step 3
3.RRL: one client subnet gets the same answer only N times per second
- Step 4
4.Extra responses are dropped or sent truncated (TC=1)
- Step 5
5.A real client retries over TCP; exempt clients always get answers
Add-DnsServerResponseRateLimitingExceptionlist ` -Name "SafeList1" -Fqdn "EQ,*.contoso.com"- Exception list criteria: -Fqdn, -ClientSubnet, -ServerInterfaceIP; format COMPARATOR,value1,value2; -Condition AND|OR.
- BIND: rate-limit block; exempt-clients = exception list; log-only no means the limit is really applied.
options { recursion no; rate-limit { responses-per-second 2; exempt-clients { 192.168.62.40; }; log-only no; };};$ rndc stats; grep rate named.stats 4 responses dropped for rate limits 4 responses truncated for rate limits- 10 parallel queries from 192.168.62.30: only 6 answered, 4 timed out. The same 10 from the exempt 192.168.62.40: all answered.
242.8 Zone scopes, transfer policies, Enable/Disable policy
Add-DnsServerZoneScope ` -ZoneName "contoso.com" ` -Name "contoso_NorthAmerica" ` -Verbose -PassThru Add-DnsServerZoneTransferPolicy ` -Name "InternalTransfers" -Action IGNORE ` -ServerInterfaceIP "ne,10.0.0.33" ` -PassThru Enable-DnsServerPolicy -Level Zone ` -Name "Policy07" -ZoneName "EuropeZone"Disable-DnsServerPolicy -Level ServerZoneScope FileName--------- --------contoso_NorthAmerica contoso_NorthAmerica.dns Name ProcessingOrder IsEnabled Action---- --------------- --------- ------internalTransfers1 3 True Ignore- Zone scope: a separate version of the records inside a zone (used by policies); its data lives in its own .dns file.
- Add-DnsServerVirtualizationInstance: a logical partition of the server that hosts same-name zones for different tenants.
- Transfer policy: -Action DENY | IGNORE; criteria -ClientSubnet, -ServerInterfaceIP, -TransportProtocol, -TimeOfDay...; -ZoneName makes it zone-level.
- Enable/Disable-DnsServerPolicy: -Level Zone|Server is required; without -Name ALL policies of that level change.
- BIND equivalent of a transfer policy: allow-transfer { 192.168.62.20; }; an AXFR from .30 gave Transfer failed.
$ dig -b 192.168.62.30 @192.168.62.10 western.contoso.com AXFR; Transfer failed.$ grep 'transfer.*denied' named.log18:18:21.251 client 192.168.62.30#41209 (western.contoso.com): zone transfer 'western.contoso.com/AXFR/IN' denied242.9 Clear and Export cmdlets
Clear-DnsServerCache -ComputerName ` "Win12S-05.DNSServer-01.Contoso.com" -ForceClear-DnsServerStatisticsClear-DnsServerStatistics ` -ZoneName "Contoso.com"Export-DnsServerZone ` -Name "western.contoso.com" ` -FileName "exportedcontoso.com"PS C:\> Clear-DnsServerStatisticsConfirmCleared statistics cannot be retrieved later, do you want to continue?[Y] Yes [N] No [S] Suspend [?] Help (default is "Y"):- Clear-DnsServerCache removes old answers (-CacheScope for one scope); Clear-DnsServerStatistics resets counters for good.
- Export-DnsServerZone writes an AD-integrated zone to a file in C:\Windows\System32\dns for troubleshooting.
242.10 Common mistakes
- Thinking DNSSEC encrypts DNS: the lab answer was plain text with an RRSIG; DNSSEC proves authenticity, DoT/DoH encrypt.
- Running Disable-DnsServerPolicy without -Name and switching off every policy of that level.
- New record missing on the secondary and not checking transfer permission, NOTIFY and the SOA serial on both servers.
- Clearing statistics before reading them: they cannot be retrieved later.
242.11 Interview tips
- Secondary vs stub: full read-only copy with authoritative answers vs only SOA, NS and glue.
- Record missing on secondary: check allow-transfer, NOTIFY, then compare SOA serials.
- KSK signs the DNSKEY set, ZSK signs the records; the parent's DS record links the chain of trust.
- RRL limits identical answers per client subnet to stop reflection attacks; truncation lets real clients retry over TCP.