Clash DNS configuration: nameserver, fallback, and DNS hijacking
Learn how Clash DNS settings work, including nameserver, fallback, fallback-filter, and dns-hijack, plus common DNS pollution and leak scenarios.
First, check whether DNS queries are reaching Clash
To change the resolver Clash uses, start with dns.nameserver. To send queries for a few known domains to different resolvers, consider dns.nameserver-policy. Use fallback when you want the response from the primary resolver to determine whether another set of results should be used. If an app is still querying the resolver configured by the system, check how DNS traffic is routed first. Changing upstream resolvers won't change where the app sends its queries.
The examples below use fields available in the Mihomo v1.19.x series. The client version and the version of the core it runs are not the same thing; if you're using vanilla Clash or another fork, check which fields your core supports. Menu names vary by client version. When troubleshooting, verify which subscription is enabled, which overrides are applied to it, and whether the startup log reports configuration errors. The YAML you edit and save may not be the configuration the core ultimately loads.
| Field | Configuration path | What it controls |
|---|---|---|
nameserver | dns | Default upstream for regular domains |
nameserver-policy | dns | Upstream preferred when a domain condition matches |
fallback | dns | Alternate upstreams used by the fallback branch |
fallback-filter | dns | Domains or primary results that should use fallback results |
dns-hijack | tun | DNS requests entering TUN that the core should resolve |
nameserver: establish a troubleshooting baseline with one upstream
Use this snippet in an existing Mihomo configuration for local testing. 127.0.0.1:1053 opens a DNS listener on the local machine only; it serves a different purpose from mixed-port, which handles HTTP or SOCKS traffic. A single upstream makes it easier to pinpoint failures. The example uses redir-host so you can inspect real addresses, not to compare the performance of two DNS modes. If your configuration already has a dns section, merge these fields into it instead of adding a second top-level key with the same name.
dns:
enable: true
listen: 127.0.0.1:1053
enhanced-mode: redir-host
default-nameserver:
- 1.1.1.1
nameserver:
- https://dns.google/dns-query
The DoH URL in nameserver uses a hostname. Here, default-nameserver resolves the upstream hostname; it is not the upstream that handles regular queries. The example uses plain DNS for bootstrap resolution and DoH for domain queries. So seeing a bootstrap query sent to 1.1.1.1:53 in a packet capture does not prove that domain queries are also sent over plain DNS. If the example upstream is unreachable on your network, replace it with a resolver you can reach before deciding the configuration is wrong.
If your proxy node uses a hostname as its server address, check proxy-server-nameserver separately. A startup deadlock can occur if the core must go through the proxy to reach a resolver, but also needs to resolve the node's hostname before it can connect. Make sure node hostnames have a resolution path that works before the proxy is up. Being able to resolve a test domain does not guarantee that the node hostname will resolve.
fallback and fallback-filter: choosing by domain or IP address
Don't think of fallback simply as a second server that starts only when the primary DNS times out. For address queries subject to fallback evaluation, the primary and fallback upstreams may be queried concurrently. Even if the primary responds, filter conditions can cause the core to use the fallback result. If you need to send a domain only to a specific upstream, prefer nameserver-policy. Using a fallback result does not mean the primary upstream never received the query.
Choosing between domain and IP address conditions
- Use
fallback-filter.domainto specify domains whose queries should use fallback results. When an address query matches one of these domain conditions, the core doesn't need to check the primary upstream's returned IP first. - Use
fallback-filter.ipcidrto check whether a primary result falls within a specified range. For example,240.0.0.0/4can be treated as one suspicious address range, but it is not a comprehensive list of polluted addresses. Don't add ranges used by your local network indiscriminately, or valid internal answers may be replaced. - With
geoip: trueandgeoip-code: CN, the core uses its GeoIP database to evaluate the address returned by the primary upstream. Legitimate sites may return overseas addresses through international CDNs, and GeoIP databases can be out of date. A geographic mismatch is a fallback condition, not proof of DNS pollution. Setfalseexplicitly if you don't need this check.
To observe address-based filtering, merge the fields below into the dns section from the previous example. This is a minimal change for observing filter behavior; it doesn't mean two public resolvers are a good choice for everyday use. If the problem affects only internal company domains, route that domain suffix to a resolver that can return internal records, and make sure the device is connected to a network that can reach it. Public fallback resolvers usually can't replace this path.
fallback:
- https://cloudflare-dns.com/dns-query
fallback-filter:
geoip: false
ipcidr:
- 240.0.0.0/4
TUN dns-hijack: intercepting queries entering the virtual network interface
Set dns-hijack under tun to send matching requests to the core's DNS resolver; it does not define a new DNS upstream. The system proxy setting mainly affects apps that honor system proxy settings. It does not route every DNS query on the device through the core. To intercept traditional DNS, enable TUN in a supported client and check that its generated configuration covers both UDP and TCP port 53.
tun:
enable: true
auto-route: true
dns-hijack:
- "any:53"
- "tcp://any:53"
This section covers routing and interception fields only. Whether a virtual network interface can be created, whether apps are excluded from TUN, and whether queries to local network addresses enter TUN all depend on the OS, permissions, and client routing settings. Sending a query directly to 127.0.0.1:1053 tests the DNS listener, not TUN. Browser Secure DNS over HTTPS on port 443 and system Private DNS over TLS on port 853 won't be redirected to the core's DNS resolver just because port 53 is matched. Encrypted requests may still travel through the proxy as regular connections, so the port alone can't tell you which route they take.
Troubleshooting order: listener, system path, upstream traffic
- Test the core's listener first. On a computer with
diginstalled, rundig @127.0.0.1 -p 1053 example.com A +time=2 +tries=1. If it times out, check whether the core loaded the new configuration and whether the port is listening. ASERVFAILresponse means the local service replied; next, check bootstrap resolution, upstream connectivity, and TLS errors. The 2-second setting is a test timeout, not a DNS speed measurement. - Then test the app you actually use. Leave the configuration unchanged, query through the system's default DNS path on the same device, and reproduce the issue in the affected app. Check the app's Secure DNS setting, system Private DNS, TUN exclusions, and cache. The server address shown by a system tool may only be the address the query was originally directed to; on its own, it doesn't prove where the query ultimately went.
- Finally, check the egress path. On a device you have permission to inspect, monitor outbound connections on the physical network interface. For regular DNS, check the destination address and port 53; for encrypted DNS, compare the upstream endpoint with proxy egress logs. Retest with a fresh query or after clearing the relevant cache. Otherwise, not seeing a request may simply mean the answer came from cache.
DNS pollution and DNS leaks are different problems. To investigate pollution, check whether an answer was altered or incorrectly replaced; different resolvers returning different CDN addresses isn't enough to draw a conclusion. To investigate leaks, check whether queries went to an unintended resolver. An answer can be correct even when the query took the wrong path. If DNS returns the expected result but a site still won't connect, check the matched rule and policy group on the client's connection page. rules determine how application traffic is routed; they don't guarantee that DNS queries use the same egress path.