Last active
May 23, 2025 00:39
-
-
Save flipeador/040499104f000ba507f4d6b5667aec7a to your computer and use it in GitHub Desktop.
Configure AdGuard DNS (Encrypted) in Windows 11 with PowerShell.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Configure AdGuard DNS (Encrypted)
https://adguard-dns.io/en/public-dns.html
Instructions
Open the Windows Terminal as Administrator and run the PowerShell script.