Skip to content

Instantly share code, notes, and snippets.

@u1-liquid
Last active December 22, 2023 01:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save u1-liquid/b38cc74becc3b95d10084bd7695b3fed to your computer and use it in GitHub Desktop.
Save u1-liquid/b38cc74becc3b95d10084bd7695b3fed to your computer and use it in GitHub Desktop.
Set DNS servers
#Requires -RunAsAdministrator
Write-Output "Update DoH settings ..."
$baseRegistryPath = "HKLM:\SYSTEM\CurrentControlSet\Services\Dnscache\InterfaceSpecificParameters"
if (Test-Path $baseRegistryPath) {
Remove-Item -Path $baseRegistryPath -Recurse -Force 2>&1 | Out-Null
}
$adapters = Get-NetAdapter -IncludeHidden | Where-Object {$_.Status -ne 'Not Present'}
foreach ($adapter in $adapters) {
$interfaceGuid = $adapter.InterfaceGuid.ToLower()
$currentRegistryPath = "$baseRegistryPath\$interfaceGuid\DohInterfaceSettings"
# IPv4 DoH settings
$ipv4DohServers = @{
"1.1.1.1" = "https://cloudflare-dns.com/dns-query";
"1.0.0.1" = "https://cloudflare-dns.com/dns-query";
"8.8.8.8" = "https://dns.google/dns-query";
"8.8.4.4" = "https://dns.google/dns-query"
}
foreach ($server in $ipv4DohServers.GetEnumerator()) {
$path = "$currentRegistryPath\Doh\$($server.Key)"
New-Item -Path $path -Force 2>&1 | Out-Null
New-ItemProperty -Path $path -Name "DohTemplate" -Value $server.Value -PropertyType String -Force 2>&1 | Out-Null
New-ItemProperty -Path $path -Name "DohFlags" -Value 1 -PropertyType Qword -Force 2>&1 | Out-Null
}
# IPv6 DoH settings
$ipv6DohServers = @{
"2606:4700:4700::1111" = "https://cloudflare-dns.com/dns-query";
"2606:4700:4700::1001" = "https://cloudflare-dns.com/dns-query";
"2001:4860:4860::8888" = "https://dns.google/dns-query";
"2001:4860:4860::8844" = "https://dns.google/dns-query"
}
foreach ($server in $ipv6DohServers.GetEnumerator()) {
$path = "$currentRegistryPath\Doh6\$($server.Key)"
New-Item -Path $path -Force 2>&1 | Out-Null
New-ItemProperty -Path $path -Name "DohTemplate" -Value $server.Value -PropertyType String -Force 2>&1 | Out-Null
New-ItemProperty -Path $path -Name "DohFlags" -Value 1 -PropertyType Qword -Force 2>&1 | Out-Null
}
}
Write-Output "Update DNS settings ..."
$adapters | Set-DNSClientServerAddress –ServerAddresses ("1.1.1.1", "8.8.8.8", "1.0.0.1", "8.8.4.4") 2>&1 | Out-Null
$adapters | Set-DNSClientServerAddress –ServerAddresses ("2606:4700:4700::1111", "2001:4860:4860::8888", "2606:4700:4700::1001", "2001:4860:4860::8844") 2>&1 | Out-Null
Set-DNSClientServerAddress "Tailscale" –ServerAddresses ("100.100.100.100") 2>&1 | Out-Null
Set-DNSClientServerAddress "Tailscale" –ServerAddresses ("fec0:0:0:ffff::1", "fec0:0:0:ffff::2", "fec0:0:0:ffff::3") 2>&1 | Out-Null
Write-Output "DNS settings have been updated for all network adapters."
ipconfig /all
Read-Host -Prompt "Press any key to continue"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment