对自建节点的兄弟们说一句。都开始自建节点了,就别用那些脚本面板了,你不知道它做了什么,也不明白它那样做的意义。沉下心来学习,不懂的就问AI,这样既获得成就感,也获得了安全。
Hysteria2 适合在丢包率高的网络环境下提速,而 VLESS + XTLS-Reality 则是目前最隐蔽、最接近真实网页流量的方案之一。
一、 准备工作
- 安装sing-box:https://sing-box.sagernet.org/zh/installation/package-manager/
- 服务器端口:请确保防火墙已放行对应端口(示例中使用
443)。 - 域名:Reality 需要一个“回国”或“目标”域名(如
www.microsoft.com),不需要解析到你的 IP。
二、 Hysteria2 配置
hysteria2 基于 UDP,采用了全新的拥塞控制算法,暴力提速效果明显。
1. 服务端配置 (config.json)
{
"inbounds": [
{
"type": "hysteria2",
"tag": "hy2-in",
"listen": "::",
"listen_port": 443,
"users": [
{
"password": "你的密码"
}
],
"tls": {
"enabled": true,
"certificate_path": "/path/to/cert.crt",
"key_path": "/path/to/key.key"
}
}
]
}注意:Hy2 强制要求 TLS。你可以使用自签名证书,但在客户端需要开启 insecure。
我们可以使用 openssl 命令快速完成。请按以下步骤操作:
A. 进入目录并生成证书
在终端中执行以下命令(需要 root 权限):
cd /etc/sing-box/
# 生成自签名证书和私钥
# -days 3650 表示有效期为 10 年
# -nodes 表示不加密私钥文件
openssl req -x509 -nodes -newkey rsa:2048 -days 3650 \
-keyout server.key \
-out server.crt \
-subj "/CN=bing.com"
执行后,你会在目录下看到两个文件:
server.crt: 证书文件(用于服务端配置和客户端验证)。server.key: 私钥文件(仅用于服务端配置)。
B. 在 Hysteria2 服务端配置中引用
在你的 /etc/sing-box/config.json 服务端配置中,将路径指向这两个文件:
"certificate_path": "/etc/sing-box/server.crt",
"key_path": "/etc/sing-box/server.key"2. 客户端配置
{
"outbounds": [
{
"type": "hysteria2",
"tag": "Hysteria2",
"server": "你的服务器IP",
"server_port": 443,
"password": "你的密码",
"tls": {
"enabled": true,
"server_name": "你的证书域名",
"insecure": true
},
"up_mbps": 50,
"down_mbps": 200
}
]
}客户端的关键配置
由于是自签名证书,客户端默认是不信任的。在客户端的 outbounds 配置中,你必须开启 insecure:
"tls": {
"enabled": true,
"server_name": "bing.com",
"insecure": true // 必须设置为 true,否则无法连接
}建议
- 关于域名:在
openssl命令的-subj "/CN=bing.com"部分,你可以随意填写。只要客户端配置中的server_name与之对应即可。 - 更安全的做法:虽然
insecure: true最简单,但更安全的做法是将server.crt下载到本地,在客户端配置中使用certificate_path指定该证书,并保持insecure: false。
三、 VLESS + XTLS-Reality 配置
这种模式模拟真实的 TLS 握手,隐蔽性极强。
1. 服务端配置 (config.json)
- UUID:你可以使用命令 sing-box generate uuid 生成。
{
"inbounds": [
{
"type": "vless",
"tag": "vless-in",
"listen": "::",
"listen_port": 443,
"users": [
{
"uuid": "你的UUID",
"flow": "xtls-rprx-vision"
}
],
"tls": {
"enabled": true,
"server_name": "www.microsoft.com",
"reality": {
"enabled": true,
"handshake": {
"server": "www.microsoft.com",
"server_port": 443
},
"private_key": "你的私钥",
"short_id": ["你的简短ID"]
}
}
}
]
}2. 客户端配置
{
"outbounds": [
{
"type": "vless",
"tag": "VLESS + XTLS-Reality",
"server": "你的服务器IP",
"server_port": 443,
"uuid": "你的UUID",
"flow": "xtls-rprx-vision",
"tls": {
"enabled": true,
"server_name": "www.microsoft.com",
"utls": {
"enabled": true,
"fingerprint": "chrome"
},
"reality": {
"enabled": true,
"public_key": "你的公钥",
"short_id": "你的简短ID"
}
}
}
]
}A. 生成 Reality 密钥对 (KeyPair)
Reality 使用的是非对称加密,你需要生成一对公钥(Public Key)和私钥(Private Key)。
执行命令:
sing-box generate reality-keypair输出示例:
- PrivateKey:
uN9x...你的私钥...8vE=(填入服务端) - PublicKey:
R6kY...你的公钥...0mQ=(填入客户端)
重要提示: 私钥必须保密,仅限服务端使用;公钥则发给客户端用来加密握手流量。
B. 生成 Short ID
Short ID 是一个 1 到 8 字节的十六进制字符串,用于进一步区分流量。你可以手动输入几个数字/字母,也可以让系统生成一个随机的。
执行命令:
sing-box generate rand --hex 8输出示例:
b7f3a2c1d9e8f0a1(服务端和客户端填入一致的内容)
C. 如何填入配置文件?
你可以参照下表将生成的内容放置到对应位置:
| 参数名称 | 生成方式 | 服务端 (Server) | 客户端 (Client) |
| Private Key | reality-keypair | 填入 private_key | 无需填写 |
| Public Key | reality-keypair | 无需填写 | 填入 public_key |
| Short ID | rand --hex 8 | 填入 short_id 数组中 | 填入 short_id 字符串 |
D.多路复用
在 Sing-box 中,“多路复用”(Multiplexing,简称 Mux)主要针对 VLESS (TCP) 协议,它可以将多个并发请求合并到同一个 TCP 连接中传输。
这能显著减少 TCP 三次握手和 TLS 握手的次数,从而降低延迟(尤其是打开多图网页或并发下载时)并降低流量特征识别度。
客户端配置 (Client)
你只需要在客户端的 outbound 中添加 multiplex 字段。
"outbounds": [
{
"type": "vless",
"tag": "VLESS + XTLS-Reality",
"server": "你的服务器IP",
"server_port": 443,
"uuid": "你的UUID",
"flow": "xtls-rprx-vision",
"tls": {
"enabled": true,
"server_name": "www.microsoft.com",
"utls": {
"enabled": true,
"fingerprint": "chrome"
},
"reality": {
"enabled": true,
"public_key": "你的公钥",
"short_id": "你的简短ID"
}
}
},
"multiplex": {
"enabled": true,
"protocol": "smux",
"max_connections": 4,
"min_streams": 4,
"max_streams": 0
}
]参数详解:
protocol: 建议使用smux(Sing-box 默认且性能稳定)。max_connections: 最大物理 TCP 连接数。min_streams: 保持的最小复用流数量。
服务端配置 (Server)
Sing-box 服务端默认已经支持多路复用解包,通常不需要在 inbound 中做额外配置。只要客户端开启了 Mux,服务端会自动识别并处理。
对于 VLESS + XTLS-Reality (TCP):BBR 能够减少 TCP 三次握手后的排队延迟,在高丢包时保持窗口大小,不至于让你的速度断崖式下跌。
请开启BBR,只用Hysteria2可以不开!
发表回复