Skip to content

Hysteria2 — mihomo

mihomo 双端支持 Hysteria2。出站显式提供端口跳变字段以及大量 quic-go 流控旋钮。入站的用户表是扁平映射 —— 每条目一个用户名 / 密码对。

出站

proxies:type: hysteria2 条目。内嵌 BasicOption(通用出站 字段:interface-namerouting-mark 等)。

字段类型默认值允许值描述
namestring(required)<string>唯一的代理名。
serverstring(required)<host>上游服务器主机名或 IP。
portint(unset)<port>单一服务器端口。`ports` 已设置时省略。
portsstring(unset)<port-list>端口跳变列表。接受单端口与范围混合,以逗号分隔,例如 `"20000,20002-20100"`。与 `hop-interval` 配套使用。
hop-intervalstring30<seconds string> | <duration>两次端口跳变之间的时长。纯数字字符串(`"30"`)按秒处理;也接受 Go 风格时长(`"30s"`)。最小值 5(`adapter/outbound/hysteria2.go:25`)。
upstring(unset)<bandwidth>上行带宽。带单位字符串,如 `"100 Mbps"`、`"500 kbps"`、`"1 Gbps"`。
downstring(unset)<bandwidth>下行带宽,格式同上。
passwordstring(unset)<string>用户鉴权密码。仅当服务端允许匿名连接时可选。
obfsstring(disabled)salamander混淆类型。目前仅 `salamander` 有效。
obfs-passwordstring(unset)<string>混淆密码(与用户密码相互独立)。
obfs-min-packet-sizeint0<bytes>Salamander 混淆的最小随机填充大小。仅在 `obfs: salamander` 时有意义。
obfs-max-packet-sizeint0<bytes>Salamander 混淆的最大随机填充大小。
snistring(server)<SNI>TLS Server Name Indication。默认为 `server`。
ech-optsECHOptions(disabled)ECHOptionsEncrypted Client Hello 配置。
skip-cert-verifyboolfalsetrue | false禁用 TLS 校验(仅供测试)。
fingerprintstring(unset)<SHA256 hex>锚定服务端 TLS 证书指纹。
certificatestring(unset)<PEM file path>客户端证书(mTLS)。
private-keystring(unset)<key file path>与 `certificate` 配对的私钥。
alpn[]string[h3]h3ALPN 列表。Hysteria2 通常使用 `h3`。
cwndint0<int>QUIC 初始拥塞窗口覆盖。
bbr-profilestring(unset)default | aggressive内置 Brutal / BBR 变体的调优 profile。
udp-mtuint1200<bytes>在 QUIC 数据报中分片 UDP 载荷时使用的 MTU。
realm-optsHysteria2RealmOption(disabled)Hysteria2RealmOption经由 Hysteria2 *realm* 连接 —— 一种通过控制端点访问的多租户服务器。见下方 realm-opts 表。
initial-stream-receive-windowuint640 (quic-go default)<bytes>单流初始流控窗口。
max-stream-receive-windowuint640 (quic-go default)<bytes>单流最大流控窗口。
initial-connection-receive-windowuint640 (quic-go default)<bytes>整连接初始流控窗口。
max-connection-receive-windowuint640 (quic-go default)<bytes>整连接最大流控窗口。

源码: adapter/outbound/hysteria2.go:39-71 · 锚定版本 v1.19.27 (5184081)

入站

listeners:type: hysteria2 条目。内嵌 BaseOptionlistenport)。

字段类型默认值允许值描述
usersmap[string]string{}{<username>: <password>}用户表 —— 用户名到密码的映射。为空允许匿名连接。
obfsstring(disabled)salamanderSalamander 混淆类型。
obfs-passwordstring(unset)<string>混淆密码。
obfs-min-packet-sizeint0<bytes>Salamander 混淆的最小随机填充大小。仅在 `obfs: salamander` 时有意义。
obfs-max-packet-sizeint0<bytes>Salamander 混淆的最大随机填充大小。
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 配置 / 密钥。
max-idle-timeint0<seconds>监听器侧的空闲超时。0 使用 QUIC 默认。
alpn[]string[h3]h3TLS 握手时宣告的 ALPN 列表。
upstring(unset)<bandwidth>上行带宽(带单位字符串)。
downstring(unset)<bandwidth>下行带宽。
ignore-client-bandwidthboolfalsetrue | false丢弃客户端宣告的带宽,强制使用服务端设置。
masqueradestring(unset)<URL>伪装目标 —— 字符串 URL(`file:///path` 或 `https://upstream/`)。
cwndint0<int>QUIC 初始拥塞窗口。
bbr-profilestring(unset)default | aggressiveBrutal / BBR 调优 profile。
udp-mtuint1200<bytes>UDP 数据报分片 MTU。
mux-optionMuxOption(disabled)MuxOptionsing 风格多路复用设置。
realm-optsHysteria2RealmOption(disabled)Hysteria2RealmOption经由 Hysteria2 *realm* 连接 —— 一种通过控制端点访问的多租户服务器。见下方 realm-opts 表。
initial-stream-receive-windowuint640 (quic-go default)<bytes>单流初始流控窗口。
max-stream-receive-windowuint640 (quic-go default)<bytes>单流最大流控窗口。
initial-connection-receive-windowuint640 (quic-go default)<bytes>整连接初始流控窗口。
max-connection-receive-windowuint640 (quic-go default)<bytes>整连接最大流控窗口。

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

