wiki:DnsScripts

Version 9 (modified by spirillen, 2 weeks ago) ( diff )

--

Windows

Windows PowerShell DNS server switcher

This script is made to pick up My Privacy DNS server IP-addresses and then apply them as your default DNS Servers for enhanced Privacy If you’re using PS 3.0 or greater (on your local computer), then use the Using scope modifier.

Save this script as "SecureDNSSwitcher.ps1"

$NIC_PrimaryDNS = "95.216.209.53"
$NIC_SecondaryDNS = "116.203.32.67"
Invoke-command -ComputerName $Server -cred $cred -ScriptBlock {Set-DnsClientServerAddress -InterfaceAlias corp -ServerAddresses("$Using:NIC_PrimaryDNS","$Using:NIC_SecondaryDNS")}

If you’re using 2.0, then you’ll have to use parameters to pass in your local variables.

$ns0ip1 = [System.Net.Dns]::GetHostAddresses("ns0.dns.matrix.rocks")[0] | foreach {echo $_.IPAddressToString }
$ns0ip2 = [System.Net.Dns]::GetHostAddresses("ns0.dns.matrix.rocks")[1] | foreach {echo $_.IPAddressToString }
$ns1ip1 = [System.Net.Dns]::GetHostAddresses("ns1.dns.matrix.rocks")[0] | foreach {echo $_.IPAddressToString }
$ns1ip2 = [System.Net.Dns]::GetHostAddresses("ns1.dns.matrix.rocks")[1] | foreach {echo $_.IPAddressToString }

$NICs = Get-NetAdapter | where status -eq 'Up' | select -exp Name
Foreach($NIC in $NICs) {

$DNSServers = "$ns0ip1","$ns0ip2","$ns1ip1","$ns1ip2"
Set-DnsClientServerAddress -InterfaceAlias $NIC -ServerAddresses ($DNSServers)
}
Get-DnsClientServerAddress

To run the script you have to unblock the file with Unblock-File -Path "SecureDNSSwitcher.ps1" and the run it by typing .\SecureDNSSwitcher.ps1 within your PowerShell


Dns related articles
DnsDist, DnsFirewall, DnsHosts, DnsMasq, DnsScripts, DnsSetup

Attachments (1)

Download all attachments as: .zip

Note: See TracWiki for help on using the wiki.