Skip to main content
EN

Home / Blog / DNS & Networking

TUN internals — how the virtual adapter, routing table and DNS hijacking work together

DNS & Networking2026-06-261408 words3 min read
TUN internals — how the virtual adapter, routing table and DNS hijacking work together

The instant you flip the TUN switch, three things happen on your system: a network adapter appears, the routing table is rewritten, and port 53 is hijacked.

Understand those three and every awkward TUN problem has a direction to investigate.

1. Creating the virtual adapter

TUN is a kind of virtual network device provided by the operating system. As far as the system is concerned it is an ordinary adapter, except the other end is not a physical cable but a userspace program — here, the Mihomo core.

A packet's journeyApplicationemits an IP packetSystem routingdecides which adapter it leaves byTUN virtual adapterthe packet is handed to the core programMihomo processes itdecides direct or forwarded, by rule
Entirely transparent to the application, which believes it is on the network normally

Per-platform implementations:

PlatformImplementationPrivileges required
WindowsThe wintun driverAdministrator (installing a driver plus a system service)
macOSThe utun kernel extensionroot (a privileged helper)
Linux/dev/net/tunCAP_NET_ADMIN

Clash Verge's "service mode" exists precisely to avoid asking for elevation every time — install the system service once and it performs the privileged operations from then on.

2. Rewriting the routing table

An adapter alone is not enough; the system has to be told to send traffic to it. That is done by modifying routes.

With auto-route: true, the core adds routes like:

0.0.0.0/1    → TUN adapter
128.0.0.0/1  → TUN adapter

Why two /1 routes rather than one 0.0.0.0/0?

Because route matching follows longest-prefix-first. The system's existing default route is 0.0.0.0/0; if TUN also claimed 0.0.0.0/0, two routes of equal length would be ambiguous. Split into two /1 routes, the prefix is longer, so they reliably beat the original default — while leaving that default in place, so the core's own outbound traffic can still get out normally.

Route priority, highest first1Specific host routes 322The two TUN 1 routes3The original default route 0
A node server's IP must go via the physical adapter, otherwise its traffic loops back into TUN

auto-detect-interface: true lets the core work out the real outbound adapter (Wi-Fi or Ethernet) so it follows along when you change networks.

What strict-route does

tun:
  strict-route: true

This adds stricter routing rules and firewall policy so nothing can slip past TUN. The side effect is a higher chance of conflict with other VPN software.

Turn it off when you need to coexist with a VPN.

Excluding a specific adapter

For coexistence with a corporate VPN:

tun:
  exclude-interface: ["ppp0", "Cisco AnyConnect"]

3. DNS hijacking

tun:
  dns-hijack:
    - any:53

Meaning: any DNS query sent to port 53, whatever server it was addressed to, is intercepted and answered by the core's own resolver.

Why this is necessary: some programs hard-code a DNS server (querying 8.8.8.8 directly, say), bypassing your system settings. Without hijacking, those queries take the original path out, which means:

  • Inaccurate answers (possibly poisoned)
  • Lost domain information, leaving the core to match rules on IP alone
  • A DNS leak — your ISP can see which names you looked up
With and without DNS hijackingProgram hard-codes a query to 8.8.8.8sends a UDP packet to port 53Without hijackingthe packet is forwarded through TUN to 8.8.8.8With hijackingthe core intercepts and answers it itselfResultthe former may be poisoned and leaks, the latter is unde
Under TUN, dns-hijack is essentially mandatory

4. The stack: gvisor, system or mixed

TUN receives raw IP packets, so it needs a TCP/IP stack to reassemble them into connections. Three implementations:

The trade-off between the three stacksgvisora userbest compatibilityslightly lower performancethe default recommendationsystemhandedhighest performancedemanding about system configuration, worse compatibilityfor chasing maximum throughputmixedTCP onthe middle paththe best answer for most casesMihomo's usual default
When something goes wrong, switch to gvisor first — it is the least likely to misbehave

Guidance:

