How to Set Up Clash TUN Mode: Virtual Network Adapter, Routing, and Traffic Capture
Learn how utun interfaces and auto-route work, what stack and dns-hijack do, and the permissions and checks required to enable TUN on Windows, macOS, and Linux.
Virtual Network Adapters, System Routes, and Proxy Egress
A system proxy works only when apps use the system proxy settings. TUN operates at the network layer and receives IP packets: apps open connections as usual, the operating system looks up routes, and traffic routed to the TUN interface enters the kernel. On macOS, these interfaces are usually named utun followed by a number. On Windows and Linux, check the actual startup logs and interface list for the interface name. Seeing an existing utun interface only tells you that a tunnel interface exists; it does not prove that it belongs to your Clash client.
- System routes determine what gets captured.
auto-routeautomatically configures the routes needed to direct traffic. Creating the interface does not guarantee that a destination will use it. More specific routes, policy routing, or another VPN can change the result. - Kernel rules determine where traffic exits. In
rulemode,rulesare matched in order. A connection entering TUN can still matchDIRECT, in which case the kernel connects directly. Traffic uses a proxy egress only when a rule selects a proxy group or node. - Outbound connections need a working physical network. The kernel must not route its own outbound connections back into the same TUN. On a single-interface system, try
auto-detect-interfaceto identify the outbound interface automatically. If you have wired, wireless, or other tunnel interfaces, verify which one is actually being used for egress.
mihomo TUN Configuration Fields
This guide covers fields supported by mihomo 1.19.0. First, confirm that the running core is mihomo in the client’s core information or startup logs; the GUI client’s version number alone is not enough. If you use a subscription, merge the examples into your local overrides or managed configuration, keeping your existing proxies, proxy-groups, and rules. Do not add two top-level tun or dns sections to the same YAML file. After applying the configuration, check what the client actually passes to the core.
mode: rule
tun:
enable: true
stack: mixed
auto-route: true
auto-detect-interface: true
dns-hijack:
- any:53
- tcp://any:53
dns:
enable: true
enhanced-mode: fake-ip
fake-ip-range: 198.18.0.1/16
nameserver:
- 1.1.1.1
| Field | Purpose and troubleshooting tips |
|---|---|
enable | Enables TUN. If the configuration loads but no interface appears, first check the permissions required to create one and review the startup logs. |
stack | system uses the system network stack, gvisor uses a userspace stack, and mixed uses the system stack for TCP and gVisor for UDP. After switching, test the same destination again to distinguish stack compatibility issues from routing problems. |
auto-route | Automatically configures routes to direct traffic. When set to false, enabling TUN alone will not send app traffic through the virtual adapter unless another route points to it. |
auto-detect-interface | Automatically selects the kernel’s outbound interface. If connections fail after switching between Wi-Fi, Ethernet, or a VPN, check the current egress interface first. If you need to bind it explicitly, weigh the top-level interface-name setting against automatic detection. |
dns-hijack | Sends DNS queries entering TUN that match the configured rules to the kernel’s DNS module. any:53 covers UDP port 53; tcp://any:53 adds TCP port 53. Neither matches DoH queries sent by browsers over HTTPS. |
The example sends regular domain queries to 1.1.1.1. This is a plain-text upstream resolver; it does not mean DNS is encrypted or routed through a proxy. If you have enterprise DNS policies for internal domains, keep settings such as nameserver-policy and do not replace internal resolvers with a public DNS server. fake-ip returns synthetic addresses for eligible queries, which the kernel maps back to domain names. If your network ranges overlap with the example address pool, resolve the address conflict first. See the configuration reference for more fields.
TUN Permissions on Windows, macOS, and Linux
First, confirm that your subscription, rules, and nodes work in system proxy mode, and save a configuration you can restore. Before testing TUN, turn off the system proxy and any proxy configured separately in apps, and temporarily disable other tunnels that capture the same traffic. This prevents a working web page from being mistaken for proof that TUN captured the traffic when it was actually using a regular proxy port.
Windows: Service Mode or Administrator Privileges
Creating a virtual network adapter and changing routes requires the appropriate permissions. If your client offers service mode, install and start the service as instructed before enabling TUN. If the client requires elevated permissions, follow its prompt to run it as an administrator. Menu labels vary between clients, and installing a service does not necessarily mean it is running.
Run the following commands in PowerShell before and after enabling TUN. Compare the interface lists, then check which route the system selects for the example IPv4 destination. The default gateway may remain unchanged even when a more specific route takes effect.
Get-NetIPInterface -AddressFamily IPv4
>Find-NetRoute -RemoteIPAddress 1.1.1.1
macOS: Helper Services and utun Interfaces
Grant the helper service or required network permissions as prompted by the client, then enable TUN. If a VPN is already running, note the interfaces and routes before you start; do not assume the highest-numbered utun is the interface just created. Use the commands below to inspect the interface list and the interface field for a specific destination, then compare them with the kernel logs.
ifconfig -l
route -n get 1.1.1.1
scutil --dns
scutil --dns shows the active resolvers and their scopes; it does not, by itself, prove which route DNS queries take. If work domains use a separate VPN resolver, compare the resolver scope for those domains before and after switching.
Linux: TUN Device and Network Administration Permissions
The kernel process needs access to /dev/net/tun and permission to create network interfaces and configure routes in its network namespace; CAP_NET_ADMIN is commonly required. Prefer the service mode provided by your client. In a container, also check that the device is passed through. Even if an interface is created successfully inside the container, route changes apply only to the process’s network namespace and will not automatically capture all traffic from the host.
ls -l /dev/net/tun
ip -brief link
ip rule show
ip route get 1.1.1.1
If the interface exists but traffic to a destination still uses the physical adapter, check the priority order in ip rule show for rules that match first. Looking only at the main routing table can miss policy routing tables used by the kernel or another VPN.
Verify Traffic Capture: Routes, Rules, DNS, and UDP
- Check the interface and routes first. Run the commands for your platform, replace
1.1.1.1with the destination you want to check, and compare the results with the startup logs. The example commands cover IPv4 only. If an app prefers IPv6, check the route to an actual IPv6 destination separately. An IPv4 test does not prove that IPv6 is captured. - Then check the rules and egress. Start a new connection without an explicitly configured proxy, then use its timestamp and destination to find the matching rule and egress in the client’s connection list or kernel logs. If the page loads but the connection shows
DIRECT, the kernel may have captured it and the rule simply chose a direct connection. Reconnect after changing rules; do not judge the result using a connection already reused by the browser. - Test regular DNS separately from app-level resolution. Run
nslookup example.org 1.1.1.1to make a regular DNS query. If it enters TUN and matches an interception rule, the server specified in the command is not necessarily the final upstream resolver. Compare the result with the DNS logs available in the kernel. With the examplefake-ipsetting, eligible A record queries may return addresses in198.18.0.0/16. Filter lists, cached responses, and app-specific DoH can all change the result. - Test UDP separately at the end. A page loading successfully may only mean TCP is working. Start a new session in an app you normally use over UDP and check whether the selected egress supports UDP. A response from the local DNS module does not prove that the remote proxy node can forward UDP.
What to Check If Your Connection Drops After Enabling TUN
- No new interface: Check the service status, device permissions, and the first error reported during interface creation. Changing the DNS upstream is unlikely to help at this stage.
- Interface exists, but the connection never reaches the kernel: Check the route to the destination, whether an old connection is being reused, and whether the app has its own proxy configured. First rule out another VPN’s higher-priority route to the same destination.
- Connection reaches the kernel, but egress fails: Check the node selected by the rule and the physical egress interface, especially if the problem started after switching from Ethernet to Wi-Fi. If only UDP fails, check the node protocol’s UDP support and the
stacksetting. - Internet access works, but local network or internal domains fail: Check routes to internal destinations and their dedicated DNS settings separately.
DIRECTin a rule is a direct connection decision after traffic is captured; it is not the same as excluding an address range at the routing layer.
To restore network access, turn off TUN in the client first and wait for the service to undo its routing changes, then check the route to the destination again. If routing is still abnormal, check the related service and other VPNs; do not flush the entire routing table. Once basic connectivity is restored, switch back to the system proxy or configuration that worked before.