Clash TUN mode is often presented as a one-click solution: enable the switch, approve the virtual network interface, and expect every application to follow the same proxy policy. That description is convenient but incomplete. TUN changes how packets enter the Mihomo core; it does not automatically make DNS trustworthy, does not repair an incorrectly ordered RULE set, and does not guarantee that IPv6 traffic has disappeared. A secure setup therefore needs three coordinated decisions: how applications send packets into the virtual interface, how hostnames are resolved and represented by Fake-IP DNS, and how Mihomo decides whether each connection should use a proxy or go DIRECT. This guide builds that model from the data path upward, then turns it into a practical configuration for DNS leak prevention, internal-domain handling, IPv6 control, DNS hijack behavior, and log-based troubleshooting.

The examples use Mihomo-compatible syntax, so they apply conceptually to Clash Verge Rev and other clients that expose a Mihomo core. Menu labels vary between Clash Verge, Clash Verge Rev, Clash for Windows, ClashX, and Clash for Android, while some clients expose only a subset of the underlying options. If your GUI has separate toggles for TUN, system DNS, fake-ip, or auto-route, treat those toggles as front ends for the configuration rather than as independent magic features. The goal is not to force every device into GLOBAL mode. It is to make the packet path predictable enough that a browser, terminal, game launcher, container, or background service cannot quietly bypass the DNS and routing policy you intended.

How TUN, DNS, and routing cooperate

A conventional system proxy works only when an application understands the operating system’s HTTP or SOCKS settings. Browsers usually do; command-line tools, update agents, game launchers, Java runtimes, and sandboxed applications may not. A TUN interface operates lower in the stack. Mihomo creates a virtual network adapter, adds routes that direct selected traffic into that adapter, and receives IP packets that would otherwise leave through the physical Wi-Fi or Ethernet interface. The core then reconstructs the destination flow, applies rules, and forwards it through a proxy or the normal network.

That description hides an important detail: most applications connect to an IP address after performing DNS resolution. If the application asks the operating system resolver for example.com, receives a real address, and then opens a socket to that address, Mihomo needs a way to associate the packet with the original hostname. With Fake-IP, the DNS module returns a synthetic address from a reserved pool. Mihomo records the mapping between that fake address and the requested domain. When the application connects to the synthetic address, the core looks up the mapping and can evaluate a hostname rule such as DOMAIN-SUFFIX,example.com,Proxy rather than seeing only an opaque destination IP.

Fake-IP is therefore more than a performance trick. It preserves domain context for transparent proxying, makes domain-based split routing possible for applications that have no proxy controls, and avoids relying on large, frequently changing IP lists. It also creates state. A fake address is meaningful only while the mapping exists in the DNS module. Restarting the core, clearing the cache, or changing the fake-IP range can invalidate old connections. That is normal, but it explains why a long-lived application can appear to lose connectivity after a profile reload while a newly opened browser works immediately.

DNS leaks happen when these layers disagree. For example, TUN may capture TCP packets while the operating system sends DNS queries directly to the router, an ISP resolver, or a hard-coded public resolver. The eventual web connection might use a proxy, yet an observer can still see the requested domain in the DNS exchange. Another failure occurs when a client returns real DNS addresses while the TUN route expects fake-IP mappings. The connection may still succeed, but hostname rules become less reliable and special DNS handling can be bypassed.

Core principle: TUN captures packets, Fake-IP preserves hostname identity, DNS hijack redirects resolver traffic, and RULE mode selects the egress. DNS leak prevention requires all four behaviors to agree; enabling only the TUN checkbox is not enough.

In practice, the path should look like this: an application asks for a hostname; Mihomo receives or intercepts that DNS request; the DNS module applies its policy and returns either a fake or real answer; the application opens a connection; TUN routes the packet to Mihomo; the rule engine evaluates the recorded domain or destination; and the selected proxy group or DIRECT policy forwards the flow. Each arrow is a diagnostic boundary. If the query never appears in Mihomo’s DNS log, investigate resolver interception. If a fake address appears but the connection leaves through the physical interface, investigate routes and strict-route behavior. If the packet reaches Mihomo but uses the wrong node, investigate rule order and provider rules.

Designing a Fake-IP DNS policy without breaking the LAN

A robust configuration starts by separating upstream resolver roles. nameserver entries are the normal resolvers used for ordinary queries. fallback entries can provide an alternate path when the primary response is unavailable or unsuitable, depending on the core version and fallback filter. nameserver-policy assigns resolver groups to domain patterns, which is useful when internal company names, domestic services, and proxy-bound domains should not share exactly the same upstream path. Do not copy a resolver list from an unrelated tutorial without checking whether those servers are reachable from your network and whether your privacy requirements permit their use.

The following baseline illustrates the important relationships. It is intentionally conservative: IPv6 is disabled at the core, fake-IP is enabled for transparent traffic, and common private ranges are excluded from fake-IP translation. Replace the proxy group names and resolver addresses with values appropriate to your environment.

