First, understand DNS upstreams, response modes, and TUN interception
Clash DNS issues usually fall into three layers: whether queries reach the core, which servers the core queries, and what address the app receives. tun.dns-hijack handles the first layer; fields such as dns.nameserver handle the second; and dns.enhanced-mode handles the third. After DNS returns an address, the connection still follows the active proxy mode and rules. Changing public DNS does not, by itself, route the connection through a proxy.
| Layer | YAML field | What to check |
|---|---|---|
| Query entry point | dns.listen、tun.dns-hijack | Does the query go to a local listening port, or enter the core with TUN traffic? |
| Upstream selection | dns.nameserver、dns.nameserver-policy、dns.fallback | Does the domain use a dedicated upstream, or the default resolver? |
| Response mode | dns.enhanced-mode、dns.fake-ip-filter | Does the app need the real address, or can it use an address mapped by the core? |
The examples below use configuration fields from mihomo 1.19.x. Older Clash versions and different clients may not support the same fields in their interfaces. When using a subscription, first check which configuration and core the client has loaded, then merge the examples using the client's supported override method. Verify the effective configuration after merging; direct edits to a subscription cache may be overwritten at the next update.
Configuring nameserver: get default resolution working first
nameserver is the default upstream for regular domain queries. Start with a single DoH upstream and bind a local test listener to the loopback address 127.0.0.1:1053. This port is for explicit queries; adding listen does not automatically move your operating system's DNS to port 1053. The example uses redir-host so you can inspect real address records directly.
dns:
enable: true
listen: 127.0.0.1:1053
enhanced-mode: redir-host
default-nameserver:
- 223.5.5.5
nameserver:
- https://dns.alidns.com/dns-query
Separate bootstrap resolution from proxy-node resolution
- Resolving the DoH server hostname:
dns.alidns.commust itself be resolved first. The example uses an IP address indefault-nameserverfor bootstrap resolution, so the configured resolver chain does not depend on a DoH endpoint it cannot yet reach. - Resolving proxy node hostnames:
proxy-server-nameserverresolves hostnames for proxy node servers. If your nodes use hostnames and other DNS queries depend on those nodes for forwarding, node resolution must work first. Do not make it depend on the same proxy connection before that connection is established. - Resolving private domains: If company or home domains are only registered on a LAN DNS server, use
nameserver-policyto route those domains to a reachable internal resolver. A public resolver may respond successfully but still return that the domain does not exist.
fallback and fallback-filter: filter by response, not timeout retries
fallback specifies another group of upstream servers. For address queries on the default resolution path, mihomo can query nameserver and fallback in parallel, then choose which result to use based on conditions such as fallback-filter. The list does not mean “wait for the first server to time out, then try the second,” and you should not assume that whichever responds fastest will be used. Queries matched by nameserver-policy use their specified upstream and are not routed by the settings below.
Merge this snippet under the existing dns: section. It explicitly disables country or region checks and demonstrates only domain routing and filtering of primary-result addresses. If you use a hostname for the fallback DoH endpoint, make sure the bootstrap resolver can resolve it.
fallback:
- https://cloudflare-dns.com/dns-query
fallback-filter:
geoip: false
ipcidr:
- 240.0.0.0/4
domain:
- '+.example.org'
domain: This example sendsexample.organd its subdomains to the fallback upstream. It demonstrates the matching scope; it is not a recommendation to use a fallback upstream for this domain.ipcidr: Use the fallback result when an address returned by the primary upstream falls within a listed network. This filters upstream responses; it does not make240.0.0.0/4a connection-routing rule.geoip: When enabled, a primary result that does not match the country or region specified bygeoip-codecan trigger the fallback result. GeoIP databases may be out of date, and the same CDN may return addresses from multiple regions, so a location mismatch is not proof of a DNS error.
If you simply need certain domains to always use a specific resolver, use nameserver-policy. If two upstreams return different addresses, first check whether the target service is reachable, then decide whether filtering is needed. Different addresses alone do not show that either response is wrong.
Choosing between fake-ip and redir-host
fake-ip: preserve domain information through address mapping
fake-ip can return an address mapped by the core to the app first. When the core receives a connection to that address, it looks up the original domain from the mapping for routing and the subsequent connection. Place the snippet below under dns: as well; a commonly used address range is 198.18.0.0/16. For an ordinary domain A query that is not excluded by a filter, a response in this range is expected—it is not the server's real address.
enhanced-mode: fake-ip
fake-ip-range: 198.18.0.1/16
fake-ip-filter:
- '+.home.arpa'
This filter syntax applies to the default blacklist filtering mode. Queries for home.arpa and its subdomains return their real resolved addresses, but the filter does not select an internal DNS server for them. To use a specific home resolver as well, configure nameserver-policy separately. If your devices use other domain suffixes, use the actual query names. Keep the client's existing compatibility entries; do not replace the entire section with this example.
redir-host: return upstream addresses to the app
Use redir-host first for comparison when an app must read or validate real addresses, or when device discovery passes DNS results to another device. If only a few domains cannot use address mapping, keeping fake-ip and filtering those domains individually is easier to troubleshoot. If the app receives a mapped address but the subsequent connection bypasses the core, the connection may fail. In that case, check the system proxy or TUN traffic path before repeatedly changing upstreams.
Configuring TUN dns-hijack: match UDP and TCP separately
dns-hijack belongs under the top-level tun: section, not dns:. It sends matching regular DNS traffic entering TUN to the core's DNS module. Make sure dns.enable is enabled, then merge the fields below into the TUN configuration the client actually uses, keeping its existing network stack and routing settings.
tun:
enable: true
dns-hijack:
- 'any:53'
- 'tcp://any:53'
any:53 matches regular UDP DNS; the second entry adds TCP port 53. Neither entry sends all network traffic to the DNS module, nor do these port rules intercept common DoH on port 443 or DoT on port 853. Enabling the system proxy alone does not enable TUN. Even with TUN enabled, platform restrictions or excluded routes may keep queries to a LAN resolver from passing through the virtual interface.
If you want an app to use the same DNS policy, first check whether it uses the system resolver or its own encrypted DNS. To verify interception, send a regular query through the system resolver, then check the core logs or the client's DNS diagnostics. Querying 127.0.0.1:1053 directly tests only the listener; it does not prove that TUN is intercepting system queries.
Verify the active configuration: from the listening port to the actual connection
Change one layer at a time. Start with a minimal configuration and confirm that resolution works, then add a fallback upstream, and finally switch the response mode or enable TUN. After reloading the configuration in the client, test the same domain and record type. If needed, clear the system or app DNS cache so an old response is not mistaken for the latest result.
- Test the local listener. If
digis installed, rundig @127.0.0.1 -p 1053 example.com A. On Windows, runnslookup -port=1053 -type=A example.com 127.0.0.1in Command Prompt. If the connection is refused or keeps timing out, first check that the core loaded the configuration, the port is not in use, and the startup logs show no errors. - Test real and mapped addresses. Check the A record with
redir-host, then switch tofake-ipand test again. A response within198.18.0.0/16for a regular test domain means mapping is working. To check the upstream's real result, switch toredir-hostor use a domain excluded by the filter; do not use a mapped address to judge whether fallback resolution is correct. - Test private domains and the system resolver. Run
nslookup example.comwithout specifying a server, then query a known internal domain the same way. If public domains resolve but the internal domain does not, check thenameserver-policysuffix and whether the internal resolver is reachable. If an explicit query to the listener works but system queries fail, check system DNS, TUN routes, and the app's DNS settings first. - Test the actual connection. Open the target site in a browser, then check the domain, matched rule, and outbound policy on the client's Connections page. If DNS returns a response but the page still times out, continue troubleshooting the rules and outbound connection. If there is no corresponding entry on the Connections page, check whether the app's traffic is passing through the client.