sing-box hysteria2端口跳跃设置
sing-box自版本1.11更新后,支持Hysteria2的端口跳跃功能,故撰以此文以备忘。
一、sing-box服务端
sing-box在更新1.11后,服务端关于hysteria2协议的配置基本没变,由于服务端并不能同时监听多个端口,因此不能在服务器端使用类似”listen_ports”: [“56050:57050”],这样的端口范围配置写法作为监听地址。建议和hysteria2官方配置一样,配合 iptables 或 nftables 的 DNAT 将端口转发到服务器的监听端口。
此处仅以iptables方式为例,操作步骤如下:
- 安装iptables (如有可省略)
apt install iptables - 添加规则
iptables -t nat -A PREROUTING -i eth0 -p udp –dport 56050:57050 -j REDIRECT –to-ports 56037
#注:此处为将端口范围 56050:57050转发至56037端口,此56037为服务端hy2协议设置的监听端口。 - 查看规则 (非必须)
iptables -t nat -L - 安装iptables-persistent
apt install iptables-persistent -y - 保存规则配置
netfilter-persistent save - 查看netfilter-persistent运行状态
systemctl status netfilter-persistent - 重启
reboot
至此服务服务端的设置已完成。
二、sing-box客户端
sing-box在更新1.11后,客户端关于hysteria2协议的配置新增了端口跳跃范围,仅需于原本的配置文件中增加如下内容即可:
"server_ports": [
"56050:57050"
],
"hop_interval": "60s",
其中hop_interval的默认值为30s,将原配置中”server_port”: 56037栏删除。其余可参看官方文档内容。
至此sing-box关于hysteria2端口跳跃设置就基本完成。
good, 这样一来速度就快了许多了!
这个方法不错,以前都是用的大厂的,速度没保障!