Clash DNS Leak Test & Prevention Guide

Learn what causes DNS leaks and how to test for them. Covers mihomo settings for enhanced-mode, nameserver-policy, respect-rules, and TUN DNS hijacking.

How to tell if DNS is leaking

Routing web traffic through a proxy doesn’t mean DNS queries follow the same route. A browser may use its own secure DNS, while an app may resolve a domain through the system before sending the IP address through the proxy. A leak occurs when public domains you intended to resolve through a specific resolver are instead queried through your router’s ISP-provided DNS. Internal queries deliberately sent to a corporate DNS server are a different case.

  • Web traffic egress: The IP address shown by a website tells you where that web connection exits.
  • DNS resolver egress: Leak tests typically identify the recursive resolver or forwarding server that queries the test domain’s authoritative server. It may differ from the configured connection IP and may not be in the same city as your web traffic egress.
  • Local outbound path: This determines which network interface sends a query, which protocol it uses, and whether it goes through a proxy. DoH encrypts queries between your device and the resolver, but direct DoH and DoH through a proxy take different routes.

DNS leak testing: compare browser, system, and core behavior

  1. Establish a baseline. On a network where temporarily disabling the proxy is acceptable, turn off the client’s system proxy and TUN mode, then use a trusted DNS leak test to record resolver IPs and organizations. Prefer an extended test that issues fresh domain queries for each round. If disabling the proxy isn’t appropriate, skip this step and check the expected upstream resolvers instead.
  2. Isolate browser settings. In Firefox, check the setting under Settings → Privacy & Security → DNS over HTTPS. For diagnosis, temporarily turn it off and test the system resolver path, then restore your usual setting and test again. If extra resolvers appear only when secure DNS is enabled, check which provider the browser selected and where its connections go.
  3. Test each proxy entry point separately. Test once with only the system proxy enabled, once with only TUN enabled, then test again using your usual settings. Keep the same node and rule mode for each round, and record resolver IPs, organizations, and client logs. The system proxy affects only traffic that uses that proxy setting; it doesn’t reveal the DNS path used by other apps.
  4. Compare system queries with the core listener. On Windows, run nslookup example.org to query the default server, and use PowerShell’s Get-DnsClientServerAddress to check DNS addresses for each interface. If dig is installed and the core listener described below is enabled, run dig @127.0.0.1 -p 1053 example.org A to test the core directly.

Don’t treat command output as a record of the upstream resolver: nslookup shows the server address it uses, which may not be the component handling queries after TUN takes over. A dig query to 127.0.0.1 only confirms that the core listener is reachable. To check whether unexpected plaintext DNS leaves through a physical network interface, inspect UDP and TCP traffic on port 53 on that interface. Seeing no 53 traffic doesn’t rule out apps resolving names independently over HTTPS.

mihomo DNS settings: Fake-IP and upstream routing

The examples below use mihomo (Clash Meta) fields. First confirm which core the client is actually running, then back up your current configuration. If the client periodically refreshes a subscription, put your changes in a supported override location. After applying them, inspect the effective configuration—not just the text in the editor. If a dns: section already exists, merge the entries into it; don’t add a second top-level key with the same name.

config.yaml · DNS snippet
dns:
  enable: true
  listen: 127.0.0.1:1053
  enhanced-mode: fake-ip
  fake-ip-range: 198.18.0.1/16
  fake-ip-filter:
    - "+.home.arpa"
  nameserver:
    - "https://1.1.1.1/dns-query"
  nameserver-policy:
    "+.home.arpa":
      - 192.168.1.1

enhanced-mode: choose which addresses clients receive

fake-ip can return synthetic addresses to clients. When the core handles the connection that follows, it uses its mapping to recover the original domain and apply the rules. If an A query for a public domain returns 198.18.x.x, it matched the example’s synthetic address range; that doesn’t mean a real upstream lookup completed, nor does it prove there was no leak. For domains that need real addresses, add narrowly scoped exceptions in fake-ip-filter. redir-host uses actual DNS results instead.

nameserver-policy: choose the resolver for specific domains

