Skip to content

TUIC — mihomo

mihomo 双端同时支持 TUIC v4(基于 token)与 TUIC v5(UUID + 密码)。 声明入站有两种方式:标准的 listeners: 条目,或顶层 tuic-server 块。

出站

proxies:type: tuic 条目。内嵌 BasicOption

字段类型默认值允许值描述
namestring(required)<string>唯一的代理名。
serverstring(required)<host>上游服务器主机名或 IP。
portint(required)<port>上游服务器端口。
tokenstring(unset)<string>旧式 TUIC v4 令牌。与 `uuid` + `password`(v5)互斥。
uuidstring(required for v5)<UUID>用户 UUID(TUIC v5)。
passwordstring(required for v5)<string>用户密码(TUIC v5)。
ipstring(unset)<host>解析后覆盖目的 IP。当 SNI / 证书对应的名称与真实服务器 IP 不同时使用。
heartbeat-intervalint10000<milliseconds>QUIC 心跳间隔。**毫秒**,不是秒。
alpn[]string[h3]h3ALPN 列表。TUIC 要求 HTTP/3 ALPN。
reduce-rttboolfalsetrue | false重连时使用 0-RTT 握手。
request-timeoutint8000<milliseconds>等待 connect 帧响应的超时(毫秒)。
udp-relay-modestringnativenative | quicUDP 隧道方式。`native`(数据报)更快;`quic`(每包一流)能穿透屏蔽 QUIC 数据报的中间盒。
congestion-controllerstringcubiccubic | new_reno | bbr | bbr_meta_v1 | bbr_meta_v2QUIC 拥塞控制器。`bbr` 是 mihomo 的 v2 BBR;`bbr_meta_v1` / `bbr_meta_v2` 保留旧变体以保兼容。
disable-sniboolfalsetrue | false完全省略 ClientHello 中的 SNI 扩展。
max-udp-relay-packet-sizeint1252<bytes>分片前的 UDP 载荷最大字节数。
fast-openboolfalsetrue | false把代理请求帧与 QUIC 握手并发送出。
max-open-streamsint100<int>每个 QUIC 连接的最大并发流数。
cwndint32<int>初始拥塞窗口(包数)。默认 32(`transport/tuic/common/congestion.go:17-19`)。
bbr-profilestring(unset)default | aggressive`congestion-controller: bbr` 时的 BBR 调优 profile。
skip-cert-verifyboolfalsetrue | false禁用 TLS 校验(仅供测试)。
fingerprintstring(unset)<SHA256 hex>锚定服务端 TLS 证书指纹。
certificatestring(unset)<PEM file path>客户端证书(mTLS)。
private-keystring(unset)<key file path>与 `certificate` 配对的私钥。
recv-window-connint0<bytes>整连接初始接收窗口。0 使用 quic-go 默认。
recv-windowint0<bytes>单流初始接收窗口。0 使用 quic-go 默认。
disable-mtu-discoveryboolfalsetrue | false跳过路径 MTU 探测;在丢弃 probe 的网络上有用。
max-datagram-frame-sizeint1252<bytes>QUIC 数据报帧最大字节数。
snistring(server)<SNI>TLS Server Name Indication。
ech-optsECHOptions(disabled)ECHOptionsEncrypted Client Hello 配置。
udp-over-streamboolfalsetrue | false使用 UDP-over-stream 帧替代 QUIC 数据报。
udp-over-stream-versionint11帧版本。当前仅定义 1。

源码: adapter/outbound/tuic.go:34-69 · 锚定版本 v1.19.27 (5184081)

入站(listeners 下)

listeners:type: tuic 条目。内嵌 BaseOption

字段类型默认值允许值描述
token[]string[][<string>]旧式 TUIC v4 令牌列表。为空则禁用 v4。
usersmap[string]string{}{<uuid>: <password>}TUIC v5 用户表。键为 UUID,值为密码。
certificatestring(required)<PEM file path>TLS 服务端证书。
private-keystring(required)<key file path>TLS 私钥。
client-auth-typestring(none)no-client-cert | request-client-cert | require-any-client-cert | verify-client-cert-if-given | require-and-verify-client-certmTLS 客户端鉴权模式。
client-auth-certstring(unset)<PEM file path>作为客户端根的 CA 集合。
ech-keystring(unset)<ECH config>Encrypted Client Hello 配置 / 密钥。
congestion-controllerstringcubiccubic | new_reno | bbr | bbr_meta_v1 | bbr_meta_v2服务端 QUIC 拥塞控制器。
max-idle-timeint0<milliseconds>QUIC 连接空闲超时。0 使用 QUIC 默认。
authentication-timeoutint1000<milliseconds>等待客户端鉴权帧的最长时间(毫秒)。
alpn[]string[h3]h3TLS 握手时宣告的 ALPN 列表。
max-udp-relay-packet-sizeint1252<bytes>接受的最大 UDP 载荷。
cwndint32<int>初始拥塞窗口(包数)。
bbr-profilestring(unset)default | aggressiveBBR 调优 profile。
mux-optionMuxOption(disabled)MuxOptionsing 风格多路复用设置。

