AD SPACE AVAILABLE · BRAND PARTNERS WELCOME

Put 365 Wiki to work with your AI

Copy the prompt below, paste it into the AI you already use, then ask your question.

Download full Skill

Try it with the prompt first. If you use 365 Wiki often, install the full 365Wiki Skill so you do not have to paste it again. No regular AI? Gemini or Microsoft Copilot on the web will work.

365Wiki Skill

i365Finds Editorial is the independent research and editorial organization behind 365 Wiki. We follow changes in tools, products, services, entertainment, and digital life around the world, turning scattered and fast-moving information into clearly sourced, well-structured public content that is easier to understand and compare.
Indexed 90,207 Wiki articles

How Custom DoH Leaks DNS Queries Alongside Open-Source VPN Clients

Johanna Simantke · 365Finds Editorial

You configure WireGuard or OpenVPN to route all traffic through an encrypted tunnel, and then you enable custom DNS-over-HTTPS (DoH) in your browser or a local resolver daemon like cloudflared or dnscrypt-proxy. The goal seems obvious: you get the tunnel privacy of an open-source VPN while retaining full control over DNS filtering, ad blocking, and query logging.

At 365Finds, we see privacy-conscious engineers assemble this exact combination constantly. It looks airtight on paper. Yet in practice, this hybrid setup routinely leaks plaintext DNS queries directly to the local network gateway and ISP listeners.

The leak does not happen because WireGuard or DoH cryptography failed. It happens because DoH and open-source VPNs operate at fundamentally different network layers. When your operating system reconciles application-level socket bindings against kernel-level TUN/TAP routing tables, several hidden bypass paths emerge.


The Root Architectural Conflict: Layer 3 Tunnel vs. Layer 7 Resolver

An open-source VPN client like WireGuard creates a virtual Layer 3 network interface (typically wg0). It routes raw IP packets by manipulating kernel routing tables and policy rules (ip rule and AllowedIPs = 0.0.0.0/0, ::/0). WireGuard itself does not process DNS queries; it merely transports whatever IP packets the OS feeds into wg0.

DoH, defined in RFC 8484, wraps DNS request wire formats inside standard HTTP/2 or HTTP/3 sessions encrypted via TLS on TCP port 443. It is an application-layer service.

When you point an application or local stub resolver to a custom DoH endpoint, you sever the default link between the VPN tunnel's internal DNS resolver and the host operating system. The OS network stack now treats that DNS traffic as arbitrary HTTPS packets or splits name resolution across competing interfaces.

This architectural mismatch triggers DNS leaks through four primary vectors.


1. The Bootstrap Resolution Paradox

A DoH client cannot connect to an HTTPS URL without knowing the IP address behind the hostname. If your custom DoH URI is:

https://dns.nextdns.io/abc123

Your system faces a chicken-and-egg dilemma: it must resolve dns.nextdns.io before it can establish the TLS handshake for DoH.

How does the client resolve that bootstrap hostname? In most setups, the browser or resolver daemon falls back to the system’s standard getaddrinfo() call. If the VPN client has not completed its handshake, or if the local network resolver is queried prior to tunnel establishment, that initial query goes straight out of the physical interface (eth0 or wlan0) as an unencrypted UDP port 53 query to your local router or ISP resolver.

Anyone sniffing the local network—a coffee shop router, a hotel Wi-Fi gateway, or your ISP—immediately sees:

Even after the DoH session is up, many clients re-resolve bootstrap hostnames periodically. If routing tables shift or a network interface flaps, those subsequent bootstrap lookups bleed onto the local link in plaintext.


2. OS-Level Socket Bindings and SO_BINDTODEVICE Bypass

On modern Linux distributions, name resolution is managed by systemd-resolved or NetworkManager. When an open-source VPN client comes online, it attempts to set interface-specific DNS configurations.

However, Linux manages DNS on a per-link basis. Physical interfaces (eth0, wlan0) retain DHCP leases and upstream nameservers assigned by the local network. If the VPN client does not explicitly strip the global routing domain (~.) from the physical interface, systemd-resolved maintains multiple active resolvers simultaneously.

Furthermore, several local stub resolvers and system services bind their sockets directly to a physical network device using the socket option:

setsockopt(sock, SOL_SOCKET, SO_BINDTODEVICE, "eth0", sizeof("eth0"));

When a socket is bound to a physical network device via SO_BINDTODEVICE:

  1. The Linux kernel skips standard routing table evaluation.
  2. The packet bypasses the policy routing tables created by wg-quick or OpenVPN.
  3. Outbound DNS packets egress directly through the physical NIC onto the local LAN.

If your custom DoH forwarder or local stub resolver runs before the VPN interface is registered, or if it explicitly anchors to the primary interface to preserve an external gateway route, every query it generates exits outside the TUN interface completely unencrypted.


3. Silent Fallbacks: The Opportunistic DoH Trap

Most browser-based DoH configurations default to opportunistic or fallback modes. In Firefox, the Trusted Recursive Resolver (TRR) engine operates in several modes:

ModeNameBehavior
0DisabledStandard OS resolver only.
1ReservedDynamic selection based on response times.
2TRR FirstAttempts DoH first; silently falls back to native OS DNS on error or timeout.
3TRR OnlyStrict DoH. Fails immediately if DoH fails; never falls back to OS DNS.
5Explicitly DisabledUser opted out of TRR completely.

The default in many consumer implementations is Mode 2 (TRR First). If your open-source VPN resets its MTU, drops a keepalive handshake, or encounters temporary latency, the browser’s DoH query times out.

Instead of displaying a network error, the browser silently issues a standard, unencrypted UDP port 53 request to the operating system's native resolver. If the OS resolver points to your local router (192.168.1.1), that failed query leaks across the local subnet in cleartext. You believe your browsing is protected by both WireGuard and DoH, while a network observer captures your entire browsing history through silent fallbacks.


