DNS Resolution, Traffic Interception, and Rule-Based Routing
When troubleshooting Clash DNS, separate three steps: whether the app's DNS query reaches the core, which upstream the core queries, and which rule matches the app's subsequent connection. tun.dns-hijack handles the first step, the dns section handles the second, and rules determine the third. Changing nameserver won't switch a connection from DIRECT to a proxy. Enabling the system proxy also doesn't mean every app's DNS queries are intercepted.
This guide covers mihomo, the successor core to Clash Meta. Client interface labels and config merge behavior vary. Before making changes, confirm which core is running, save a copy of your existing config, and apply edits through the client's supported local config or override feature. Don't add a second top-level dns: or tun: section to the same YAML file; merge your changes into the existing sections. If an update removes your changes, check whether the override is applied to the active config instead of switching to a different set of DNS servers.
nameserver, fallback, and fallback-filter
Start by testing a single upstream
nameserver is the list of upstream servers used for standard queries. When troubleshooting, start with one reachable server. Once direct queries work, add a second upstream or configure servers for specific domains. In the example below, the core's DNS listener is bound to port 1053 on the local machine for standalone testing. This does not automatically change the operating system's DNS server to that port.
dns:
enable: true
listen: 127.0.0.1:1053
enhanced-mode: redir-host
nameserver:
- 223.5.5.5
Bare IP addresses in the example are standard DNS upstreams on the default port, 53; they are not encrypted DNS. First, use redir-host to confirm that a regular public domain resolves to its real IP address, then try fake-ip. This helps distinguish upstream connectivity issues from app compatibility problems with synthetic addresses.
fallback selects between results; it's not just a timeout retry
For regular domains that aren't routed through a dedicated policy, configuring fallback lets the core query nameserver and fallback in parallel, then select a result according to fallback-filter. Don't assume the second group is queried only after the first one times out. Put the following settings under the same dns: node, at the same level as nameserver:
fallback:
- 1.1.1.1
fallback-filter:
geoip: true
geoip-code: CN
ipcidr:
- 240.0.0.0/4
- With
geoip: trueandgeoip-code: CN, the core uses IP geolocation data to evaluate the address returned by the primary upstream. If the primary result is determined to be outsideCN, the result fromfallbackis used instead. This check is based on the IP's geolocation, not the domain suffix. ipcidrchecks whether an address returned by the primary upstream falls within a specified range. In this example, primary results in240.0.0.0/4are handled by the fallback group. This is not a traffic-routing rule, nor does it recheck fallback results.- Use
fallback-filter.domainto send specified domains directly to fallback resolution.nameserver-policyroutes domains matching a pattern to a specific upstream. For corporate intranet domains, configure a dedicated resolver based on your actual office network rather than relying on GeoIP to guess which server to use.
Choosing a country or region doesn't guarantee a correct result. CDN addresses vary by query location, and GeoIP data may not reflect actual IP assignments. If only one domain resolves incorrectly, compare the responses from both upstreams first, then consider a dedicated policy for that domain. Avoid changing how an entire group of queries is handled to fix a single domain.
Resolving upstream and proxy node hostnames
If you switch to a DoH endpoint with a hostname, its IP must be resolved before the connection to the DoH server can be made. default-nameserver resolves hostnames used by DNS upstreams; when setting it up, use a reachable IP address as a bootstrap resolver. proxy-server-nameserver resolves the server hostnames of proxy nodes. If DNS queries use the proxy for outbound traffic while the node's hostname also depends on that same proxy to resolve, you can end up in a loop. When troubleshooting, first confirm that the node hostname resolves through an independently reachable path, then check DoH queries.
Choosing between fake-ip and redir-host
fake-ip returns a synthetic address to the app and stores the domain-to-address mapping in the core. When the app connects to that address, the core can recover the domain and apply domain-based rules. mihomo commonly defaults to fake-ip-range: 198.18.0.1/16, so a regular public domain resolving to 198.18.x.x can be expected in this mode. This only confirms that the core issued a synthetic address; it doesn't prove that the real upstream lookup or the subsequent proxy connection succeeded.
redir-host returns the real address resolved by the upstream. Use it for comparison when you need to verify the real IP or an app has compatibility issues with synthetic addresses. If an app connects directly to a cached IP or gets an address through its own encrypted DNS, the core may not be able to associate that connection with the original domain. If a domain rule doesn't match, check the destination and matched rule in the connection details rather than relying on the browser's address bar.
Start with a narrowly scoped exception for local network domains
If enabling fake-ip causes issues only with a NAS or printer accessed by an intranet domain, add the actual domain to fake-ip-filter in the default list-based filter config. For example, if your local network uses home.arpa, add '+.home.arpa' to return real addresses for matching domains. This filter changes how responses are returned; it doesn't send queries to your router. If the router is the only DNS server that knows those records, use nameserver-policy to send the relevant domains to your local DNS server. Devices discovered through mDNS need separate troubleshooting for local network discovery; this standard DNS exception is not a substitute.
DNS hijacking in TUN mode
Here, “hijacking” means handing DNS traffic that enters the local TUN and meets the matching criteria to the core's DNS module. Keep dns.enable: true, then set the matching rules in the top-level tun section. This example is for a local client whose routing is managed by mihomo. Enabling TUN may require system permissions.
tun:
enable: true
auto-route: true
auto-detect-interface: true
dns-hijack:
- any:53
- tcp://any:53
any:53matches UDP queries on port 53 that enter TUN.tcp://any:53adds TCP port 53, which is used by queries that switch to TCP, for example when a UDP response is truncated.127.0.0.1:1053is the listener configured earlier for manual testing. Here,53is the destination port of the app's original DNS query. The two ports don't have to match.- These rules don't convert DoH queries sent by the browser over HTTPS or DoT queries sent over TLS into standard DNS. If the issue occurs only in a browser, first compare its Secure DNS settings with the system's DNS resolution path. Restore your original settings after testing.
Use three steps to tell resolution failures from rule mismatches
- Test the core's listener directly. In an environment with
diginstalled, query the same domain over both UDP and TCP. If the connection is refused or times out, first check that the active client config includeslisten: 127.0.0.1:1053, then determine whether the listener failed to start or the upstream didn't respond. If only UDP works, troubleshoot the listener's TCP path. - Test the system's default path. With TUN enabled, run
nslookup example.orgwithout specifying a server, and check the core logs to confirm whether the query reached it. The server address shown by the tool is often the resolver the app originally intended to contact; that line alone doesn't show whether interception worked. To minimize cache interference, use a known-good domain that you haven't queried during this test session. - Check the actual connection. Open the test domain and review the destination domain, matched rule, and outbound policy in the client's connection details. If DNS resolution works but the connection times out, check the outbound policy and node connectivity. If the issue occurs only with
fake-ip, first check for conflicts between the synthetic address range and existing routes, and confirm that the core also intercepts the app's connection.
dig @127.0.0.1 -p 1053 example.org A
dig @127.0.0.1 -p 1053 example.org A +tcp
nslookup example.org
Change one variable at a time: test nameserver first, add fallback next, then switch enhanced-mode, and enable TUN interception last. Browser, system, and core DNS caches are separate. If you still see old results after changing the config, don't keep stacking options. Confirm that the config has reloaded, then use fresh queries to test the listener, system path, and app connection separately.