V2Ray DNS Leak Test and Prevention: v2rayN and v2rayNG DNS Setup

Learn how to test for DNS leaks and configure remote DNS, TUN routing, and domain resolution in v2rayN and v2rayNG.

At a glance

Using a proxy for web traffic doesn’t mean your DNS queries use it too. If a test still shows your local network’s resolvers, first establish a baseline with the same browser and proxy disabled. Then check which traffic the browser, TUN, or VPN captures, and where remote DNS queries actually exit. Change one setting at a time so you can identify what changed the result.

DNS leaks: web traffic and DNS queries take different paths

Think of DNS as an address book: apps usually need to look up a domain’s IP address before connecting. A DNS leak occurs when a domain you expect to resolve through the proxy is instead sent to your local network or another unexpected resolver. If you’ve explicitly set a site to bypass the proxy, using a local resolver is expected routing behavior. The key is knowing which queries are supposed to bypass it.

App sends queryClient captures itResolution policy matchesOutbound route selectedResolver responds

This simplified flow applies only to queries captured by the client. On desktop, a system proxy mainly affects apps that honor the system proxy settings; it doesn’t automatically capture the operating system’s DNS traffic. If your browser uses Secure DNS, it may also send queries over HTTPS to a resolver chosen by the browser. Whether that HTTPS connection uses the proxy depends on traffic capture and routing rules.

How to test for DNS leaks: establish a baseline, then test the proxy

  1. Record a baseline: On a network where you don’t need a proxy, temporarily turn off your proxy and VPN. In the same browser, visit a DNS leak test that lists recursive resolvers. Note the network type, browser Secure DNS status, resolver addresses, and providers. If you can’t disable the proxy, skip the baseline and compare the expected resolvers with the client logs instead.
  2. Keep conditions consistent: Re-enable the proxy and keep the current node, routing mode, and network unchanged. Use the test page’s retest option to trigger a fresh round of queries; don’t compare against a result from an earlier session. Test pages usually use different domains for each round, making cached results less likely than when you repeatedly open a familiar site.
  3. Separate browser and system behavior: If Secure DNS is enabled in your browser, temporarily turn it off and run another test in the same mode, then restore it. On Windows, you can also run the command below to check whether system DNS resolution works. The command doesn’t specify a server and doesn’t prove that your browser uses the same route.
Resolve-DnsName -Name example.com -Type A -DnsOnly
What you seeWhat to check first
The web exit changes, but the resolver matches the baselineCheck browser Secure DNS, whether the app is captured, and whether the resolver connection matches a bypass rule. A matching result is a clue, not conclusive proof.
Multiple resolvers appear, or the resolver and proxy node are in different regionsIdentify the provider first, then look at the addresses. Public resolvers may use multiple exits; neither their location nor their number proves a leak on its own.
The test page looks as expected, but another app still has problemsCheck whether the app is covered by TUN or VPN capture and whether it uses its own resolver. A browser test only checks the browser that ran it.

First identify which queries are taking the wrong route

If changing Secure DNS affects only the browser’s test results, troubleshoot the browser’s DNS path first. Don’t change the proxy node and client DNS at the same time. A test page shows the recursive resolver that handled its query. To confirm which outbound route the client used to reach that resolver, check the logs or actual network traffic.

v2rayN: remote DNS and TUN traffic capture

Remote DNS specifies a resolver; TUN determines which traffic can enter the client. They solve different problems: setting a remote DNS server won’t make apps that bypass the client use the proxy. The steps below use the common v2rayN 7.x interface. Spacing and field layout may vary by minor version and selected core.

  1. Note your current settings

    In the main window, note the current node, system proxy status in the bottom bar, and routing configuration. Open Settings → DNS Settings and record the existing DNS configuration for your selected core. If the interface provides a custom configuration editor, keep a copy of its contents; don’t paste a single URL as if it were a complete configuration.

  2. Set a remote DNS server

    If the interface has a Remote DNS field that accepts DoH URLs, https://1.1.1.1/dns-query is an example of the address format. DoH uses HTTPS on port 443 by default; conventional DNS typically uses port 53. Entering an address selects a resolver, but doesn’t determine whether its connection uses the proxy or bypasses it. Keep the existing direct DNS setting for comparison and rollback.

  3. Enable TUN

    Return to the bottom bar of the main window, enable TUN, and grant permission if prompted. If the app you’re testing originally used the system proxy, set System Proxy to Clear System Proxy to check whether TUN works on its own. Don’t change the node or routing mode at the same time. Note the original setting so you can restore it afterward.

  4. Check the outbound route and test again

    Repeat the test in the same browser and check the main window logs for the resolver address and its matching outbound route. If the resolver matches a direct rule, open Settings → Routing Settings and check the active configuration and rule order. If there’s no outbound entry, don’t assume that a working webpage proves the connection used the proxy.

