Mihomo 内核 TUN 模式深度配置:系统级透明代理实战

Mihomo TUN 模式简介

TUN 模式是 Mihomo (Clash Meta) 内核最强大的功能之一,通过创建虚拟网卡实现系统级透明代理。与传统 HTTP/SOCKS5 代理不同,TUN 模式无需应用支持即可拦截和代理所有网络流量,包括不支持代理设置的软件。

TUN 模式原理

TUN (Tunnel) 是一种虚拟网络设备,工作在 OSI 第三层(网络层)。Mihomo 通过创建 TUN 设备,将系统流量重定向到 Clash 内核处理,实现真正的全局代理。

配置详解

tun:
  enable: true
  stack: system  # system/gvisor/mixed
  dns-hijack:
    - 8.8.8.8:53
    - 8.8.4.4:53
  auto-route: true
  auto-detect-interface: true
  mtu: 9000
  strict-route: false
  inet4-address: 198.18.0.1/16
  inet6-address: fc00::/18
  endpoint-independent-nat: false

Stack 模式对比

模式 优点 缺点 适用场景
system 性能最好 兼容性一般 Windows/macOS
gvisor 兼容性好 CPU 占用略高 Linux/特殊环境
mixed 自动选择 配置复杂 通用推荐

DNS 配置

dns:
  enable: true
  listen: 0.0.0.0:53
  enhanced-mode: fake-ip
  fake-ip-range: 198.18.0.1/16
  nameserver:
    - https://doh.pub/dns-query
    - https://dns.alidns.com/dns-query
  fallback:
    - https://8.8.8.8/dns-query
    - https://1.1.1.1/dns-query
  fallback-filter:
    geoip: true
    geoip-code: CN

常见问题

  • 无法上网:检查 auto-route 和 auto-detect-interface 设置
  • DNS 泄漏:确保 dns-hijack 包含所有 DNS 服务器
  • 部分应用不走代理:检查 strict-route 设置

推荐资源

机场推荐:https://clashhub.net/85-2

客户端下载:https://clashhub.net/290

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注