TUN mode can capture an app’s IP traffic without automatically controlling every DNS request the app makes. A browser may send ordinary DNS queries through Mihomo while another app uses its own encrypted resolver, and an operating system can keep a separate resolver active in the background. The result can look like a DNS leak even when the proxy itself is working. This guide explains how DNS moves through Mihomo TUN mode, how to configure fake-ip and nameserver-policy, and how to test for leaks without mistaking expected behavior for a configuration failure.

Understand TUN and DNS Flow

A TUN interface gives Mihomo a route for IP packets. When an application opens a connection, the operating system sends the packet through that interface, and Mihomo can apply routing rules. DNS is a separate step: an application first needs an address for a domain, and it can obtain that address through the system resolver, a hard-coded DNS server, DNS over HTTPS (DoH), or DNS over TLS (DoT).

For a conventional system DNS query over UDP or TCP port 53, Mihomo can use TUN’s dns-hijack setting to redirect the request to its DNS module. That module then chooses an upstream resolver according to the DNS configuration. In fake-ip mode, Mihomo can return a synthetic address to the app and retain the domain-to-address mapping. When the app connects to that address, Mihomo recovers the domain and can apply domain rules before deciding where the connection should go.

This flow is not the same as forcing every possible DNS mechanism through the proxy. DoH usually travels as HTTPS on port 443, and DoT commonly uses port 853. A normal port-53 hijack does not identify every encrypted DNS request, because those packets resemble other encrypted connections. A browser’s “secure DNS” setting, a VPN-like app, or a program with a built-in resolver may therefore use a different path from the system resolver.

Think in layers: TUN captures IP traffic, DNS hijacking redirects supported DNS packets, and Mihomo’s DNS settings select upstream resolvers. An application can still choose a resolver outside the system DNS path, so verify both Mihomo and the apps you use.

Also distinguish a DNS leak from a deliberate direct lookup. A domain routed directly may be resolved by a direct-side resolver. A proxied domain should not unexpectedly be resolved by an ISP resolver if your design requires its DNS lookup to follow the proxy path. Which upstream is correct depends on your privacy requirements, network restrictions, and whether local or regional domains need direct resolution.

Configure TUN and DNS Basics

Start with a small, understandable configuration. The example below enables TUN, redirects conventional DNS traffic on port 53, and uses fake-ip. Replace the resolver addresses and rule choices with values suitable for your network. Merge these fields into the existing profile rather than replacing unrelated proxy, rule, or controller settings.

Mihomo TUN and DNS Baseline
tun:
  enable: true
  stack: mixed
  auto-route: true
  auto-detect-interface: true
  dns-hijack:
    - any:53

dns:
  enable: true
  listen: 127.0.0.1:1053
  ipv6: false
  enhanced-mode: fake-ip
  fake-ip-range: 198.18.0.1/16
  fake-ip-filter:
    - '*.lan'
    - '*.local'
    - 'time.*.com'
    - 'time.*.gov'
  default-nameserver:
    - 1.1.1.1
    - 8.8.8.8
  proxy-server-nameserver:
    - https://1.1.1.1/dns-query
  nameserver:
    - https://1.1.1.1/dns-query
    - https://8.8.8.8/dns-query
  direct-nameserver:
    - 223.5.5.5
    - 119.29.29.29

dns.enable activates Mihomo’s DNS module. listen is the local DNS service address; it is not an upstream server address. Binding to loopback is a sensible default for a desktop installation, while router or LAN deployments may need a different listen address and appropriate firewall controls. Do not expose a DNS listener to an untrusted network without understanding the consequences.

default-nameserver provides initial resolution for resolver hostnames and other DNS bootstrap needs. Using IP-address resolvers there avoids a dependency on resolving a DNS server’s own hostname before DNS is available. proxy-server-nameserver is used for resolving proxy server addresses where applicable; a reachable bootstrap resolver can prevent a circular dependency in which Mihomo needs the proxy to resolve the proxy endpoint.

