Hysteria2 — mihomo
mihomo 双端支持 Hysteria2。出站显式提供端口跳变字段以及大量 quic-go 流控旋钮。入站的用户表是扁平映射 —— 每条目一个用户名 / 密码对。
出站
proxies: 下 type: hysteria2 条目。内嵌 BasicOption(通用出站 字段:interface-name、routing-mark 等)。
| 字段 | 类型 | 默认值 | 允许值 | 描述 |
|---|---|---|---|---|
name | string | (required) | <string> | 唯一的代理名。 |
server | string | (required) | <host> | 上游服务器主机名或 IP。 |
port | int | (unset) | <port> | 单一服务器端口。`ports` 已设置时省略。 |
ports | string | (unset) | <port-list> | 端口跳变列表。接受单端口与范围混合,以逗号分隔,例如 `"20000,20002-20100"`。与 `hop-interval` 配套使用。 |
hop-interval | string | 30 | <seconds string> | <duration> | 两次端口跳变之间的时长。纯数字字符串(`"30"`)按秒处理;也接受 Go 风格时长(`"30s"`)。最小值 5(`adapter/outbound/hysteria2.go:25`)。 |
up | string | (unset) | <bandwidth> | 上行带宽。带单位字符串,如 `"100 Mbps"`、`"500 kbps"`、`"1 Gbps"`。 |
down | string | (unset) | <bandwidth> | 下行带宽,格式同上。 |
password | string | (unset) | <string> | 用户鉴权密码。仅当服务端允许匿名连接时可选。 |
obfs | string | (disabled) | salamander | 混淆类型。目前仅 `salamander` 有效。 |
obfs-password | string | (unset) | <string> | 混淆密码(与用户密码相互独立)。 |
obfs-min-packet-size | int | 0 | <bytes> | Salamander 混淆的最小随机填充大小。仅在 `obfs: salamander` 时有意义。 |
obfs-max-packet-size | int | 0 | <bytes> | Salamander 混淆的最大随机填充大小。 |
sni | string | (server) | <SNI> | TLS Server Name Indication。默认为 `server`。 |
ech-opts | ECHOptions | (disabled) | ECHOptions | Encrypted Client Hello 配置。 |
skip-cert-verify | bool | false | true | false | 禁用 TLS 校验(仅供测试)。 |
fingerprint | string | (unset) | <SHA256 hex> | 锚定服务端 TLS 证书指纹。 |
certificate | string | (unset) | <PEM file path> | 客户端证书(mTLS)。 |
private-key | string | (unset) | <key file path> | 与 `certificate` 配对的私钥。 |
alpn | []string | [h3] | h3 | ALPN 列表。Hysteria2 通常使用 `h3`。 |
cwnd | int | 0 | <int> | QUIC 初始拥塞窗口覆盖。 |
bbr-profile | string | (unset) | default | aggressive | 内置 Brutal / BBR 变体的调优 profile。 |
udp-mtu | int | 1200 | <bytes> | 在 QUIC 数据报中分片 UDP 载荷时使用的 MTU。 |
realm-opts | Hysteria2RealmOption | (disabled) | Hysteria2RealmOption | 经由 Hysteria2 *realm* 连接 —— 一种通过控制端点访问的多租户服务器。见下方 realm-opts 表。 |
initial-stream-receive-window | uint64 | 0 (quic-go default) | <bytes> | 单流初始流控窗口。 |
max-stream-receive-window | uint64 | 0 (quic-go default) | <bytes> | 单流最大流控窗口。 |
initial-connection-receive-window | uint64 | 0 (quic-go default) | <bytes> | 整连接初始流控窗口。 |
max-connection-receive-window | uint64 | 0 (quic-go default) | <bytes> | 整连接最大流控窗口。 |
源码: adapter/outbound/hysteria2.go:39-71 · 锚定版本 v1.19.27 (5184081)
入站
listeners: 下 type: hysteria2 条目。内嵌 BaseOption (listen、port)。
| 字段 | 类型 | 默认值 | 允许值 | 描述 |
|---|---|---|---|---|
users | map[string]string | {} | {<username>: <password>} | 用户表 —— 用户名到密码的映射。为空允许匿名连接。 |
obfs | string | (disabled) | salamander | Salamander 混淆类型。 |
obfs-password | string | (unset) | <string> | 混淆密码。 |
obfs-min-packet-size | int | 0 | <bytes> | Salamander 混淆的最小随机填充大小。仅在 `obfs: salamander` 时有意义。 |
obfs-max-packet-size | int | 0 | <bytes> | Salamander 混淆的最大随机填充大小。 |
certificate | string | (required) | <PEM file path> | TLS 服务端证书。入站必填。 |
private-key | string | (required) | <key file path> | TLS 私钥。 |
client-auth-type | string | (none) | no-client-cert | request-client-cert | require-any-client-cert | verify-client-cert-if-given | require-and-verify-client-cert | mTLS 客户端鉴权模式。 |
client-auth-cert | string | (unset) | <PEM file path> | 作为客户端根的 CA 集合。 |
ech-key | string | (unset) | <ECH config> | Encrypted Client Hello 配置 / 密钥。 |
max-idle-time | int | 0 | <seconds> | 监听器侧的空闲超时。0 使用 QUIC 默认。 |
alpn | []string | [h3] | h3 | TLS 握手时宣告的 ALPN 列表。 |
up | string | (unset) | <bandwidth> | 上行带宽(带单位字符串)。 |
down | string | (unset) | <bandwidth> | 下行带宽。 |
ignore-client-bandwidth | bool | false | true | false | 丢弃客户端宣告的带宽,强制使用服务端设置。 |
masquerade | string | (unset) | <URL> | 伪装目标 —— 字符串 URL(`file:///path` 或 `https://upstream/`)。 |
cwnd | int | 0 | <int> | QUIC 初始拥塞窗口。 |
bbr-profile | string | (unset) | default | aggressive | Brutal / BBR 调优 profile。 |
udp-mtu | int | 1200 | <bytes> | UDP 数据报分片 MTU。 |
mux-option | MuxOption | (disabled) | MuxOption | sing 风格多路复用设置。 |
realm-opts | Hysteria2RealmOption | (disabled) | Hysteria2RealmOption | 经由 Hysteria2 *realm* 连接 —— 一种通过控制端点访问的多租户服务器。见下方 realm-opts 表。 |
initial-stream-receive-window | uint64 | 0 (quic-go default) | <bytes> | 单流初始流控窗口。 |
max-stream-receive-window | uint64 | 0 (quic-go default) | <bytes> | 单流最大流控窗口。 |
initial-connection-receive-window | uint64 | 0 (quic-go default) | <bytes> | 整连接初始流控窗口。 |
max-connection-receive-window | uint64 | 0 (quic-go default) | <bytes> | 整连接最大流控窗口。 |
源码: listener/inbound/hysteria2.go:12-42 · 锚定版本 v1.19.27 (5184081)
realm-opts
出站与入站的 realm-opts 块共享同一结构。在出站上,它通过一个控制 端点把代理指向某个 Hysteria2 realm —— 即托管在多 realm 服务器上的 一个租户 —— 该端点会回传实际的连接详情。realm 模式是较新的进阶 特性;除非你正在连接 realm 服务器,否则请保持禁用。
| 字段 | 类型 | 默认值 | 允许值 | 描述 |
|---|---|---|---|---|
enable | bool | false | true | false | 为该代理启用 realm 模式。 |
server-url | string | (unset) | <URL> | realm 控制服务器的 URL,用于获取 realm 连接详情。 |
token | string | (unset) | <string> | 向 realm 控制服务器出示的鉴权 token。 |
realm-id | string | (unset) | <string> | 要加入的 realm 标识符。 |
stun-servers | []string | (unset) | <host:port list> | 用于 realm NAT 穿透的 STUN 服务器。 |
sni | string | (unset) | <SNI> | 控制服务器连接的 TLS SNI。 |
skip-cert-verify | bool | false | true | false | 对控制服务器跳过 TLS 校验(仅供测试)。 |
fingerprint | string | (unset) | <SHA256 hex> | 锚定控制服务器的 TLS 证书指纹。 |
certificate | string | (unset) | <PEM file path> | 面向控制服务器的客户端证书(mTLS)。 |
private-key | string | (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"。port与ports互斥 —— 二选一。 设置ports后,mihomo 每隔hop-interval随机挑选一个新成员 拨号。hop-interval最小值为 5 秒 (adapter/outbound/hysteria2.go:25),低于 5 会被向上钳制。- 带宽值接受带单位后缀(
b、kbps、Mbps、Gbps、Tbps), 数字与单位之间需要空格 ——"100 Mbps"。字符串由 mihomo 的tools.StringToBps辅助函数解析。 obfs-min-packet-size与obfs-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)
