Clash DNS Configuration: Nameservers, Fallback, and Fake-IP Setup
Learn what each Clash DNS setting does, how fake-IP and redir-host differ, how fallback-filter selects responses, and which DNS queries dns-hijack captures.
nameserver: First, confirm queries reach the core
The examples below use mihomo (formerly Clash.Meta). The client app saves and applies the configuration, but the running core handles DNS. Older versions of Clash may not support every mihomo field. If your subscription includes its own dns section, inspect the effective configuration after overrides and merging: the file you edited before the subscription updated may not be the one the core is currently reading.
Start by separating three steps: which resolver the system or app sends queries to, which upstream mihomo queries, and which connection rules apply to the address the app receives. dns.enable enables DNS in the core, while dns.listen opens a query endpoint; neither changes the system DNS settings automatically. nameserver sets the core's regular resolvers, but does not determine whether traffic uses DIRECT or a proxy group.
Listen on a local port to test the upstream directly
dns:
enable: true
listen: 127.0.0.1:1053
enhanced-mode: redir-host
nameserver:
- https://1.1.1.1/dns-query
This is an example of the top-level dns section, not a complete subscription. If you already have this section, merge the fields rather than adding a second top-level key with the same name. The example listens on local port 1053; only programs explicitly sending queries to that port will use it. An IP-based DoH URL avoids bootstrap-resolution issues with the upstream hostname during initial testing. In production, choose a resolver that is reachable on your network and permitted for your use.
| Field | Purpose | When to check |
|---|---|---|
nameserver | Upstreams for routine domain lookups | Most domains fail to resolve or return unexpected answers |
default-nameserver | Bootstrap resolution for DNS upstreams specified by hostname | Queries time out after changing a DoH URL from an IP address to a hostname |
proxy-server-nameserver | Resolvers for proxy node hostnames | Regular domains resolve, but connections to nodes specified by hostname fail |
nameserver-policy | Sets an upstream for matching domains, taking precedence over the regular nameserver and fallback | Internal company domains must use an internal DNS server that can resolve the relevant zone |
When both the upstream and node are specified by hostname, check both dependencies: the DoH server's hostname must resolve first, and the node's hostname must resolve before the node can connect. If resolving the node depends on a proxy that is not yet connected, the two can end up waiting on each other. Test whether the dedicated resolver is reachable first instead of masking the issue by adding more resolvers.
fallback-filter: Choose a response by domain or IP address
fallback is not simply a secondary resolver that waits for the primary to time out. For address queries in the regular resolution flow, mihomo can query both upstream groups in parallel, then select a response based on the filter conditions. Domains matching fallback-filter.domain are queried directly through fallback, without waiting for the primary upstream to return an address first. For domains with nameserver-policy configured, check whether that policy matches first.
dns:
enable: true
listen: 127.0.0.1:1053
enhanced-mode: redir-host
nameserver:
- https://1.1.1.1/dns-query
fallback:
- https://8.8.8.8/dns-query
fallback-filter:
geoip: false
ipcidr:
- 0.0.0.0/32
domain:
- '+.example.org'
- Match by domain:
+.example.orgmatchesexample.organd its subdomains. Use it as a test to confirm that a known domain goes to the intended upstream; don't use the example domain as a production rule. - Match by address: For queries that don't match the domain conditions above, if the primary upstream returns an address matching
ipcidr, mihomo uses the result fromfallback.0.0.0.0/32matches only that one IPv4 address; it does not represent the entire IPv4 address space. - Match by GeoIP: With
geoip: trueandgeoip-code: CN, mihomo can use thefallbackresult when the address returned by the primary upstream doesn't meet the configured region criteria. This check relies on GeoIP data and cannot verify that a response is correct. A CDN serving an address in another region for legitimate reasons may also trigger the switch.
Different addresses from two reachable upstreams don't necessarily mean one of them is wrong. First check which configured condition triggered the switch, then confirm that the selected address can connect. If internal domains should only use internal resolvers, assign an upstream with nameserver-policy instead of mixing internal DNS into region-based checks intended for public IP addresses.
fake-ip vs. redir-host: Which address does the app receive?
redir-host returns the real address resolved by the upstream, making it useful for checking DNS results. With fake-ip, IPv4 queries can instead receive a mapped address from the configured pool. When the app starts a connection and the core captures it, the core uses the mapping to recover the original domain, then applies the routing rules to choose an outbound. This changes the DNS response and how the domain is recovered; it does not force all connections through a proxy.
Verify traffic returns to the core before adding exceptions
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
This example uses the common 198.18.0.1/16 address pool. Unless the domain matches fake-ip-filter, seeing its A record fall within 198.18.0.0/16 is expected. This confirms only that fake-IP responses are active; the returned address can't tell you which public IP the upstream ultimately resolved, or whether the app's subsequent connection reached the core. Check the connection view for the destination domain and matched rule.
fake-ip-filter makes matching domains resolve to real addresses, but it doesn't automatically select a LAN DNS server for them or make the app connect directly. This example keeps real-address responses for home.arpa; in an actual setup, assign a reachable local resolver for that zone in nameserver-policy. For a client that only accepts real addresses, add an exception for the affected domain rather than switching the entire configuration to another mode.
dns-hijack: Which DNS queries does TUN capture?
fake-ip determines how the core responds to DNS queries; dns-hijack determines which queries entering TUN are handed to the core's DNS service. Enabling the system proxy alone does not activate the TUN rules below. TUN is not guaranteed to carry every app request: permissions, route exclusions, and operating system traffic handling can all keep some traffic off the virtual interface.
tun:
enable: true
auto-route: true
dns-hijack:
- any:53
- tcp://any:53
Merge this into the top-level tun section and keep the enabled dns section. any:53 matches UDP queries on port 53 that enter TUN; tcp://any:53 adds TCP port 53, for example when a client retries over TCP after receiving a truncated UDP response. auto-route configures system routes; it does not convert all encrypted DNS traffic back into standard DNS queries.
- Browser Secure DNS: DoH sent directly by an app usually uses HTTPS on port 443, while DoT typically uses TCP port 853. Neither matches the port 53 rules above. Even if this traffic enters TUN, that alone doesn't mean the core's DNS service handles the query.
- LAN resolvers: Queries sent to a router or LAN DNS server may go directly over the local route. Especially on Windows and macOS, don't assume
any:53will capture DNS requests sent to the LAN. Check the client logs and actual responses. - Listening vs. interception:
127.0.0.1:1053is for sending test queries directly;53in the TUN list is the original destination port being matched. They serve different purposes, so there's no need to make them the same port.
Troubleshooting order: listen, respond, capture, route
Keep a working copy of your configuration and change one field at a time. In a terminal with dig installed, run the commands below to send an A-record query directly to the core's local listener. The second command tests the same listener over TCP; it does not test TUN interception.
dig @127.0.0.1 -p 1053 example.org A +time=2 +tries=1
dig @127.0.0.1 -p 1053 example.org A +tcp +time=2 +tries=1
- Confirm the configuration loaded. If both commands time out or the connection is refused, first check that the core is running,
dns.enableis active, and port1053is available. ASERVFAILresponse means the local listener replied; investigate upstream connectivity and bootstrap resolution next. - Compare DNS modes. Start with
redir-hostto check whether the A record returns a real address, then switch tofake-ipand confirm the result falls within the configured address pool. Keep the test domain out offake-ip-filter, and don't compare a fresh query against an address cached by your browser. - Test system queries. Remove the explicit server and port, then run
dig example.org Afor an initial check of the default resolution path. Also check whether the core receives the query. If the command-line test works but the browser doesn't, check the browser's Secure DNS settings and cache; a command-line result can't replace a browser test. - Check the actual outbound route. Open a test site, then check the connection view in the client for the destination domain, matched rule, and outbound policy. If the domain resolves but the connection times out, investigate destination reachability, the policy group, and node status instead of repeatedly changing
nameserver.