PowerShell DnsServer module (5/5)
The last part of the DnsServer module is about Set- cmdlets that change a running DNS server (recursion, block list, primary zone, records, policies, aging, RRL, DNSSEC keys) plus the Show-, Start-, Test- and Sync- operations. Every change is shown with its real effect in the BIND 9 lab (the module itself is not installed on the office PC: Count 0).
245.1 How a Set- cmdlet changes behaviour
- Step 1
1.Client 192.168.65.30 asks dnssvr1 for app.partner.lab
- Step 2
2.Recursion on: dnssvr1 forwards to upstream 192.168.65.20 -> 192.168.65.60
- Step 3
3.Set recursion off (Set-DnsServerRecursion -Enable $false / recursion no)
- Step 4
4.Same query -> REFUSED (recursion requested but not available)
- Step 5
5.wpad.partner.lab is on the block list -> NXDOMAIN
245.2 Set-DnsServerRecursion and recursion scopes
- Recursion = the server asks other DNS servers on behalf of the client and returns the answer.
- -Enable on/off; -Timeout, -AdditionalTimeout, -RetryInterval set the waits.
- -SecureResponse $true protects the cache from pollution.
- Set-DnsServerRecursionScope changes the forwarders and recursion of one scope.
Set-DnsServerRecursion -RetryInterval 15 ` -PassThru Set-DnsServerRecursionScope ` -Name "ScopeInternal" ` -Forwarder 192.168.0.1 ` -EnableRecursion $False -PassThruName Forwarder EnableRecursion---- --------- ---------------ScopeInternal 192.168.0.1 Falseoptions { recursion yes; # step 1 allow-recursion { 192.168.65.0/24; }; forwarders { 192.168.65.20; }; forward only;};# step 2: sed recursion yes -> norndc reconfig$ dig @192.168.65.10 app.partner.lab A;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 56603;; flags: qr rd ra; QUERY: 1, ANSWER: 1app.partner.lab. 3600 IN A 192.168.65.60 $ sed recursion yes -> no; rndc reconfig recursion no;$ dig @192.168.65.10 app.partner.lab A;; ->>HEADER<<- opcode: QUERY, status: REFUSED, id: 674;; flags: qr rd; QUERY: 1, ANSWER: 0;; WARNING: recursion requested but not available- Note the ra (recursion available) flag disappears after recursion is turned off.
245.3 Global query block list and RPZ
Set-DnsServerGlobalQueryBlockList ` -List "Isatap" -PassThru -VerboseVERBOSE: Setting DNS server GlobalQueryBlockList on Fabrikam01 server. VERBOSE: GlobalQueryBlockList successfully set on server Fabrikam01.Enable : True List : {isatap}- -List REPLACES the whole old list; -Enable turns the block list on/off.
- WPAD and ISATAP are hijack-prone, so they are in the default list.
- BIND has no such setting; the closest equivalent is an RPZ (response policy zone) where CNAME . means answer NXDOMAIN.
# rpz.lab.dbwpad.partner.lab CNAME .isatap.partner.lab CNAME . # named.conf, view "default"response-policy { zone "rpz.lab"; };zone "rpz.lab" { type primary; file "/var/bind/rpz.lab.db"; };rndc reconfig$ dig @192.168.65.10 wpad.partner.lab A;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 30358$ dig @192.168.65.10 isatap.partner.lab A;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 5636rpz QNAME NXDOMAIN rewrite wpad.partner.lab/A/IN via wpad.partner.lab.rpz.lab $ dig @192.168.65.10 app.partner.lab A +noall +answerapp.partner.lab. 3580 IN A 192.168.65.60245.4 Set-DnsServerPrimaryZone and allow-update
Set-DnsServerPrimaryZone ` -Name "western.contoso.com" ` -DynamicUpdate "NonsecureAndSecure" ` -PassThruZoneName ZoneType IsAutoCreated IsDsIntegrated IsReverseLookupZone IsSigned-------- -------- ------------- -------------- ------------------- --------western.contoso.com Primary False True False False| Option | What it changes |
|---|---|
| -DynamicUpdate None|Secure|NonsecureAndSecure | Who may send dynamic updates |
| -ReplicationScope / -DirectoryPartitionName | Where in AD the zone is stored |
| -ZoneFile | File for a file-backed zone |
| -Notify NoNotify|Notify|NotifyServers + -NotifyServers | Which secondaries get NOTIFY |
| -SecureSecondaries NoTransfer|TransferAny.. + -SecondaryServers | Who may take zone transfers |
- BIND lab: allow-update { none; } -> even the keyed update was REFUSED; allow-update { key upd-key; } -> accepted; without a key still REFUSED (like Secure on Windows).
$ rndc reconfig (allow-update key upd-key) allow-update { key "upd-key";$ nsupdate -k /root/upd.keyupdate sent$ dig @192.168.65.10 host02.contoso.com A +noall +answerhost02.contoso.com. 3600 IN A 192.168.65.53 $ nsupdate (no key)update failed: REFUSEDview default: update 'contoso.com/IN' denied245.5 Set-DnsServerResourceRecord: change a record's TTL
- Step 1
1.Get-DnsServerResourceRecord Host01 A -> $OldObj
- Step 2
2.Copy it: $NewObj = [ciminstance]::new($OldObj)
- Step 3
3.Change $NewObj.TimeToLive to 2 hours
- Step 4
4.Set-DnsServerResourceRecord -NewInputObject $NewObj -OldInputObject $OldObj
- Step 5
5.Output: Host01 A TimeToLive 02:00:00
Name and Type cannot be changed this way; BIND does it with nsupdate delete + add
$OldObj = Get-DnsServerResourceRecord ` -Name "Host01" -ZoneName "contoso.com" ` -RRType "A"$NewObj = [ciminstance]::new($OldObj)$NewObj.TimeToLive = ` [System.TimeSpan]::FromHours(2)Set-DnsServerResourceRecord ` -NewInputObject $NewObj ` -OldInputObject $OldObj ` -ZoneName "contoso.com" -PassThruHostName RecordType Timestamp TimeToLive RecordData-------- ---------- --------- ---------- ----------Host01 A 0 02:00:00 2.2.2.2server 192.168.65.10zone contoso.comupdate delete host01.contoso.com Aupdate add host01.contoso.com 7200 A 192.168.65.52send# nsupdate -k /root/upd.key# then: rndc sync contoso.com in default$ rndc sync contoso.com in default$ grep host0 /var/bind/default/contoso.com.dbhost01 A 192.168.65.52host02 A 192.168.65.53- rndc sync writes the journal into the zone file: the job of Sync-DnsServerZone.
245.6 Set-DnsServerQueryResolutionPolicy
Set-DnsServerQueryResolutionPolicy ` -Name "PolicyMalicious" ` -InternetProtocol "eq,IPv4" -PassThru | Format-List *Action : IgnoreAppliesOn : QueryProcessingCondition : AndCriteria : {DnsServerPolicyCriteria, DnsServerPolicyCriteria}IsEnabled : TrueLevel : ServerName : PolicyMaliciousProcessingOrder : 2- Criteria use "operator,value01,value02": -ClientSubnet, -Fqdn, -QType, -TimeOfDay, -InternetProtocol, -TransportProtocol, -ServerInterfaceIP.
- Also changes -Condition, -ProcessingOrder, -ZoneScope, -RecursionScope.
- BIND lab: changing the branch acl from .40 to .30 + rndc reconfig swapped the two career answers.
$ dig -b 192.168.65.30 @192.168.65.10 career.contoso.com A +short192.168.65.100$ dig -b 192.168.65.40 @192.168.65.10 career.contoso.com A +short192.168.65.140 $ rndc reconfig (acl branch-subnet 192.168.65.30/32)$ dig -b 192.168.65.30 @192.168.65.10 career.contoso.com A +short192.168.65.140$ dig -b 192.168.65.40 @192.168.65.10 career.contoso.com A +short192.168.65.100245.7 Other zone types, aging and scavenging
- Set-DnsServerSecondaryZone / Set-DnsServerStubZone: change -MasterServers; stub -LocalMasters = masters for this server only.
- Set-DnsServerZoneDelegation -Name contoso.com -ChildZoneName west01 -NameServer ... -IPAddress 172.23.90.136.
- Aging order: first Set-DnsServerZoneAging -Aging $True on the zone, then Set-DnsServerResourceRecordAging timestamps records (-Recurse for child nodes).
- Set-DnsServerScavenging -ScavengingState $true -RefreshInterval 1.00:00:00 sets server intervals.
- Start-DnsServerScavenging runs now, but only if scavenging is on for both server and zone.
245.8 RRL, transfer policy, DNSSEC keys
| Cmdlet | Key options |
|---|---|
| Set-DnsServerResponseRateLimiting | -ResponsesPerSec 8 -ErrorsPerSec 8 -WindowInSec 7 -LeakRate 4 -TruncateRate 3 -IPv4PrefixLength 24 -Mode LogOnly|Enable|Disable -ResetToDefault |
| Set-DnsServerResponseRateLimitingExceptionlist | -Name SafeList1 -ServerInterfaceIP "EQ,10.0.0.1" -ClientSubnet -Fqdn |
| Set-DnsServerZoneTransferPolicy | -TransportProtocol "NE,TCP"; -ServerInterfaceIP $Null removes that criterion |
| Set-DnsServerSigningKey | -NextRolloverAction Normal|RevokeStandby|Retire, -RolloverPeriod |
| Step-DnsServerSigningKeyRollover | Forces a KSK rollover (update the parent DS manually first) |
| Test-DnsServerDnsSecZoneSetting / Update-DnsServerTrustPoint | Validate zone DNSSEC settings / refresh trust points |
- Use -Mode LogOnly first to see who would be limited before enforcing RRL.
Get-DnsServerSigningKey ` -ZoneName "sec.contoso.com" | Set-DnsServerSigningKey ` -NextRolloverAction "Retire" Get-DnsServerSetting -ComputerName ` "172.23.90.136" -All | Set-DnsServerSetting245.9 Daily operations: Test, Start, Suspend, Sync, Show
Test-DnsServer -IPAddress 10.123.183.155 ` -Context ForwarderStart-DnsServerZoneTransfer ` -Name "contoso.com" -FullTransferSuspend-DnsServerZone ` -Name "west02.contoso.com" -ForceSync-DnsServerZone ` -Name "west02.contoso.com" -PassThruPS C:\> Test-DnsServer -IPAddress 10.123.183.155 -Context Forwarder IPAddress Result RoundTripTime TcpTried UdpTried--------- -------- ------------ -------- --------10.123.183.155 Success 00:00:11 False True PS C:\> Test-DnsServer -IPAddress 10.123.183.155 -Context RootHints IPAddress Result RoundTripTime TcpTried UdpTried--------- -------- ------------ -------- --------10.123.183.155 NoResponse 00:00:12 False True- Test-DnsServer -Context DnsServer|Forwarder|RootHints checks whether a working DNS server answers at that IP.
- Start-DnsServerZoneTransfer is incremental unless -FullTransfer.
- A suspended zone ignores all queries until Resume-DnsServerZone.
- Show-DnsServerCache = BIND rndc dumpdb -cache; Set-DnsServerRootHint replaces the whole root hints list.
245.10 Common mistakes
- Thinking recursion off = DNS stopped: the server still replies (REFUSED) and stays authoritative for its own zones.
- Passing one name to -List and wiping the rest of the block list (it replaces).
- Trying to change a record's Name or Type with Set-DnsServerResourceRecord.
- Turning on record aging before zone aging, or running Start-DnsServerScavenging with scavenging off on the zone.
245.11 Interview tips
- Change a TTL: Get- into $OldObj, copy to $NewObj, set TimeToLive, Set-DnsServerResourceRecord with both; BIND: nsupdate delete + add.
- Block wpad: Set-DnsServerGlobalQueryBlockList -List wpad -Enable $true; BIND: RPZ with CNAME .
- Recursion off makes the server authoritative-only, it does not stop it.
- DnsServer series recap: Add- (1-2), Get-/Import-/Invoke- (3), Remove- + first Set- (4), Set-/Show-/Test- (5).