SituationChoose
Unsure / first-time setupmixed
Strange connection problemsgvisor
Soft router, chasing throughputsystem
UDP problems on macOSgvisor

5. MTU and fragmentation

tun:
  mtu: 1500

MTU is the maximum size of a single packet. Set the TUN adapter's MTU larger than the real link supports and packets get fragmented, hurting performance; set it too small and transfer efficiency drops.

1500 is the Ethernet standard and usually needs no change. But if your node runs over a link that already carries encapsulation overhead (certain relays, a PPPoE connection), the usable MTU is below 1500 and you may need 1400–1450.

6. A complete TUN configuration

tun:
  enable: true
  stack: mixed
  device: Mihomo
  auto-route: true
  auto-detect-interface: true
  auto-redirect: false          # extra redirection on Linux
  strict-route: false
  mtu: 1500
  dns-hijack:
    - any:53
    - tcp://any:53
  # exclude adapters to avoid VPN conflicts
  # exclude-interface: ["ppp0"]
  # exclude specific apps (Mihomo)
  # exclude-package: ["com.example.app"]   # Android

The DNS configuration that goes with it:

dns:
  enable: true
  enhanced-mode: fake-ip
  fake-ip-range: 198.18.0.1/16
  fake-ip-filter:
    - "*.lan"
    - "*.local"
    - "+.pool.ntp.org"
    - "+.msftconnecttest.com"
    - "+.msftncsi.com"
  nameserver: [223.5.5.5, https://doh.pub/dns-query]

DNS has to be configured alongside — TUN has taken over all traffic, so if DNS is wrong nothing resolves at all.

The underlying cause of common problems

SymptomUnderlying causeFix
Everything dies after enabling TUNRoutes were rewritten but the core's own traffic loops backConfirm auto-detect-interface: true; restart
Network does not recover after closing the appThe process was force-killed so routes were never withdrawnStart Clash Verge again and quit properly, or reboot
LAN devices unreachableNo direct rule for private rangesAdd IP-CIDR,192.168.0.0/16,DIRECT,no-resolve
NAS or printer not foundmDNS names caught by fake-ipAdd "*.local" and "*.lan" to fake-ip-filter
Conflicts with the corporate VPNBoth rewrite the routing tableTurn off strict-route, use exclude-interface
System reports "no internet connection"The connectivity-check name went through fake-ipAdd "+.msftconnecttest.com" to the filter
Large downloads stallOversized MTU causing fragment lossSet mtu to 1400
UDP games will not connectThe node does not support UDP, or the stack is wrongConfirm udp: true on the node, switch the stack to gvisor
High CPU useAll traffic passes through a userspace stackSwitch the stack to system, or drop TUN and use the system proxy

Verifying that TUN is really working

Look at the adapter:

# Windows
Get-NetAdapter | Where-Object {$_.InterfaceDescription -like "*wintun*"}
# Linux / macOS
ip link show    # or ifconfig

You should see an adapter named Mihomo or utunX.

Look at the routes:

# Windows
route print -4
# Linux
ip route show

You should see two /1 routes pointing at the TUN adapter.

Check that traffic really goes through:

Open the connections page in Clash Verge and use a program that definitely ignores the system proxy — command-line curl with no environment variables set, for instance — to reach the internet. An entry appearing on the connections page means TUN is in effect.

In short

The three things TUN does:

  • A virtual adapter — needs a driver and privileges, which service mode handles
  • The routing table — two /1 routes take over everything, with node IPs pinned to the physical adapter
  • DNS hijacking — stops hard-coded resolvers from bypassing the core

When something breaks, work through those three layers: is the adapter there → are the routes right → does DNS work.

Related: DNS and fake-ip explained and split tunnelling in practice.


Related docs

Clash DNS configuration — fake-ip or redir-host?
DNS & Networking Clash DNS configuration — fake-ip or redir-host?

How fake-ip actually works, how it differs from redir-host, the division of labour between nameserver and fallback, how to prevent DNS leaks, and why internal hostnames stop resolving.

2026-07-131433 words3 min read