PowerShell: Set DNS Servers on Localhost

Display the current DNS Server Entries

PS C:\Users\KimConnect> Get-DnsClientServerAddress

InterfaceAlias Interface Address ServerAddresses
Index Family
-------------- --------- ------- ---------------
Ethernet 2 6 IPv4 {,}
Ethernet 2 6 IPv6 {::1}
Loopback Pseudo-Interface 1 1 IPv4 {}
Loopback Pseudo-Interface 1 1 IPv6 {fec0:0:0:ffff::1, fec0:0:0:ffff::2, fec0:0:0:ffff::3}
isatap.{65BFBD6D-9E20-4A2... 7 IPv4 {,}
isatap.{65BFBD6D-9E20-4A2... 7 IPv6 {::1}

Note the Interface indexes and run these commands to set them:

Set-DnsClientServerAddress -InterfaceIndex 6 -ServerAddresses ($peerDnsServerIp,"")
Set-DnsClientServerAddress -InterfaceIndex 7 -ServerAddresses ($peerDnsServerIp,"")

Domain Controllers with DNS integration should have their DNS Client server  address set as their counterparts to avoid “island” effects. Secondary entry should be their loop-back interface – rather than their routable IPs for increased querying efficiency.

The DNS Client service queries the DNS servers in the following order:

  1. The DNS Client queries the first DNS server on the preferred adapter’s list of DNS servers and waits 1 second.

  2. If the DNS Client receives no response, then it queries to the first DNS servers on All Adapters and waits 2 seconds.

  3. If the DNS Client still receives no responses, it queries all DNS servers on All Adapters and waits another 2 seconds.

  4. If no responses again, it queries to all DNS servers on all adapters and waits 4 seconds.

  5. If void condition persists, the DNS client sends queries to all DNS servers on all adapters and waits 8 seconds for a response.

  6. Finally, the DNS client gives up and curses mother nature.

Leave a Reply

Your email address will not be published. Required fields are marked *