realm-opts

出站与入站的 realm-opts 块共享同一结构。在出站上,它通过一个控制 端点把代理指向某个 Hysteria2 realm —— 即托管在多 realm 服务器上的 一个租户 —— 该端点会回传实际的连接详情。realm 模式是较新的进阶 特性;除非你正在连接 realm 服务器,否则请保持禁用。

字段类型默认值允许值描述
enableboolfalsetrue | false为该代理启用 realm 模式。
server-urlstring(unset)<URL>realm 控制服务器的 URL,用于获取 realm 连接详情。
tokenstring(unset)<string>向 realm 控制服务器出示的鉴权 token。
realm-idstring(unset)<string>要加入的 realm 标识符。
stun-servers[]string(unset)<host:port list>用于 realm NAT 穿透的 STUN 服务器。
snistring(unset)<SNI>控制服务器连接的 TLS SNI。
skip-cert-verifyboolfalsetrue | false对控制服务器跳过 TLS 校验(仅供测试)。
fingerprintstring(unset)<SHA256 hex>锚定控制服务器的 TLS 证书指纹。
certificatestring(unset)<PEM file path>面向控制服务器的客户端证书(mTLS)。
private-keystring(unset)<key file path>与 `certificate` 配对的私钥。
alpn[]string(unset)<string list>控制服务器连接的 ALPN。

源码: adapter/outbound/hysteria2.go:73-87 · 锚定版本 v1.19.27 (5184081)

示例

出站 —— 单端口、salamander 混淆、100 / 300 Mbps:

yaml
proxies:
  - name: hy2-plain
    type: hysteria2
    server: example.com
    port: 443
    password: <password>
    obfs: salamander
    obfs-password: <obfs>
    sni: example.com
    up: 100 Mbps
    down: 300 Mbps
    alpn: [h3]

出站 —— 在 20000-20100 端口范围内跳变:

yaml
proxies:
  - name: hy2-hop
    type: hysteria2
    server: example.com
    ports: 20000-20100
    hop-interval: 30s
    password: <password>
    obfs: salamander
    obfs-password: <obfs>
    sni: example.com
    up: 200 Mbps
    down: 1 Gbps
    alpn: [h3]

出站 —— 经由控制服务器连接某个 realm:

yaml
proxies:
  - name: hy2-realm
    type: hysteria2
    server: example.com
    port: 443
    password: <password>
    sni: example.com
    alpn: [h3]
    realm-opts:
      enable: true
      server-url: https://realm.example.com/control
      token: <realm-token>
      realm-id: team-a
      stun-servers:
        - stun.example.com:3478

入站,含两用户与 HTTP-file 伪装:

yaml
listeners:
  - name: hy2-in
    type: hysteria2
    listen: 0.0.0.0
    port: 443
    users:
      alice: <alice-password>
      bob: <bob-password>
    obfs: salamander
    obfs-password: <obfs>
    certificate: /etc/mihomo/server.crt
    private-key: /etc/mihomo/server.key
    up: 500 Mbps
    down: 1 Gbps
    masquerade: file:///var/www
    alpn: [h3]

说明

  • ports 接受单端口与范围混合,以逗号分隔,如 "20000,20002-20100,30000"portports 互斥 —— 二选一。 设置 ports 后,mihomo 每隔 hop-interval 随机挑选一个新成员 拨号。
  • hop-interval 最小值为 5 秒adapter/outbound/hysteria2.go:25),低于 5 会被向上钳制。
  • 带宽值接受带单位后缀(bkbpsMbpsGbpsTbps), 数字与单位之间需要空格 —— "100 Mbps"。字符串由 mihomo 的 tools.StringToBps 辅助函数解析。
  • obfs-min-packet-sizeobfs-max-packet-size 仅在 obfs: salamander 时生效。它们为 Salamander 混淆器设置随机填充 的上下界;在任何其他(或没有)obfs 下都会被忽略。
  • mihomo 入站 users 是 YAML 映射而非对象列表。键是用户名、值是 密码,例如 users: { alice: pw1, bob: pw2 }。要允许匿名连接, 保持映射为空。
  • 四个 *-receive-window 字段是内置 quic-go 栈的直接旋钮。多数 用户保持 0(默认)即可。在高 BDP 链路上可调高 connection 级 窗口以提升吞吐。

跨内核说明

  • Xray-core 把配置拆到 settings(version / clients)与 streamSettings.hysteriaSettings(auth / 带宽 / 伪装)。参见 Hysteria2 — Xray-core
  • sing-box 把配置放在单块中,但带宽使用 整数 Mbps(无单位 后缀),且 masquerade 字段多态(字符串 URL 或类型化对象)。 参见 Hysteria2 — sing-box
  • mihomo 也可以 托管 realm —— 参见 Hysteria2 realm 监听器

源码: adapter/outbound/hysteria2.go:39-87 · v1.19.27 (5184081)

由 Argsment 出品的 Core Tutorial