Setting Google DNS with powershell
My local ISP's router won't let me modify dns settings in it's dhcp table. (no drew Joy), now I'm going to have to add a separate router.. while I waiting for my router, I created the following powershell code to point my boxes to google dns.
The following PS code will:
- look for a nic with an active gateway
- apply google dns server definitions for both ipv4 and ipv6
Tested on Windows 8.1, 10, W2k12R2, W2k16
#requires admin ps (changing dns), Powershell 3+ (use $PSVersionTable to PS version)
#CODE
|
|
#
Updated the following for CloudFlare DNS
# Show current settings
Get-DnsClientServerAddress
# look for nic w/ gateway
$GWNic=(Get-NetIPConfiguration -All |Where {$_.IPv4DefaultGateway -ne $null}).interfaceindex
# set dns servers to both ipv4/ipv6, #Reference: https://blog.cloudflare.com/dns-resolver-1-1-1-1/
Set-DnsClientServerAddress -InterfaceIndex $GWNic -ServerAddresses ("1.1.1.1","1.0.0.1","2606:4700:4700::1111","2606:4700:4700::1001")
# Confirmation
Get-DnsClientServerAddress