This example sends home.arpa and its subdomains to 192.168.1.1, while other queries use nameserver. Keep this policy only if your router actually handles that local domain, and replace the address with the correct server. If you don’t have a local domain, remove the example filter and policy entries. The filter controls whether synthetic addresses are returned; the policy determines which upstream resolver receives the query. Adding a corporate suffix to the filter list does not prevent queries from being sent to a public upstream.

respect-rules: route DNS upstream connections through rules

nameserver-policy selects the resolver; respect-rules makes the core follow routing rules when connecting to it. If you want the DoH server mentioned above to use the proxy, adding only its HTTPS address isn’t enough. Merge these three keys into your existing dns: section. proxy-server-nameserver is specifically used to resolve proxy node hostnames and is required when respect-rules is enabled.

config.yaml · merge under dns
  respect-rules: true
  prefer-h3: false
  proxy-server-nameserver:
    - "https://9.9.9.9/dns-query"
  1. In your existing rules: section, put IP-CIDR,1.1.1.1/32,Proxy,no-resolve before any direct rules that would match first and before the final MATCH. Replace Proxy with the exact name of an existing group that selects a proxy node, not DIRECT.
  2. If you keep the local resolver policy, make sure 192.168.1.1 matches a LAN direct rule, such as IP-CIDR,192.168.1.1/32,DIRECT,no-resolve placed before the fallback rule. Don’t send a local resolver to a remote server just to proxy public DoH traffic.
  3. The node-resolution upstream must work before the selected node is connected. 9.9.9.9 is only a candidate address; check that it’s reachable on your network. Don’t make its reachability depend on the node it needs to resolve. After saving, restart the core, check that the first node connects, then test web and DNS resolver egress again. If node hostname resolution times out, check this startup path first.

TUN DNS hijacking: intercept UDP and TCP port 53

Here, “hijacking” means handing regular DNS traffic entering TUN to the core’s DNS module. The example intercepts both UDP and TCP because clients may fall back to TCP when a response is truncated. First make sure the client has the system permissions it needs for TUN, then verify that the route is actually active after applying the configuration.

config.yaml · TUN snippet
tun:
  enable: true
  auto-route: true
  auto-detect-interface: true
  dns-hijack:
    - "any:53"
    - "tcp://any:53"

any:53 doesn’t cover every DNS protocol, and it can’t intercept traffic that never enters TUN. Browser DoH usually uses 443; Android’s strict Private DNS uses DoT, typically on 853. The port 53 rule above won’t convert either connection into a DNS query handled by the core. Either keep the app’s separate resolution path as intended and verify its outbound route, or—if device policy allows—disable the app’s independent resolver so it uses the system path.

If the system still sends queries to the router on the physical interface’s subnet, first check whether that traffic actually enters TUN. Don’t assume it’s intercepted just because dns-hijack is configured. Multiple network interfaces, a work VPN, and route exceptions can all change the path. See TUN mode setup to check the active interfaces and routes. Avoid overriding settings provided by a corporate network just for testing.

Retest and rollback: troubleshoot by symptom

Test result and what to check next
SymptomCheck first
Web traffic egress has changed, but the test still shows an unexpected ISP resolverTest browser secure DNS, the system’s default resolver, and TUN interception separately. Check the physical interface for unexpected UDP or TCP traffic on port 53.
A local domain returns a synthetic address or fails to resolveCheck that the domain suffix matches both fake-ip-filter and nameserver-policy, then confirm the local resolver is reachable and actually hosts the domain.
Nodes time out during startup after enabling respect-rulesFirst check that the node-resolution upstream is reachable independently, then check the DoH address’s rule order and proxy group selection.
The issue appears only after switching network interfacesRecheck routes and DNS addresses for each interface, then inspect IPv4 and IPv6 paths separately. Receiving an AAAA record alone is not evidence of a leak.

Change one setting at a time, apply it, and retest with a fresh query. Test a public domain, a known internal domain, and a cold node startup separately. If the network goes down, undo the latest DNS or TUN override first, then reload your backup and check that the system proxy and DNS settings have returned to their previous state. Keep a record of the expected resolvers and proxy group selection so you can compare after switching networks or updating a subscription. See the DNS section under Advanced Config for field definitions.

Download Clash