nameserver is the main upstream list for Mihomo DNS queries. The sample uses HTTPS endpoints, but an endpoint’s availability depends on the network, certificate validation, and the client’s Mihomo build. If a resolver cannot be reached, test it independently and check Mihomo’s log before changing several fields at once. Setting ipv6: false here only controls DNS behavior in Mihomo; it does not necessarily disable IPv6 on the operating system or prevent every IPv6 connection.

Use Fake-IP and Nameserver Policy Carefully

fake-ip is useful when you want Mihomo to match domain rules even after an application has resolved a hostname. The app receives an address from the configured synthetic range, and Mihomo uses its mapping to associate a later connection with the original domain. This can make domain-based routing more reliable than waiting for a real IP and then trying to infer the requested hostname.

Some devices and applications expect real DNS answers. Local discovery, certain games, VoIP clients, captive portals, and software that performs its own address checks may behave badly when given synthetic addresses. Add only the necessary domains to fake-ip-filter; a very broad filter can silently move many requests back to real-IP resolution and make rule behavior harder to predict. Filter syntax and available presets may vary by Mihomo version, so check the documentation for the core bundled with your client.

nameserver-policy lets you select DNS servers for matching domains. This is useful for sending local or region-specific names to a resolver that can answer them while keeping other lookups on the primary resolver list. For example, the following policy directs selected internal domains and a regional suffix to a local DNS server:

Nameserver Policy Example
dns:
  nameserver-policy:
    '+.corp.example': 10.20.0.53
    '+.home.arpa': 192.168.1.1
    'geosite:cn': 223.5.5.5
  direct-nameserver:
    - 223.5.5.5
    - 119.29.29.29

Use real internal domains and resolver addresses in your own profile; the example addresses are placeholders for a private network. The +.corp.example form targets the domain and its subdomains in Mihomo’s supported policy syntax. A policy entry is not a routing rule: it selects a DNS resolver, while rules and proxy groups decide whether the resulting connection is proxied or direct.

Keep the DNS and routing decisions aligned. If an internal hostname must resolve only on a company network, route it directly and use the company resolver only when that network is available. If a domain must be resolved through a particular upstream for privacy or reachability, verify that the relevant query actually matches the policy. Do not assume that adding a resolver under nameserver guarantees every domain will use it; policy entries and other DNS options can affect selection.

Apply and Test the Configuration

Change one area at a time so that a successful test tells you what worked. If your client supports profile backups, save the current profile first. Then follow this practical sequence:

  1. Confirm the core. Check that the client is running a Mihomo-compatible core and that the profile is accepted. A YAML parse error or an unsupported field can prevent the intended settings from taking effect.
  2. Enable TUN in the client. Turn on the client’s TUN option and grant any required administrator, system-extension, or VPN permission. Client UI options can override or generate parts of the profile, so compare the active configuration with the file you edited.
  3. Start with a known system lookup. Flush the operating system’s DNS cache if necessary, then resolve a test hostname using the normal system resolver. Check Mihomo’s logs or connection view to see whether the request is handled as expected.
  4. Test routing separately. Visit one domain intended for proxying and one intended for direct access. Confirm the selected rule and proxy group in the client. A correct DNS answer alone does not prove that the connection followed the intended route.
  5. Check a controlled leak test. Use a reputable DNS leak test while the proxy is connected. Note the resolver operators and locations reported, then compare them with the upstreams you configured. Repeat after reconnecting or clearing cache if results appear stale.
  6. Test special applications. Check browsers with secure DNS enabled, communication apps, and any software known to use a custom resolver. Compare behavior with the app’s encrypted-DNS option disabled, then re-enable it if that feature is required and configure it deliberately.

A leak-test website reports the resolvers it can observe for its own test traffic; it does not inspect every request made by every app on the device. A reported resolver can also belong to the intended DoH provider or an upstream that exits near your proxy server. Interpret the result against your design rather than treating any resolver outside your home network as proof of a leak.

