Skip to content

Instantly share code, notes, and snippets.

@flipeador
Last active May 23, 2025 00:39
Show Gist options
  • Save flipeador/040499104f000ba507f4d6b5667aec7a to your computer and use it in GitHub Desktop.
Save flipeador/040499104f000ba507f4d6b5667aec7a to your computer and use it in GitHub Desktop.
Configure AdGuard DNS (Encrypted) in Windows 11 with PowerShell.
# Configure the public AdGuard DNS server with DoH (Encrypted) programatically in W11.
# https://adguard-dns.io/en/public-dns.html#:~:text=Configure%20AdGuard%20DNS%20manually
# Define AdGuard DNS servers and their DoH template.
$servers4 = @(
# IPv4 default servers: block ads and trackers.
@{ address = "94.140.14.14"; template = "https://dns.adguard-dns.com/dns-query" },
@{ address = "94.140.15.15"; template = "https://dns.adguard-dns.com/dns-query" }
)
$servers6 = @(
# IPv6 default servers: block ads and trackers.
@{ address = "2a10:50c0::ad1:ff"; template = "https://dns.adguard-dns.com/dns-query" },
@{ address = "2a10:50c0::ad2:ff"; template = "https://dns.adguard-dns.com/dns-query" }
)
$addresses4 = $servers4 | ForEach-Object { $_.address }
$addresses6 = $servers6 | ForEach-Object { $_.address }
# Register each AdGuard DNS server with its DoH template
foreach ($server in $servers4 + $servers6) {
Add-DnsClientDohServerAddress `
-ServerAddress $server.address `
-DohTemplate $server.template `
-AllowFallbackToUdp $False `
-AutoUpgrade $True
}
# Detect active Wi-Fi/Ethernet network adapter.
$adapter = Get-NetAdapter |
Where-Object { $_.Name -match "^(Wi-Fi|Ethernet)" -and $_.Status -eq "Up" } |
Select-Object -First 1
if (-not $adapter) {
Write-Error "No active network adapter found. Please check your network connection."
exit 1
}
# Apply the DNS servers to the detected active adapter.
$alias = $adapter.InterfaceAlias
$addresses = $addresses4 + $addresses6
Set-DnsClientServerAddress -InterfaceAlias $alias -ResetServerAddresses
Set-DnsClientServerAddress -InterfaceAlias $alias -ServerAddresses $addresses
# Enable DoH automatic template for the detected active adapter.
$guid = $adapter.InterfaceGuid.ToLower()
$rkey = "HKLM:\System\CurrentControlSet\Services\Dnscache\InterfaceSpecificParameters\$guid"
$addresses = @{ "Doh" = $addresses4; "Doh6" = $addresses6 }
foreach ($type in $addresses.Keys) {
$key = "$rkey\DohInterfaceSettings\$type"
foreach ($address in $addresses[$type]) {
New-Item -Path $key -Name $address -Force | Out-Null
New-ItemProperty -Path "$key\$address" -Name "DohFlags" -Value 1 -PropertyType QWord -Force | Out-Null
}
}
@flipeador
Copy link
Author

flipeador commented Apr 18, 2025

Configure AdGuard DNS (Encrypted)

Instructions

Open the Windows Terminal as Administrator and run the PowerShell script.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment