Clash DNS Leak Test & Prevention: fake-ip and nameserver-policy Guide
Learn how to detect DNS leaks, compare fake-ip and redir-host, configure nameserver, fallback, and nameserver-policy, and verify your setup.
How to Identify a DNS Leak: Check Resolvers and Traffic Routes Separately
A DNS leak occurs when queries take an unintended resolution path. For example, public domain queries may be configured to go through mihomo and then to a specified encrypted DNS upstream, but the browser may send them in plaintext to the router through the system resolver. By contrast, sending home.arpa to your home network's resolver is intentional split DNS, not a leak.
Start by distinguishing three addresses: the DNS endpoint an app sends queries to, the upstream resolver selected by the core, and the public egress IP used for application traffic. The IP shown by a website is the third one; DNS leak test pages usually show the recursive resolver that looked up the test domain, or its egress IP. A mismatch between these addresses does not indicate a leak, and a resolver's location does not prove whether queries went through a proxy.
- Keep the client in its current working mode. Note the system DNS settings, the browser's Secure DNS status, and the expected public and LAN upstreams. If both the system proxy and TUN are enabled, record that too.
- Run a DNS leak test in your browser and note the resolver names and addresses. If the results differ from what you expect, change one setting at a time and test again. For example, in Chrome, check “Use secure DNS” under Settings → Privacy and security → Security, and compare results with the feature on and off. Restore the original setting afterward unless you decide to change your DNS policy.
- Run a second comparison using the system resolver. On Windows, run
Resolve-DnsName example.org -Type A -DnsOnly; on Linux with systemd-resolved, runresolvectl query example.org. These commands check the system's DNS path and do not replace browser testing. For retests, use a newly generated test domain to avoid cached results.
fake-ip vs. redir-host: Different Addresses Returned to Apps
dns.enhanced-mode determines how the core responds to DNS queries. With fake-ip, ordinary domains can receive synthetic addresses, with the domain-to-address mapping stored by the core. When an app connects to that address, the core recovers the domain along the intercepted traffic path and selects an egress according to its configuration. With redir-host, the app receives the actual resolved address. Both modes can use encrypted upstreams; choosing one mode alone will not prevent DNS leaks.
| Mode | A record returned to the app | What to check |
|---|---|---|
fake-ip |
Ordinary domains can receive a synthetic address from the configured 198.18.0.1/16 address pool. |
Subsequent connections must pass through a core that recognizes the mapping. Domains that require real addresses can be excluded individually. |
redir-host |
Returns the real IPv4 address. | Check connection logs to confirm the domain works and which rule it matches; a real address alone does not show which DNS path was used. |
mihomo DNS Configuration: Default Upstreams, LAN Policies, and Fallback Resolvers
The following example is for mihomo, the successor project to Clash Meta. Merge it into the existing dns section; do not add a second key with the same name. If your GUI client merges subscription settings through overrides, check the configuration actually loaded by the core after saving. Older Clash versions and clients using other cores may not support the same fields. This example sends public queries to a DoH upstream and routes home.arpa queries to a LAN DNS server. Keep the LAN entry only if that zone is configured on your network, and replace 192.168.1.53 with the address of your actual resolver.
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
fallback:
- https://9.9.9.9/dns-query
fallback-filter:
geoip: false
ipcidr:
- 0.0.0.0/32
nameserver-policy:
'+.home.arpa':
- 192.168.1.53
nameserverprovides the regular upstream for resolving queries; queries matched bynameserver-policyuse the resolver specified by that policy. The LAN entry uses regular DNS, so queries to192.168.1.53:53on the LAN interface are expected.fallbackis not a standby server that only comes online after the primary times out. For queries on the default resolution path, the core can query both upstream groups in parallel and choose a result based on the filtering criteria. This example disables GeoIP filtering and lists0.0.0.0/32as one condition for selecting a fallback result. If you want queries to reach only one public DNS provider, removefallbackandfallback-filter; filtering criteria do not restrict where queries are sent.listenopens port1053on the local machine for targeted testing. Adding this field does not automatically change system DNS settings or redirect apps' existing requests to port53to the core. If the port is already in use, check the startup logs, choose another port, and update your test commands accordingly.
DoH encrypts the connection between you and the DNS provider; it does not mean that connection goes through a proxy. nameserver-policy selects a server, not the route used to reach it. To route DNS upstream connections according to your rules, check the respect-rules setting for your mihomo version. If you enable it, also configure proxy-server-nameserver to give node hostnames a separate resolution path, so the proxy does not need to be established before it can resolve its own nodes.
TUN DNS Handling: Check Routes Before Ports
With system proxy mode alone, apps that read the proxy settings may send domain names to the proxy or resolve them locally first. TUN intercepts traffic at the virtual network adapter and routing layer, but enabling TUN does not guarantee that every DNS query reaches the core. First confirm that TUN is running in the client, then check the system routes and the active tun.dns-hijack settings.
To have the core handle regular DNS queries entering TUN, check that the hijack list includes both any:53 and tcp://any:53 to cover UDP and TCP. Excluded interfaces, route exceptions, or system handling of LAN DNS can all bypass this path. If system proxy and TUN are both enabled, test them separately during a maintenance window to find out which layer is handling the traffic.
Browser DoH usually uses HTTPS on port 443, while DoT used by systems or apps usually runs over TCP port 853. Neither matches hijack rules for port 53. If you find an unexpected resolver, first check whether an app has explicitly configured encrypted DNS. Then decide whether to use the system DNS path or keep the app's setting and include that upstream in your expected policy.
Verify the Configuration: Local Responses, Apps, and Network Interfaces
Query the Local Listener Directly
Run these queries in a terminal with dig installed. The first checks the local listener and synthetic A record from the example; the second checks whether an internal domain resolves to a real address. The example assumes your LAN DNS has an A record for nas.home.arpa. If it does not, use a record that exists on that resolver.
dig @127.0.0.1 -p 1053 example.org A +time=2 +tries=1
dig @127.0.0.1 -p 1053 nas.home.arpa A +time=2 +tries=1
With the fake-ip configuration above, the first query should return an address from the pool, but it is not expected to return a specific IP. The second should return the internal record. If a query times out, check the listening port and startup logs. If the internal query returns NXDOMAIN, confirm that the domain exists and that the override is active. A successful direct query proves only that the local endpoint works; it does not prove that apps are intercepted or that public DoH is reachable. The core can return a synthetic address first and resolve the domain as needed when application traffic arrives.
Retest After Restoring the Normal Traffic Path
- Visit a public domain in your browser while checking the client's connection logs. Confirm the domain, matched rule, and egress, then run another DNS leak test to check for unexpected recursive resolvers. If the expected DoH upstream appears but the site will not load, troubleshoot the upstream connection and application egress separately. Do not draw conclusions from the synthetic address alone.
- If you still suspect plaintext DNS is bypassing the core, inspect the actual outbound interface on a machine you are authorized to manage. Check IPv4 and IPv6 UDP and TCP traffic to destination port
53. On systems withtcpdump, runtcpdump -Dto list interfaces, then apply the filterudp dst port 53 or tcp dst port 53to the relevant interface. Look for queries to unexpected addresses during the test; do not mistake permitted LAN queries for a problem. - Not seeing plaintext traffic on port
53only means that this check did not detect that type of bypass. Also review browser Secure DNS, system encrypted DNS, and other apps that run their own resolvers. Repeat the same checks after switching Wi-Fi networks, connecting via Ethernet, or reloading a subscription, since the default interface and active configuration may change.
For a complete check, answer three questions: Which DNS providers handle public domains? Are internal domains still resolved by the LAN resolver? Do application connections use the expected egress? Keep the results for each test; they make later changes easier to diagnose than a single pass/fail status from a test page.