v2rayNG: remote DNS and Android VPN traffic capture

On Android, v2rayNG’s VPN mode captures traffic through a virtual network interface provided by the system. The VPN icon in the notification bar shows that the system VPN is connected, but it doesn’t mean every app is included or that DNS queries exit through the proxy.

  1. Check the operating mode: Open Settings from the top-left menu. If there’s an Operating Mode option, choose VPN Mode rather than a mode that only provides a local proxy port. Return to the main screen and connect, then accept the system’s VPN connection request the first time you use it.
  2. Check DNS settings: In Settings, find Remote DNS and Direct DNS. The remote setting serves the relevant proxy resolution path, while the direct setting serves the relevant bypass path; actual behavior depends on the generated configuration and routing rules. If the interface has an Enable Local DNS option, it enables DNS handling in the client—it doesn’t switch to your router’s DNS. Disconnect and reconnect after making changes, then check the results.
  3. Check which apps are included: If Per-App Proxy is enabled, make sure the test browser is covered by VPN capture. The app list may mean “include only selected apps” or “exclude selected apps.” Seeing the browser checked isn’t enough to tell which route it takes.
  4. Test encrypted DNS separately: If results still don’t match expectations, check Secure DNS in the browser first. Then search Android system settings for Private DNS and note whether a provider is specified. These are separate settings. If you need to change one temporarily, change only one at a time and restore it after testing. In particular, don’t enter a Private DNS provider hostname in the client’s DoH URL field, or vice versa.

Domain resolution strategy: when should you change it?

Consider changing domainStrategy in Xray routing only if you need IP rules to apply to domain-based traffic. It controls whether a domain is resolved to an IP address for routing matches; it doesn’t determine which outbound route DNS queries must use. Changing it won’t replace remote DNS settings or expand TUN’s coverage.

AsIs
Routing rules use the destination as provided and don’t resolve the domain just to check for a match. A later step may still resolve it when the actual connection is made.
IPIfNonMatch
If no rule matches a domain destination on the first pass, try resolving it and matching by IP. If a catch-all rule already matches on the first pass, the client won’t resolve the domain again just because IP rules exist.
IPOnDemand
A rule that requires an IP address can trigger resolution during routing. Rule order affects when this happens; it doesn’t mean every domain is resolved first.

If domain-based routing already works as expected but a test still shows an unexpected resolver, check the DNS query’s outbound route first. Don’t switch to IPOnDemand just to address a leak. Also, an IPv6 AAAA record query and whether the DNS request itself uses IPv4 or IPv6 are separate things. Restricting returned record types doesn’t guarantee the query won’t take another network path.

Common errors and how to roll back

Here are examples of errors that may appear in the logs. The same error can also come from a connection to a proxy node rather than DNS. First check whether the preceding log entries refer to a node address, resolver address, or destination.

Error: i/o timeout

Cause and fix: A connection or query didn’t complete in time. If the log points to a DoH resolver, check whether its connection on port 443 uses the expected outbound route. Then restore the original DNS setting and compare to tell whether the resolver is unreachable or the node itself is disconnected.

Error: no such host

Cause and fix: The hostname shown in the log couldn’t be resolved to a usable address. Check the spelling first. If you’ve just switched to a DoH URL with a hostname, check whether the client can resolve the server name before DoH is connected.

Error: x509: certificate signed by unknown authority

Cause and fix: The client can’t trust the server’s certificate chain. Confirm the log points to the expected DoH service, then check system trust settings and whether the network performs managed HTTPS inspection. Don’t disable certificate verification to continue connecting.

If webpages stop loading across the entire device after a change, undo the most recent change first. If that doesn’t help, restore the original DNS settings, then return TUN or VPN and the system proxy to their previous states. Once the original connection works again, test one setting at a time in this order: system or app capture, remote DNS, then routing rules. For each step, record the result from the same test page and the corresponding logs.

Download v2rayNChoose a client for your platform