源码: listener/inbound/tuic.go:12-29 · 锚定版本 v1.19.27 (5184081)

入站(顶层 tuic-server

顶层 tuic-server 块是声明 TUIC 入站的另一种方式,出于历史原因 保留。新配置建议使用 listener 形式(与入站模型其余部分组合更自然)。

字段类型默认值允许值描述
enableboolfalsetrue | false顶层 TUIC 入站总开关。为 false 时块内其他字段被忽略。
listenstring127.0.0.1:0<host:port>监听地址。语法与 mihomo 其他位置一致。
token[]string[][<string>]TUIC v4 令牌列表。
usersmap[string]string{}{<uuid>: <password>}TUIC v5 用户表。
certificatestring(required)<PEM file path>TLS 服务端证书。
private-keystring(required)<key file path>TLS 私钥。
congestion-controllerstringcubiccubic | new_reno | bbr | bbr_meta_v1 | bbr_meta_v2服务端 QUIC 拥塞控制器。
max-idle-timeint0<milliseconds>QUIC 空闲超时。
authentication-timeoutint1000<milliseconds>客户端鉴权帧超时。
alpn[]string[h3]h3ALPN 列表。
max-udp-relay-packet-sizeint1252<bytes>最大 UDP 载荷。
cwndint32<int>初始拥塞窗口。

源码: config/config.go:323-336 · 锚定版本 v1.19.27 (5184081)

示例

出站 —— TUIC v5:

yaml
proxies:
  - name: tuic-v5
    type: tuic
    server: example.com
    port: 443
    uuid: a3482e88-686a-4a58-8126-99c9df64b7bf
    password: <password>
    udp-relay-mode: native
    congestion-controller: bbr
    sni: example.com
    alpn: [h3]
    heartbeat-interval: 10000
    reduce-rtt: true

出站 —— TUIC v4(旧式):

yaml
proxies:
  - name: tuic-v4
    type: tuic
    server: example.com
    port: 443
    token: <token>
    udp-relay-mode: native
    sni: example.com
    alpn: [h3]

listeners 下的入站:

yaml
listeners:
  - name: tuic-in
    type: tuic
    listen: 0.0.0.0
    port: 443
    users:
      a3482e88-686a-4a58-8126-99c9df64b7bf: <alice password>
      6f4e6c2c-8b1d-4b4f-8e2e-1f2b5c9e0a3b: <bob password>
    certificate: /etc/mihomo/server.crt
    private-key: /etc/mihomo/server.key
    congestion-controller: bbr
    alpn: [h3]

顶层 tuic-server(旧形态):

yaml
tuic-server:
  enable: true
  listen: 0.0.0.0:443
  users:
    a3482e88-686a-4a58-8126-99c9df64b7bf: <password>
  certificate: /etc/mihomo/server.crt
  private-key: /etc/mihomo/server.key
  congestion-controller: bbr
  alpn: [h3]

说明

  • mihomo 的 TUIC 出站使用 毫秒 表示超时与间隔(不是秒)—— heartbeat-interval: 10000 即 10 秒。request-timeout 与入站的 authentication-timeout 也遵循同样约定。
  • 五种拥塞控制器在 transport/tuic/common/congestion.go:20-53 中接入。 bbr 是现代 v2 实现;bbr_meta_v1 / bbr_meta_v2 仅为兼容旧客户端 保留。
  • cwnd: 0 在运行时按 32 包处理 (transport/tuic/common/congestion.go:17-19)。
  • 顶层 tuic-server 块只能声明 一个 TUIC 入站。多端口多入站 请使用 listeners: 形式。

跨内核说明

  • Xray-core 不支持 TUIC。参见 TUIC — Xray-core
  • sing-box 仅支持 TUIC v5(无 token 形式),字段名为 snake_case (congestion_controludp_relay_mode),超时接受 Go 风格时长 字符串("3s"),且拥塞控制选择更少(cubicnew_renobbr)。 参见 TUIC — sing-box

源码: adapter/outbound/tuic.go:34-69 · v1.19.27 (5184081)

由 Argsment 出品的 Core Tutorial