Skip to content

Commit df80612

Browse files
committed
Fix Hysteria2 and AnyTLS subscription support
1 parent 3be0915 commit df80612

7 files changed

Lines changed: 311 additions & 18 deletions

File tree

README.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ bash install.sh
7373
clash secret 123 🔐 设置密钥
7474
📌 高级
7575
clash lan 🏠 局域网代理管理
76+
clash ipv6 🌐 IPv6 / IPv6-only 节点管理
7677
clash tun 🧪 Tun 模式管理(需root方式安装)
7778
clash boot 🚦 开机代理接管管理
7879
clash mixin 🧩 Mixin 配置管理
@@ -158,6 +159,32 @@ clash lan off
158159
159160
------
160161
162+
## 🌐 IPv6 / Hysteria2
163+
164+
Mihomo 支持 Hysteria2。若节点服务端只有 IPv6 地址,需要同时启用内核 IPv6 与 DNS AAAA:
165+
166+
```bash
167+
clash config kernel mihomo
168+
clash ipv6 on
169+
clash ipv6 status
170+
```
171+
172+
其他可用操作:
173+
174+
```bash
175+
clash ipv6 off
176+
clash ipv6 auto
177+
```
178+
179+
- `on`:同时写入 `ipv6: true``dns.ipv6: true`
180+
- `off`:同时关闭内核 IPv6 与 DNS AAAA。
181+
- `auto`:保留订阅原有的 IPv6 设置;订阅未配置时继续使用兼容默认值。
182+
- 使用 IPv6-only 节点前,宿主机仍需具备可用的 IPv6 默认路由。HY2 使用 UDP / QUIC,网络或防火墙也必须允许相应 UDP 流量。
183+
184+
也可以在 `.env` 中设置 `CLASH_IPV6=true``false``auto`,然后执行 `clash config regen`
185+
186+
------
187+
161188
OpenWrt 下 root/system 安装会把 `clash``clashon``clashoff` 等命令入口写入 `/usr/bin`,运行状态、日志和内核二进制仍保存在项目目录的 `runtime/` 下。仅脚本模式不会注册开机自启,设备重启后需要重新执行 `clashon`
162189
## 🧰 常用管理命令
163190
@@ -204,7 +231,7 @@ clash add "file:///绝对路径/clash.yaml" home
204231
205232
- Clash / Mihomo YAML
206233
- Base64 订阅
207-
- 分享链接(`vmess` / `vless` / `trojan` / `tuic`
234+
- 分享链接(`vmess` / `vless` / `trojan` / `tuic` / `hysteria2` / `hy2` / `anytls`
208235
209236
### 开机接管(内核 + 代理)
210237
@@ -321,12 +348,15 @@ CLASH_DOWNLOAD_BASE=https://github.com/WindSpiritSR/clash/releases/download
321348
CLASH_BUNDLED_ASSET_ENABLED=true
322349
CLASH_SHELL_AUTO_RESTORE_PROXY=true
323350
CLASH_PREDOWNLOAD_GEO=true
351+
CLASH_IPV6=auto
324352
```
325353
326354
按需设置即可,不需要每项都写。
327355
328356
- `CLASH_SHELL_AUTO_RESTORE_PROXY`:控制登录 Shell 是否自动恢复上次 `clashon` 写入的代理变量。默认 `true` 保持兼容;如果不希望 SSH 远程登录后自动带上 `http_proxy` / `https_proxy`,设为 `false`,之后仍可手动执行 `clashon`
329357
- `CLASH_PREDOWNLOAD_GEO`:控制安装期是否预下载 GEO 数据。默认 `true`,会提前下载 `Country.mmdb``geoip.metadb``GeoIP.dat``GeoSite.dat` 等规则分流常用资源;临时部署、只想先跑起来时可设为 `false` 跳过安装期预下载。注意:当最终运行配置实际使用 `GEOIP` 规则时,启动前仍会按需准备 `Country.mmdb`,否则 Mihomo 无法可靠加载该配置。
358+
- `CLASH_IPV6`:可设为 `true``false``auto``true` 同时启用内核 IPv6 与 DNS AAAA,适用于 IPv6-only 节点;`auto` 保留订阅中的 IPv6 设置。
359+
- `CLASH_SUBSCRIPTION_UA`:覆盖拉取订阅时的 User-Agent。默认使用 `clash-verge/v2.4.0`,以便订阅服务返回 Mihomo 支持的 Hysteria2、AnyTLS 等现代协议节点;如果服务商有专用 UA 要求,可在此显式设置。
330360
331361
#### GitHub 下载加速
332362

scripts/core/clashctl.sh

Lines changed: 83 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ Usage:
3737
mixin 🧩 Mixin 配置管理
3838
relay 🔗 多跳节点管理
3939
lan 🏠 局域网代理管理
40+
ipv6 🌐 IPv6 / IPv6-only 节点管理
4041
4142
4243
📦 Subscription:
@@ -49,6 +50,7 @@ Usage:
4950
clashui 🕹️ 查看 Web 控制台
5051
secret 🔑 查看或设置 Web 密钥
5152
lan on|off|status 🏠 开启 / 关闭局域网代理
53+
ipv6 on|off|auto|status 🌐 管理内核与 DNS IPv6
5254
5355
🧪 Transparent proxy:
5456
tun 🧪 Tun 模式管理
@@ -3290,6 +3292,7 @@ cmd_ui_help_summary() {
32903292
printf ' %-18s %s\n' "clash ls" "📜 查看订阅列表"
32913293
echo "📌 高级"
32923294
printf ' %-18s %s\n' "clash lan" "🏠 局域网代理管理"
3295+
printf ' %-18s %s\n' "clash ipv6" "🌐 IPv6 / IPv6-only 节点管理"
32933296
printf ' %-18s %s\n' "clash tun" "🧪 Tun 模式管理"
32943297
printf ' %-18s %s\n' "clash mixin" "🧩 Mixin 配置管理"
32953298
printf ' %-18s %s\n' "clash sub" "🧩 订阅高级管理(启用 / 禁用 / 重命名 / 删除)"
@@ -4403,6 +4406,84 @@ cmd_lan() {
44034406
esac
44044407
}
44054408

4409+
print_ipv6_status() {
4410+
local mode mode_text kernel_ipv6 dns_ipv6 kernel
4411+
4412+
mode="$(config_ipv6_mode)"
4413+
kernel_ipv6="$(runtime_config_ipv6_enabled 2>/dev/null || echo "等待运行配置生成")"
4414+
dns_ipv6="$(runtime_config_dns_ipv6_enabled 2>/dev/null || echo "等待运行配置生成")"
4415+
kernel="$(runtime_kernel_type 2>/dev/null || echo unknown)"
4416+
4417+
case "$mode" in
4418+
true) mode_text="已开启" ;;
4419+
false) mode_text="已关闭" ;;
4420+
*) mode_text="自动(保留订阅设置)" ;;
4421+
esac
4422+
4423+
ui_title "🌐 IPv6"
4424+
ui_kv "🔧" "配置模式" "$mode_text"
4425+
ui_kv "🚀" "当前内核" "$kernel"
4426+
ui_kv "🌐" "内核 IPv6" "$kernel_ipv6"
4427+
ui_kv "🔎" "DNS AAAA" "$dns_ipv6"
4428+
if [ "$kernel" != "mihomo" ]; then
4429+
ui_warn "Hysteria2 建议使用 Mihomo:clash config kernel mihomo"
4430+
fi
4431+
ui_blank
4432+
}
4433+
4434+
cmd_ipv6() {
4435+
local action
4436+
prepare
4437+
4438+
action="${1:-status}"
4439+
case "$action" in
4440+
on|enable)
4441+
set_config_ipv6_mode true
4442+
regenerate_config
4443+
apply_runtime_change_after_config_mutation
4444+
success "IPv6 与 DNS AAAA 已开启"
4445+
print_ipv6_status
4446+
print_config_apply_feedback
4447+
;;
4448+
off|disable)
4449+
set_config_ipv6_mode false
4450+
regenerate_config
4451+
apply_runtime_change_after_config_mutation
4452+
success "IPv6 与 DNS AAAA 已关闭"
4453+
print_ipv6_status
4454+
print_config_apply_feedback
4455+
;;
4456+
auto|reset)
4457+
set_config_ipv6_mode auto
4458+
regenerate_config
4459+
apply_runtime_change_after_config_mutation
4460+
success "IPv6 已恢复为自动模式"
4461+
print_ipv6_status
4462+
print_config_apply_feedback
4463+
;;
4464+
status)
4465+
print_ipv6_status
4466+
ui_next "IPv6-only / Hysteria2 节点不可用时执行:clash ipv6 on"
4467+
ui_blank
4468+
;;
4469+
-h|--help|help)
4470+
echo "📜 用法:"
4471+
echo " clash ipv6 status"
4472+
echo " clash ipv6 on"
4473+
echo " clash ipv6 off"
4474+
echo " clash ipv6 auto"
4475+
echo
4476+
echo "🌐 说明:"
4477+
echo " on 同时启用内核 IPv6 与 DNS AAAA"
4478+
echo " off 同时关闭内核 IPv6 与 DNS AAAA"
4479+
echo " auto 保留订阅中的 IPv6 设置,缺省时沿用兼容默认值"
4480+
;;
4481+
*)
4482+
die_usage "未知的 ipv6 子命令:$action" "clash ipv6 on|off|auto|status"
4483+
;;
4484+
esac
4485+
}
4486+
44064487
print_profile_use_feedback() {
44074488
local profile="$1"
44084489

@@ -7262,7 +7343,7 @@ cmd_sub() {
72627343

72637344
case "${1:-}" in
72647345
update)
7265-
regenerate_config
7346+
regenerate_config "manual-refresh"
72667347
apply_runtime_change_after_config_mutation
72677348
print_config_regen_feedback
72687349
print_config_apply_feedback
@@ -8087,6 +8168,7 @@ case "$cmd" in
80878168
dev) cmd_dev "$@" ;;
80888169
config) cmd_config "$@" ;;
80898170
lan) cmd_lan "$@" ;;
8171+
ipv6) cmd_ipv6 "$@" ;;
80908172
mixin) cmd_mixin "$@" ;;
80918173
relay) cmd_relay "$@" ;;
80928174
profile) cmd_profile "$@" ;;

scripts/core/common.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1796,6 +1796,32 @@ runtime_config_allow_lan() {
17961796
esac
17971797
}
17981798

1799+
runtime_config_ipv6_enabled() {
1800+
local file
1801+
local value
1802+
file="$(runtime_config_file)"
1803+
[ -s "$file" ] || return 1
1804+
1805+
value="$("$(yq_bin)" eval '.ipv6' "$file" 2>/dev/null | head -n 1)"
1806+
case "$value" in
1807+
false) echo "false" ;;
1808+
*) echo "true" ;;
1809+
esac
1810+
}
1811+
1812+
runtime_config_dns_ipv6_enabled() {
1813+
local file
1814+
local value
1815+
file="$(runtime_config_file)"
1816+
[ -s "$file" ] || return 1
1817+
1818+
value="$("$(yq_bin)" eval '.dns.ipv6' "$file" 2>/dev/null | head -n 1)"
1819+
case "$value" in
1820+
true) echo "true" ;;
1821+
*) echo "false" ;;
1822+
esac
1823+
}
1824+
17991825
runtime_port_value_is_valid() {
18001826
local port="${1:-}"
18011827

scripts/core/completion.sh

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,17 @@ _clash_for_linux_complete_lan() {
213213
fi
214214
}
215215
216+
_clash_for_linux_complete_ipv6() {
217+
local cur="$1"
218+
local rel_index="$2"
219+
220+
COMPREPLY=()
221+
222+
if [ "$rel_index" -eq 1 ]; then
223+
_clash_for_linux_add_matches "$cur" on off auto status enable disable reset help -h --help
224+
fi
225+
}
226+
216227
_clash_for_linux_complete_mixin() {
217228
local cur="$1"
218229
local rel_index="$2"
@@ -347,7 +358,7 @@ _clash_for_linux_complete_top_level() {
347358
COMPREPLY=()
348359
_clash_for_linux_add_matches "$cur" \
349360
add use ls health select mode test on off status status-next \
350-
boot log logs doctor ui secret tun dev config lan mixin \
361+
boot log logs doctor ui secret tun dev config lan ipv6 mixin \
351362
relay profile sub proxy upgrade update completion help \
352363
-h --help
353364
}
@@ -426,6 +437,7 @@ _clash_for_linux_complete_command() {
426437
boot) _clash_for_linux_complete_boot "$cur" "$rel_index" "$arg1" ;;
427438
config) _clash_for_linux_complete_config "$cur" "$rel_index" "$arg1" ;;
428439
lan) _clash_for_linux_complete_lan "$cur" "$rel_index" ;;
440+
ipv6) _clash_for_linux_complete_ipv6 "$cur" "$rel_index" ;;
429441
mixin) _clash_for_linux_complete_mixin "$cur" "$rel_index" ;;
430442
relay) _clash_for_linux_complete_relay "$cur" "$rel_index" "$arg1" ;;
431443
sub) _clash_for_linux_complete_sub "$cur" "$rel_index" "$arg1" ;;

0 commit comments

Comments
 (0)