dns:
  enable: true
  ipv6: false
  enhanced-mode: fake-ip
  fake-ip-range: 198.18.0.1/16
  fake-ip-filter-mode: blacklist
  fake-ip-filter:
    - "*.lan"
    - "*.local"
    - "+.internal"
    - "localhost.ptlogin2.qq.com"
    - "time.*.com"
  listen: 0.0.0.0:1053
  use-hosts: true
  respect-rules: true
  nameserver:
    - https://1.1.1.1/dns-query
    - https://dns.google/dns-query
  fallback:
    - tls://1.1.1.1:853
    - tls://8.8.8.8:853
  nameserver-policy:
    "geosite:private,cn":
      - 192.168.1.1
    "+.corp.example":
      - 192.168.1.10

tun:
  enable: true
  stack: mixed
  auto-route: true
  strict-route: true
  dns-hijack:
    - any:53
    - tcp://any:53

rules:
  - DOMAIN-SUFFIX,corp.example,DIRECT
  - DOMAIN-SUFFIX,lan,DIRECT
  - IP-CIDR,192.168.0.0/16,DIRECT,no-resolve
  - GEOIP,private,DIRECT
  - MATCH,Proxy

The 198.18.0.0/15 benchmarking range is commonly used for fake-IP pools because it is not intended for normal Internet routing. Some profiles use a different private range, and the exact choice is less important than keeping it consistent with the client’s documentation. Never select an address pool that overlaps with your home LAN, office VPN, container bridge, or a corporate route. If your router uses 198.18.0.0/16 for testing, choose another supported range or fake-IP mappings can collide with legitimate destinations.

fake-ip-filter deserves deliberate review. Internal suffixes such as .lan, .local, and a company namespace often need real answers because printers, NAS devices, service discovery, and split-horizon DNS do not understand synthetic addresses. A filter entry prevents fake-IP substitution; it does not automatically guarantee that the query uses the correct resolver or that the resulting packet is routed DIRECT. That is why the example pairs filters with nameserver-policy and explicit private-network rules.

Be careful with broad exclusions. Adding an entire vendor domain to the fake-IP filter because one login page failed can force many unrelated services back to real DNS and weaken domain-aware routing. Prefer the narrowest hostname pattern that fixes the application. Conversely, if an application embeds a literal IP address, Fake-IP cannot invent a hostname that was never queried. That traffic must be handled with IP rules, process rules, or application-specific proxy settings.

Hands-on setup and verification sequence

Make changes in a controlled order rather than enabling every advanced switch at once. First export or copy the working profile. A backup gives you a known-good state when a route change cuts off the GUI or makes the local management page unreachable. Next confirm that the profile already has a valid proxy group and that ordinary system-proxy traffic works. TUN should solve applications that ignore system proxy settings, not conceal a broken subscription or an unavailable node.

  1. Enable the DNS module: Turn on Mihomo DNS and select Fake-IP as the enhanced mode. Keep the default fake-IP range until you have confirmed that it does not overlap with your LAN, VPN, or container networks.
  2. Define local exceptions: Add your router address, local suffixes, printer names, NAS domains, and corporate split-DNS zones to the appropriate filter or policy list. Test these names before enabling strict routing.
  3. Enable TUN with auto-route: Use the mixed stack when the client supports both IPv4 and IPv6 capture internally. If your platform has a documented reason to prefer a specific stack, follow that platform guidance rather than assuming mixed is universally superior.
  4. Enable DNS hijack: Redirect UDP port 53 and, where supported, TCP port 53 to Mihomo. This catches applications that ignore the operating system resolver configuration. Do not assume encrypted DNS on port 443 or 853 is automatically hijacked; those flows need application-aware handling or a compatible resolver strategy.
  5. Apply strict routing carefully: Strict route prevents captured connections from silently escaping through another interface, but it can also interfere with VPN clients, virtual machines, captive portals, and local management addresses. Keep a recovery path, such as a second device or a temporarily disabled TUN switch.
  6. Restart test applications: Close and reopen browsers, terminals, launchers, and background services. Existing sockets and cached DNS answers can make a correct configuration look ineffective.

Begin testing with a simple hostname that should use the proxy. In the Mihomo dashboard, inspect the DNS result and the connection entry. A fake address in the configured pool indicates that Fake-IP answered the query. The connection log should show the original hostname, the matched rule, the selected proxy group, and the final outbound. Then test a local hostname and a private IP. Those should follow the DIRECT policy and remain reachable even when the proxy node is unavailable. Finally, disable the system proxy temporarily and launch an application that normally ignores proxy variables. If its connection appears in Mihomo through TUN, transparent capture is doing useful work rather than merely duplicating the desktop proxy.

Do not use a single browser leak-test page as your only proof. Web pages can use cached answers, DoH inside the browser, WebRTC candidates, or an already established connection. Check several layers: the client DNS log, the system resolver configuration, packet captures if you administer the machine, and the outbound connection log. A resolver query to your ISP or a manually configured public DNS server is evidence of a leak even if the final HTTP request uses the expected proxy. Conversely, seeing a local router address in a policy log may be correct when that resolver is intentionally used for internal domains.

