使用 sing-box 搭建 Anytls + Reality 节点
sing-box 是一个开源的、跨平台的通用代理与网络转发工具,常用于科学上网、流量分流、透明代理、流媒体解锁和多协议代理服务部署。它可以看作是新一代的高性能代理核心之一,设计目标是高性能、模块化、可扩展。它可以:
-
作为代理客户端使用
-
作为代理服务器部署
-
做透明代理网关
-
实现分流策略
-
解锁流媒体
-
构建家庭或服务器网络出口
本文主要介绍如何使用 sing-box 作为代理服务器,并部署一个 AnyTLS 节点。
1. 准备工作¶
- 海外 VPS 一台安装好主流的操作系统 (Almalinux 8+、Ubuntu 16+、Debian 8+)
本教程使用的是一台Hostvds VPS
- 配置:2 vCore 4 GB RAM ($3.99)
- 域名: .top 域名 ($1.88)
- 操作系统: Almalinux 9
2. 安装 sing-box¶
这里以 Redhat 系列发行版为例,更多平台安装方式,请参考 sing-box 官方文档,或之前讲 sing-box 作为代理客户端教程中 sing-box 安装部分。
对于 Redhat 系列发行版(Centos, Fedora, AlmaLinux, Rocky Linux 等)
# 向 DNF 添加 sing-box 官方软件仓库
# 这样系统就可以从该仓库获取 sing-box 软件包
sudo dnf config-manager addrepo --add-repo=https://sing-box.app/sing-box.repo
# 从指定网址下载并导入 sing-box 官方的 GPG 公钥
# 用于验证软件包签名,防止安装被篡改的软件
sudo rpm --import https://sing-box.app/gpg.key
# 清除 DNF 的所有缓存数据(软件包缓存、仓库元数据等)
# 常用于仓库更新异常或软件列表不同步时强制重新下载缓存
sudo dnf clean all
# 更新本地软件仓库缓存
# 让系统读取刚添加的仓库中的软件列表
sudo dnf makecache
# 安装 sing-box
# -y 表示自动确认安装过程中的提示
sudo dnf install -y sing-box
# 确认版本, 确保有 with_quic
sing-box version
# 设置为开机自启动
sudo systemctl enable --now sing-box.service
# 查看服务状态
systemctl status sing-box.service
# 如果启动过程中出现任何错误,查看日志并进行修复
journalctl -u sing-box
如何出现以下错误,需要在sing-box.service service区块添加 Environment="ENABLE_DEPRECATED_SPECIAL_OUTBOUNDS=true" 或者将 配置文件中 /etc/sing-box/config.json 中 outbounds 中dns-out部分删除
```json { "type": "dns", "tag": "dns-out" }
```
Jan 30 23:36:48 server-0hrxrx.novalocal sing-box[3807]: ERROR[0000] legacy special outbounds is deprecated in sing-box 1.11.0 and will be removed in sing-box 1. Jan 30 23:36:48 server-0hrxrx.novalocal sing-box[3807]: FATAL[0000] to continuing using this feature, set environment variable ENABLE_DEPRECATED_SPECIAL_OUTBOUNDS=true
3. 准备 reality keypair¶
[root@server]# sing-box generate reality-keypair
PrivateKey: IP0qUZtsJ2v7QXYpZ0g8u5LgqaTPgzoR7UXwdpyatlo
PublicKey: 1lc1VNOi9uvUTjvhze_U_7RTf1FFuS8YhSEpwhWVqGc
4. 获取 Reality 伪装目标网站¶
这一步很关键,如果目标网站选择不正确,会导致连接失败,在服务端会看到invalid request, 在客户端日志中会看到Reality shakehand失败。
方法一: 网站直接获取 (简单,但无法指定区域距离,访问速度会有影响)
方法二: FOFA手动搜索获取 (灵活,可以指定区域距离,但稍微繁琐需要一定的动手能力)
- ASN查询工具:https://tools.ipip.net/as.php
- 目标网站查询工具:https://fofa.info
方法三:本地工具获取目 (方便,但无法指定区域距离,访问速度会有影响)
wget -O /tmp/RealiTLScanner https://github.com/XTLS/RealiTLScanner/releases/download/v0.2.1/RealiTLScanner-linux-64
chmod +x /tmp/RealiTLScanner
./RealiTLScanner -addr <your_server_ip>
feasible=true 基本上能拿来使用。使用前最后打开浏览器看一下,是否是正规可靠的网站。
5. 配置 AnyTLS + Reality 代理服务器¶
参考以下配置替换其中的域名、端口、uuid、密码,然后放入/etc/sing-box/config.json,一个简单的AnyTLS节点就配置完成了。
sing-box提供了uuid生成工具
sing-box generate uuid
{
"log": {
"level": "info"
},
"inbounds": [
{
"type": "anytls", // 协议类型:AnyTLS,提供增强的混淆能力
"tag": "anytls-in",
"listen": "::", // 监听地址:"::" 表示同时监听 IPv4 和 IPv6
"listen_port": 443,
"users": [
{
"name": "sekai",
"password": "71a636a6-974d-4454-8653-4cc332a9cd3e"
}
],
"padding_scheme": [
"stop=8",
"0=50-100",
"1=150-500",
"2=500-1200,c,500-1200,c,500-1200",
"3=20-100,500-1200",
"4=600-1100",
"5=400-900",
"6=700-1300",
"7=300-800"
],
"tls": {
"enabled": true, // 启用 TLS
"server_name": "www.dalkyo.xyz", // 伪装域名:向外展示的域名,使用RealiTLScanner获取到的域名
"reality": {
"enabled": true, // 启用 REALITY 传输
"handshake": {
"server": "www.dalkyo.xyz", // 真实握手目标服务器
"server_port": 443
},
// 这里的 Private Key 必须由 sing-box generate reality-keypair 命令生成
"private_key": "IP0qUZtsJ2v7QXYpZ0g8u5LgqaTPgzoR7UXwdpyatlo",
"short_id": "a1b2c3d4e5f67890" // 简短 ID,用于识别合法客户端
}
}
}
],
"outbounds": [
{
"type": "direct"
}
]
}
6. 防火墙开放 UDP 端口¶
7. 检测配置¶
8. 重启 sing-box¶
当日志中出现 inbound/anytls[anytls-in]: tcp server started at [::]:443 表示 sing-box AnyTLS 节点监听在 443 端口
sing-box[12182]: INFO[0000] network: updated default interface eth0, index 2
sing-box[12182]: INFO[0000] inbound/anytls[anytls-in]: tcp server started at [::]:443
sing-box[12182]: INFO[0000] sing-box started (0.11s)
9. 测试¶
目前支持Anytls + Reality的客户端并不多(截至2026二月),Mihomo内核不支持Anytls + Reality,所以clash系列客户端测试不了,目前只有Xray内核和sing-box内核(1.12+版本)支持连接Anytls + Reality节点。
V2rayN 测试,将以下连接字符串中域名替换成真实域名,粘贴到 v2rayN 节点分组,然后测试节点真连接延迟:
连接字符串: anytls://71a636a6-974d-4454-8653-4cc332a9cd3e@your_server_ip:443?security=reality&sni=www.dalkyo.xyz&fp=chrome&pbk=1lc1VNOi9uvUTjvhze_U_7RTf1FFuS8YhSEpwhWVqGc&sid=a1b2c3d4e5f67890&type=tcp#anytls_reality
如果使用 sing-box 系列客户端,可以使用如下配置, 可以将以下配置中的 ip 替换成真实域名, 导入到客户端进行测试:
{
"log": {
"level": "info",
"timestamp": true
},
"dns": {
"servers": [
{
"tag": "google",
"type": "tls",
"server": "8.8.8.8",
"detour": "anytls-out"
},
{
"tag": "local",
"type": "udp",
"server": "223.5.5.5"
}
],
"strategy": "ipv4_only",
"final": "google"
},
"inbounds": [
{
"type": "tun", //开启tun模式,需要管理员权限
"address": "172.19.0.1/30", //指定虚拟网卡ip
"auto_route": true,
"strict_route": true,
"sniff": true
}
],
"outbounds": [
{
"type": "anytls",
"tag": "anytls-out",
"server": "your_server_ip",
"server_port": 443,
"password": "71a636a6-974d-4424-8653-4cc332a9cd3e",
"tls": {
"enabled": true,
"server_name": "www.dalkyo.xyz", //与服务端配置对应
"utls": {
"enabled": true,
"fingerprint": "chrome"
},
"reality": {
"enabled": true,
"public_key": "1lc1VNOi9uvUTjvhze_U_7RTf1FFuS8YhSEpwhWVqGc",
"short_id": "a1b2c3d4e5f67890"
}
}
},
{
"type": "direct",
"tag": "direct"
}
],
"route": {
"rules": [
{
"protocol": "dns",
"action": "hijack-dns"
},
{
"ip_is_private": true,
"action": "route",
"outbound": "direct"
},
{
"action": "route",
"outbound": "anytls-out"
}
],
"auto_detect_interface": true,
"default_domain_resolver": "local" // 修复 WARN 警告
}
}
在客户端,将以上内容中的必要信息替换,保存为json文件,执行检查,以管理员权限运行如下脚本。
打开浏览器检查是否能科学上网。如果出现任何错误,在客户端会有错误日志打印出来,服务端使用journalctl -u sing-box -f 查看日志。