Posted On July 9, 2019

PowerShell: Set DNS Servers on Localhost

kimconnect 0 comments
blog.KimConnect.com >> Codes , Networking >> 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 {192.168.1.5, 127.0.0.1}
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 {192.168.1.5, 127.0.0.1}
isatap.{65BFBD6D-9E20-4A2... 7 IPv6 {::1}

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

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

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 *

Related Post

PowerShell: Set PasswordNeverExpires on SamAccountName

Quick 1-liner Code $accounts=@( 'orange', 'apple', 'pear', 'dog', 'cat', 'dinosaur', 'chicken', 'cow', 'yomama', 'yodada' )…

List Autorun Services

# $cred = get-Credential -credential kdoan-a $Username = 'kimconnect\kim-Admin $Password = 'PASSWORD' $pass = ConvertTo-SecureString…

PowerShell: How to Send Key Strokes to a Program Graphical User Interface

# WARNING: there's a kill-process command when the target program is already running # so…
Other project: DragonCoin.com