TUN mode can capture application traffic without changing each app’s proxy settings, but it does not automatically make DNS private. A device may send web connections through Mihomo while DNS lookups still go to a router, an ISP resolver, or a hard-coded public DNS server. This guide explains where those leaks come from, compares fake-ip with redir-host, and walks through a practical Mihomo YAML setup for TUN users. It also covers common edge cases such as DNS hijacking, local network names, IPv6, and applications that bypass the system resolver.
What TUN Captures—and What It Does Not
A TUN interface gives Mihomo a virtual network adapter. When an application opens a connection, the operating system can route packets through that adapter, allowing Mihomo to inspect the destination and apply rules. This is useful for apps that do not support a conventional system proxy, but it should not be confused with a DNS privacy switch.
DNS is often a separate step. An application may ask the operating system to resolve example.com, then connect to the returned IP address. If the DNS request leaves through the physical network before Mihomo handles the connection, the resolver can see the domain even if the eventual connection is proxied. Some applications also send DNS directly over HTTPS or TLS, use their own resolver, or connect to a literal IP address. TUN capture, DNS interception, and the application’s resolver behavior all affect the result.
A useful way to think about leak prevention is to follow both parts of a request:
- Name lookup: Where does the DNS query go, and which resolver answers it?
- Connection routing: Which Mihomo rule selects the proxy, direct, or reject path for the resulting connection?
- Resolver bootstrap: How does Mihomo resolve the hostname of an encrypted DNS server or proxy node without creating a DNS loop?
These paths are related, but they are not identical. For example, a browser may use DoH to contact a resolver directly over HTTPS. The request can look like ordinary web traffic to a network monitor, and it may not use the operating system’s port 53 resolver at all. A DNS interception setting aimed only at port 53 cannot necessarily identify that traffic as DNS.
Fake-IP vs. Redir-Host for TUN
Mihomo’s DNS enhanced modes determine what address Mihomo returns to an application and how it later recovers the original domain for rule matching. The choice matters in TUN mode because domain-based rules are most useful when Mihomo can retain the requested hostname, rather than seeing only a resolved address.
With redir-host, Mihomo resolves the domain and returns the real IP address to the client. When the application connects, Mihomo can apply IP-based rules to the destination. This mode may be useful for applications that expect real addresses, but IP-only visibility can make domain-based routing less reliable. Shared hosting and content delivery networks also mean that one IP may serve many unrelated domains. In addition, the lookup must complete before the application receives an address.
With fake-ip, Mihomo returns a synthetic address from a reserved pool, commonly 198.18.0.0/15, and keeps a mapping between that address and the requested domain. When the application connects to the synthetic address, Mihomo can recover the hostname and apply domain rules. This usually gives rule matching more context and avoids requiring the application to wait for a real IP before the routing decision.
- Choose fake-ip when you want domain rules to work consistently, your applications tolerate synthetic addresses, and you want Mihomo to retain the original hostname for routing.
- Choose redir-host when a specific application or network environment depends on real DNS answers, or when fake-IP behavior causes compatibility problems that cannot be fixed with an appropriate filter.
- Do not treat either mode as encryption. The enhanced mode controls how Mihomo represents DNS answers to applications; it does not, on its own, encrypt the connection between Mihomo and an upstream resolver.
Fake-IP is often a practical starting point for TUN, but the complete DNS path still depends on the upstream resolver configuration and the rules used for DNS connections. A fake address protects the domain-to-connection association inside Mihomo; it does not hide a query that an application separately sends to an external resolver.
Mihomo YAML Baseline and Setup
The following is a focused configuration example, not a complete profile. Keep your existing proxies, proxy-groups, and rules sections, and merge these top-level settings into the same YAML file. Replace the example resolver choices if your network blocks them or your organization requires a specific DNS service.
dns:
enable: true
listen: 0.0.0.0:1053
ipv6: false
enhanced-mode: fake-ip
fake-ip-range: 198.18.0.1/16
# Domains that need real answers, such as selected LAN discovery services.
fake-ip-filter:
- '*.lan'
- '*.local'
- 'localhost.ptlogin2.qq.com'
# Encrypted upstream resolvers used for ordinary DNS lookups.
nameserver:
- https://1.1.1.1/dns-query
- https://dns.google/dns-query
# Bootstrap resolver for proxy server hostnames.
# Use an address reachable without resolving through the proxy itself.
proxy-server-nameserver:
- 223.5.5.5
- 119.29.29.29
tun:
enable: true
stack: mixed
auto-route: true
auto-detect-interface: true
strict-route: true
dns-hijack:
- any:53
The dns.listen address starts Mihomo’s DNS listener; it is not a substitute for TUN interception. The dns-hijack entry asks Mihomo to redirect conventional DNS traffic on port 53 that reaches the TUN interface. The DNS server addresses in nameserver are examples of encrypted DNS endpoints, while proxy-server-nameserver supplies a bootstrap path for resolving proxy server hostnames. Without a bootstrap resolver, a profile can get stuck trying to resolve the server through a DNS route that itself depends on that server.
Before applying the change, make a copy of the current profile. In the client, select the Mihomo-compatible profile and merge the settings at the top level; do not paste a second dns: or tun: block elsewhere, because duplicate YAML keys can be rejected or interpreted unexpectedly. Then validate the profile, enable TUN with the required operating-system permissions, and restart or reload the core. If the client has its own DNS, TUN, or system-proxy controls, check that they do not overwrite the profile values.
- Start with a known baseline. Confirm that ordinary proxy traffic works before changing DNS. Note the active profile, selected proxy group, and current DNS mode so you can revert quickly.
- Merge the DNS settings. Enable Mihomo DNS, select
fake-ip, and set the upstream resolvers. Keep the bootstrap resolver reachable directly; do not point it at a hostname that must be resolved by the same unavailable path. - Enable TUN and port 53 hijacking. Turn on
auto-routeanddns-hijack. Usestrict-routeonly after confirming that the client and operating system support the behavior you expect, especially if you rely on local network access. - Reload and inspect logs. Look for YAML parse errors, permission failures, DNS timeouts, or messages indicating that the TUN interface could not be created. A profile that loads successfully is necessary, but it is not proof that all DNS is captured.
- Test the paths separately. Check a proxied domain, a direct domain, a local device name, and an application that normally uses DNS. Confirm that the selected rule and resolver behavior match your intention.
Routing Resolvers and Handling LAN Exceptions
Using an HTTPS resolver does not automatically mean its traffic uses the proxy. Mihomo must itself establish a connection to the resolver endpoint, and the route for that connection depends on the configuration and rules. If you require upstream DNS traffic to use a proxy, verify that your Mihomo version supports the relevant DNS routing options and that the resolver connection follows the intended rules. Options such as respect-rules can change DNS request routing in supported configurations, but they should not be enabled blindly: resolver bootstrap and proxy-node resolution still need a working path.
Keep the bootstrap path distinct from the resolver path. A proxy node may be configured with a domain name, while an encrypted DNS endpoint also has a hostname. Mihomo needs some initial way to resolve those names before it can use the corresponding connection. A common failure pattern is to route every DNS lookup through a proxy that cannot start until its own server hostname has been resolved. Use a reachable bootstrap resolver for proxy server names, then test whether the encrypted resolver can be reached using the intended direct or proxied route.
Fake-IP filtering is another area where restraint helps. A filter tells Mihomo to return a real DNS answer for matching domains instead of a synthetic address. This can restore compatibility for local discovery, certain games, voice applications, or software that shares IP addresses with another service. However, an overly broad filter can make domain-based routing less predictable, while filtering every domain defeats much of the benefit of fake-IP.
For home networks, entries such as *.lan or *.local may be useful, but they are not universal requirements. A router’s private hostname may only be resolvable by the router’s own DNS server. If a local name does not resolve, identify which resolver knows it and whether that resolver is reachable through Mihomo. A filter does not create a local DNS record; it only changes how Mihomo handles the matching query.
IPv6 deserves a deliberate decision. Setting dns.ipv6: false in this example prevents Mihomo DNS from returning IPv6 answers, but it does not necessarily disable IPv6 at the operating-system level or guarantee that every IPv6 packet is captured. If your network and TUN setup support IPv6, configure and test it end to end. Otherwise, disabling IPv6 DNS answers and checking for an independent IPv6 route can reduce confusing cases where IPv4 traffic is proxied but IPv6 traffic escapes by another path.
Troubleshooting DNS Leaks and Failures
When an online DNS test reports an unexpected resolver, first determine what the test actually observed. It may have seen the resolver used by the browser, a resolver used by an operating-system service, or a query made outside Mihomo. Run more than one test and compare the results with Mihomo’s connection and DNS logs. A single result does not identify which setting caused the behavior.
- Queries still appear to use the router or ISP resolver: Confirm that TUN is active,
dns-hijackis applied, and the client is using the profile you edited. Check whether the application uses DoH or DoT, and inspect browser secure-DNS settings. Port 53 interception will not necessarily capture an application’s encrypted DNS connection as a DNS request. - Websites fail after enabling fake-IP: Temporarily test
redir-hostto isolate a compatibility issue. If that fixes a particular app, add only the necessary domain tofake-ip-filter, reload, and test again. Also check for stale application DNS caches and restart the affected app. - Proxy nodes fail to connect: Check whether the proxy server hostname can be resolved through
proxy-server-nameserver. A resolver timeout, blocked bootstrap DNS, or accidental loop can prevent the proxy connection from coming up even when the general DNS block looks correct. - Local devices or printers disappear: Test the private IP directly, then test the local hostname. If the IP works but the name does not, investigate local DNS and discovery behavior. Add a narrow fake-IP filter only if the application needs a real address, and make sure the LAN route is allowed by your rules.
- Some traffic bypasses the proxy: Check whether the destination is IPv6, whether another network interface is active, and whether the app uses a hard-coded IP or its own encrypted resolver. Review routing rules as well as DNS settings; DNS protection cannot force a connection to use a proxy group if the matching rule selects direct access.
- Internet access stops when TUN is enabled: Review operating-system permissions, interface selection, and route conflicts. On multi-interface systems, a VPN, virtual machine adapter, or corporate network client can change the default route. Temporarily disable conflicting network tools to identify the source rather than adding broad bypasses.
For a more reliable diagnosis, change one variable at a time and record the result. Compare the same domain under fake-ip and redir-host, inspect Mihomo’s DNS and connection logs, and check whether the connection is associated with the expected domain rule. After a change, reload the configuration and clear the application’s DNS cache when appropriate; cached records can make a corrected setup appear broken or make an earlier leak appear fixed.
There is no single YAML option that can prove every application is leak-free. The strongest practical setup combines Mihomo DNS, TUN routing, appropriate port 53 interception, a deliberate resolver and bootstrap path, carefully scoped fake-IP exceptions, and testing of the apps and network interfaces you actually use. Start with the baseline above, keep exceptions narrow, and treat unusual DNS results as a clue to investigate rather than a reason to add broad rules.