IPv6, DNS hijack, and internal-domain edge cases

IPv6 is one of the most common reasons a setup looks secure in IPv4 tests but leaks in real use. An operating system may prefer an IPv6 route, while the TUN stack, firewall, or selected proxy path handles only IPv4. The result can be direct AAAA connections that never pass through the expected rule engine. Setting dns.ipv6: false prevents Mihomo from returning IPv6 DNS answers, but it is not a universal operating-system kill switch. If the host still has global IPv6 connectivity, consider disabling IPv6 at the adapter or router, or use a client and firewall policy that explicitly captures and routes IPv6. Make the choice intentionally; disabling DNS AAAA responses alone can create confusing delays in applications that repeatedly try IPv6 first.

DNS hijack also has boundaries. A redirect for any:53 usually targets classic UDP DNS, while some software uses TCP fallback, DoT on port 853, DoH on port 443, or an embedded resolver. Adding TCP port 53 improves coverage but does not magically decrypt DoH. Browser-level secure DNS may therefore bypass Mihomo’s DNS module while its ordinary web traffic remains inside TUN. If your requirement is centralized policy, disable browser DoH or configure it to an endpoint that your policy deliberately supports. On managed networks, document this choice so users do not turn secure DNS back on during troubleshooting and then misinterpret the different result as random instability.

Internal domains require a separate mental model. A company may publish git.corp.example only through an internal resolver, while public DNS returns nothing or a misleading address. If Fake-IP handles that name, the application can receive a synthetic address that is meaningless to a corporate VPN or local service. Use nameserver-policy to send the namespace to the internal resolver, exclude it from Fake-IP when required, and put a higher-priority DIRECT rule above broad proxy rules. Check both short names and fully qualified names because search-domain expansion can produce different queries. For multicast discovery such as mDNS, ordinary DNS hijack is not enough; service discovery may need to remain on the local link and should not be forced through a proxy.

Private IP rules should be placed before a final proxy catch-all. Include the ranges actually used by your network, such as the LAN subnet, loopback, link-local addresses, and any VPN or container ranges. The no-resolve option on IP-CIDR rules prevents unnecessary DNS resolution when the packet already contains an address. Avoid blindly copying every RFC1918 range if your organization deliberately routes one of those ranges through a remote overlay. Rules describe your topology, not an abstract “private is always local” assumption.

Reading logs instead of guessing

When a TUN configuration fails, collect one reproducible example and follow it through the logs. Record the hostname, time, application, network interface, and whether the failure affects only proxy traffic or also local services. In the DNS panel, ask whether the query arrived, which policy selected the resolver, and whether the answer was fake or real. In the connections panel, check whether Mihomo received the subsequent socket, which domain was associated with it, and which rule matched. This sequence separates DNS failure from route failure and route failure from proxy failure.

  • No DNS log entry: The application may use embedded DoH, a cached answer, a hard-coded IP, or a resolver path that your hijack rules do not capture.
  • DNS entry exists, but no connection entry: The application may be using stale data, the fake-IP mapping may have expired, or the process may have failed before opening a socket.
  • Connection matches DIRECT unexpectedly: Inspect rule order, geosite membership, process rules, and whether the connection arrived with a real IP instead of a hostname.
  • Proxy is selected but handshake times out: Test the node separately, verify time synchronization, inspect MTU, and compare IPv4 with IPv6 behavior before changing DNS lists.
  • Local services fail after strict-route: Check the route table, DNS policy, VPN adapter priority, and private ranges. Restore access to the router dashboard before making further edits.

Rule order is especially important because Mihomo stops at the first matching rule. A broad GEOIP,CN,DIRECT row above a carefully chosen domain rule can send a service through a path you did not expect. A broad PROCESS-NAME rule can affect every hostname opened by an application, including local resources that should never leave the LAN. During diagnosis, temporarily simplify the rule set: keep explicit internal DIRECT rules, a small set of known proxy domains, and one final MATCH rule. Once the data path is proven, reintroduce provider rule sets one at a time and inspect their actual order.

Recovery note: If enabling TUN removes Internet access, turn off TUN from the client before editing unrelated DNS entries. If the GUI is unreachable, use the operating system network settings to disable the virtual adapter or stop the Clash process, then restore the saved profile.

Compared with lightweight system-proxy tools that depend on every application honoring one desktop toggle, or DNS-only leak blockers that cannot classify transparent IP flows, Clash with Mihomo gives you a visible chain from resolver policy to Fake-IP mapping, TUN capture, rule match, and proxy outbound. That is particularly useful when a terminal, launcher, VPN-aware service, or background process behaves differently from a browser. If you want that auditable combination of transparent capture, per-domain exceptions, IPv6 controls, and detailed connection logs, the next practical step is to choose the appropriate client and profile from the download page.

Download Clash →