4. Windows Smart Multi-Homed Name Resolution (SMHNR)

On Windows, combining an open-source VPN (such as the standard OpenVPN GUI or community WireGuard client) with custom DoH creates an even more aggressive leak vector.

Windows utilizes Smart Multi-Homed Name Resolution (SMHNR). When an application requests domain resolution without binding to a specific adapter, Windows sends DNS queries across all active network interfaces simultaneously—including Wi-Fi, Ethernet, and the virtual TAP/TUN adapter. Whichever adapter returns a response first is accepted; the other responses are discarded.

If you run a custom DoH forwarder on localhost (127.0.0.1:53) or configure custom DNS without locking down the Windows DNS client:


Diagnosing Active Leaks on Your System

At 365Finds, we test resolver behavior by inspecting raw packet egress at the physical interface while the VPN tunnel is running. You should not rely solely on web-based leak test pages, which often test only browser-level resolution.

Step 1: Monitor the Physical Interface for Port 53 Traffic

Run tcpdump on your physical network interface (not the wg0 or tun0 interface):

sudo tcpdump -i eth0 -n "udp port 53 or tcp port 53 or port 853"

Replace eth0 with your actual Wi-Fi or Ethernet interface name (wlan0, enp3s0). While this capture is running, browse several domains and initiate application traffic. If you see any packets captured, your system is leaking DNS queries outside the VPN tunnel.

Step 2: Inspect systemd-resolved Link Scopes (Linux)

Check which interfaces claim the default routing domain (~.):

resolvectl status

Examine the output carefully:


How to Prevent DNS Leaks with Custom DoH and Open-Source VPNs

If you choose to run custom DoH alongside WireGuard or OpenVPN, you must enforce strict routing boundaries at both the system and network layers.

1. Hardcode Bootstrap IPs to Eliminate Plaintext Lookups

Never provide a bare domain name as the upstream DoH endpoint in resolver daemons. Always specify the server's static IP address directly, or populate your local /etc/hosts file with the resolver's IP:

# /etc/hosts entry to prevent bootstrap DNS leaks
94.140.14.14    dns.adguard-dns.com

In cloudflared or dnscrypt-proxy, configure bootstrap nameservers that point exclusively to the VPN's internal gateway IP, never the local DHCP gateway.

2. Lock Down systemd-resolved Routing Scopes (WireGuard on Linux)

Ensure your WireGuard configuration forces systemd-resolved to channel all queries into wg0 and actively revokes default routing scopes from physical adapters.

Add these directives to /etc/wireguard/wg0.conf:

[Interface]
Address = 10.200.0.2/24
PrivateKey = <YourClientPrivateKey>
DNS = 10.200.0.1

# Enforce global DNS exclusivity on wg0
PostUp = resolvectl dns %i 10.200.0.1; resolvectl domain %i '~.'; resolvectl default-route %i true
PreDown = resolvectl revert %i

If you forward DNS locally through a DoH proxy listening on 127.0.0.1:53, set DNS = 127.0.0.1 and verify that the DoH daemon's outbound HTTPS traffic is routed through wg0 via AllowedIPs = 0.0.0.0/0, ::/0.

3. Enforce Strict DoH Mode (Disable Fallback)

In Firefox, switch TRR from opportunistic Mode 2 to strict Mode 3:

  1. Type about:config in the address bar.
  2. Search for network.trr.mode.
  3. Set the value to 3.

In Mode 3, if the DoH server is unreachable or the VPN tunnel stutters, name resolution simply fails. The browser will never fall back to plaintext OS lookups.

4. Block Outside DNS on Windows (OpenVPN)

If using OpenVPN on Windows, prevent SMHNR from querying external adapters by adding this directive to your .ovpn configuration:

block-outside-dns

This instructs the Windows Filtering Platform (WFP) to drop any DNS requests directed to network interfaces other than the TAP/TUN adapter.

5. Deploy a Hard Network-Layer Firewall Kill Switch

Software configurations can fail during updates or service crashes. The only definitive guarantee against DNS leaks is a kernel-level packet filter that drops all outbound UDP and TCP port 53 traffic on physical interfaces.

Example rules using nftables:

table inet filter {
    chain output {
        type filter hook output priority 0; policy accept;

        # Allow DNS queries inside the VPN tunnel interface
        oifname "wg0" udp dport 53 accept
        oifname "wg0" tcp dport 53 accept

        # Allow local loopback DNS (if running a local DoH proxy)
        oifname "lo" udp dport 53 accept
        oifname "lo" tcp dport 53 accept

        # Drop all plaintext DNS queries attempting to exit the physical network card
        oifname "eth0" udp dport 53 drop
        oifname "eth0" tcp dport 53 drop
        oifname "wlan0" udp dport 53 drop
        oifname "wlan0" tcp dport 53 drop
    }
}

With this packet filtering rule in place, an application attempting a bootstrap lookup or opportunistic fallback cannot transmit a single plaintext packet to your local network.


365Finds Practical Assessment

Layering custom DoH on top of an open-source VPN provides fine-grained control over recursive resolvers and query filtering. But stacking security protocols without binding their interfaces creates an illusion of privacy.

When you decouple DNS resolution from the VPN tunnel’s native nameserver, your operating system defaults to convenience over isolation. It will happily route queries out of the physical Ethernet or Wi-Fi card the moment a latency spike or bootstrap lookup occurs.

Unless you explicitly pin bootstrap IPs, disable opportunistic fallbacks, and block physical port 53 traffic at the firewall level, custom DoH alongside an open-source VPN client will regularly expose your DNS queries to local network listeners.


References