Do not test only by checking an IP address. An IP-check page tells you about the visible connection endpoint, not which resolver answered a separate DNS query. Use DNS-specific tests and inspect Mihomo logs or connection details when diagnosing a suspected leak.

Diagnose Common Leak Symptoms

When a test reports an unexpected resolver, identify the request path before adding more configuration. First determine whether the app used ordinary port-53 DNS, DoH, DoT, or a cached answer. Then check whether TUN captured the app’s traffic, whether a system-level VPN or security product owns the network route, and whether the active Mihomo profile includes the fields you edited.

  • Queries appear to bypass Mihomo. Confirm TUN permissions, auto-route, and the active network interface. On some systems, another VPN, firewall, or virtual network adapter can take precedence. Temporarily test with conflicting network tools disabled, then restore them one at a time.
  • Port-53 queries are intercepted, but a browser shows another resolver. Check the browser’s secure DNS setting. DoH is carried over HTTPS and may not be redirected by dns-hijack: any:53. Disable the browser option for a controlled comparison or configure its resolver to match your intended policy.
  • Proxy nodes fail after DNS changes. Check whether Mihomo can resolve the proxy server hostname before the proxy is available. A usable default-nameserver or proxy-server-nameserver can address a bootstrap failure. Review logs for resolution timeouts rather than replacing all upstreams at once.
  • Local services stop working with fake-IP. Add only the affected domains or service patterns to fake-ip-filter, or use a suitable real-IP strategy for that environment. Confirm that the local resolver is reachable and that direct rules do not send private-network traffic to a remote proxy.
  • Results change between runs. DNS caches exist in applications, operating systems, browsers, and Mihomo. Flush or wait for the relevant cache to expire, reconnect TUN if needed, and repeat the same test with the same network and rule selection.
  • Some domains resolve but route incorrectly. Review the connection’s matched rule. Fake-IP helps preserve a domain mapping, but a conflicting earlier rule, IP-CIDR rule, or rule-provider entry can still select an unexpected route.

Make one change, reload the profile or restart the core when required, and repeat the same test. Avoid stacking multiple DNS overrides until you know which component owns the query. In particular, adding more public resolvers does not fix an app that bypasses the system resolver, and changing a routing rule does not change which DNS server answered a query.

DNS Leak Protection FAQ

Does TUN mode guarantee that no DNS requests can leak?

No. TUN can capture routed IP traffic, and Mihomo can hijack conventional DNS on port 53, but applications may use DoH, DoT, cached answers, or custom networking paths. Operating-system routing, client permissions, and other VPN software also matter. Treat TUN as an important control, not a guarantee that overrides every application choice.

Should I always use fake-IP?

No single mode fits every setup. Fake-IP is often convenient for domain-based routing and can reduce dependence on real-IP rule matching. Some local services and applications require real answers, however. Start with fake-IP if it suits your clients, then use a narrow filter or a different DNS mode only when a reproducible compatibility issue calls for it.

Is a public resolver shown by a test always a leak?

No. It may be the resolver you deliberately configured, or a resolver reached through your selected proxy path. A test result must be compared with the intended DNS design. If the reported resolver is an ISP resolver when you expected a specified encrypted upstream, investigate the app’s resolver settings, Mihomo’s active profile, and the query path.

Why does a nameserver-policy entry not change the proxy route?

nameserver-policy selects a resolver for DNS queries; it does not select a proxy group. Use routing rules and proxy groups to decide whether the eventual connection is direct or proxied. Verify both the DNS result and the matched connection rule when troubleshooting.

Reliable DNS leak protection comes from making the DNS path explicit, checking that the active TUN configuration is actually in use, and testing the applications that matter. Keep the setup simple at first, add nameserver-policy entries only for clear resolver requirements, and treat fake-IP filters as targeted compatibility exceptions. With those habits, Mihomo’s logs and repeatable tests can help distinguish a genuine bypass from normal resolver behavior.