本文记录在 Alpine Linux 上搭建 sing-box 服务端的完整流程:从 Edge community 临时安装 sing-box,编译并加载 tcp-brutal 内核模块,然后配置 VLESS Reality 入站。
本文不需要申请域名证书,Reality 会伪装到指定的 TLS 站点,例如 mirrors.kernel.org。
一、准备系统和组件
建议使用 Alpine virt 内核环境,并以 root 用户执行下面的命令。
先安装基础工具:
apk update
apk add curl wget bash vim nano jq openssl ca-certificates iproute2从 Edge community 临时安装 sing-box。这种方式只对本次安装使用 Edge community,避免把系统仓库永久混用。
apk update
apk add --repository http://dl-cdn.alpinelinux.org/alpine/edge/community sing-box设置 sing-box 开机自启:
rc-update add sing-box default确认版本:
sing-box version二、升级 virt 内核
安装 tcp-brutal 前,先确保包索引是最新的,并升级 virt 内核:
apk update
apk add --upgrade linux-virt升级内核后必须重启。否则系统仍然运行旧内核,后面编译或加载模块时容易失败。
reboot重启后确认当前内核:
uname -r三、安装编译依赖
重启进入新内核后,安装编译工具链、内核头文件和 Git:
apk update
apk add build-base linux-virt-dev git sudo如果你的内核不是 virt,需要安装与当前内核匹配的 linux-*-dev 包。可以先看当前内核:
uname -r例如内核名称里带 virt,就安装:
apk add linux-virt-dev四、下载并编译 tcp-brutal
使用 Git 下载项目源码:
git clone https://github.com/apernet/tcp-brutal.git
cd tcp-brutal
git pull origin master项目主分支可能是 main 或 master,如果 master 拉取失败,可以直接运行:
git pull编译并加载模块:
make
make loadmake 会生成 brutal.ko,make load 会把模块加载到当前系统。
五、检查 brutal 模块
检查 brutal 模块是否已经加载:
lsmod | grep brutal查看当前可用的拥塞控制算法:
sysctl net.ipv4.tcp_available_congestion_control输出里应该能看到 brutal。
也可以看内核日志:
dmesg | grep -i brutal六、设置 brutal 开机自动加载
在 tcp-brutal 源码目录下执行:
mkdir -p /lib/modules/$(uname -r)/extra
cp brutal.ko /lib/modules/$(uname -r)/extra/brutal.ko
depmod -a写入 /etc/modules,让系统启动时自动加载:
echo "brutal" >> /etc/modules
cat /etc/modules重启后再次检查:
lsmod | grep brutal
sysctl net.ipv4.tcp_available_congestion_control如果能看到 brutal,说明开机自动加载配置成功。
七、生成 Reality 所需参数
下面这些值不要直接复制别人的,要在自己的服务器上生成。
生成 UUID:
sing-box generate uuid生成 Reality 密钥对:
sing-box generate reality-keypair输出示例类似:
PrivateKey: YOUR_REALITY_PRIVATE_KEY
PublicKey: YOUR_REALITY_PUBLIC_KEY服务端配置只填写 PrivateKey,客户端连接时填写 PublicKey。
生成 short ID:
openssl rand -hex 8你最终会得到三类参数:
UUID: YOUR_UUID
Reality private: YOUR_REALITY_PRIVATE_KEY
Reality public: YOUR_REALITY_PUBLIC_KEY
Short ID: YOUR_SHORT_ID八、编写 sing-box 配置
进入配置目录:
mkdir -p /etc/sing-box /var/lib/sing-box
cd /etc/sing-box备份原配置:
cp -a config.json config.json.bak 2>/dev/null || true编辑配置文件:
vim /etc/sing-box/config.json写入下面的配置,并替换其中的占位符:
YOUR_UUID:替换为sing-box generate uuid生成的 UUIDYOUR_REALITY_PRIVATE_KEY:替换为sing-box generate reality-keypair生成的 PrivateKeyYOUR_SHORT_ID:替换为openssl rand -hex 8生成的 short IDmirrors.kernel.org:可以按需替换为其他 Reality 伪装目标站点
{
"log": {
"level": "warn",
"timestamp": true
},
"inbounds": [
{
"type": "vless",
"tag": "vless-reality-in",
"listen": "::",
"listen_port": 443,
"users": [
{
"uuid": "YOUR_UUID",
"flow": ""
}
],
"tls": {
"enabled": true,
"server_name": "mirrors.kernel.org",
"reality": {
"enabled": true,
"handshake": {
"server": "mirrors.kernel.org",
"server_port": 443
},
"private_key": "YOUR_REALITY_PRIVATE_KEY",
"short_id": ["YOUR_SHORT_ID"]
}
},
"multiplex": {
"enabled": true,
"padding": true,
"brutal": {
"enabled": true,
"up_mbps": 900,
"down_mbps": 900
}
}
}
],
"outbounds": [
{
"type": "direct",
"tag": "direct"
},
{
"type": "block",
"tag": "block"
}
],
"route": {
"rules": [
{
"inbound": "vless-reality-in",
"action": "sniff",
"timeout": "300ms"
},
{
"ip_is_private": true,
"outbound": "block"
},
{
"rule_set": ["geoip-cn", "geosite-cn"],
"outbound": "block"
}
],
"rule_set": [
{
"tag": "geoip-cn",
"type": "remote",
"format": "binary",
"url": "https://testingcf.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@sing/geo/geoip/cn.srs",
"download_detour": "direct",
"update_interval": "7d"
},
{
"tag": "geosite-cn",
"type": "remote",
"format": "binary",
"url": "https://testingcf.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@sing/geo/geosite/cn.srs",
"download_detour": "direct",
"update_interval": "7d"
}
],
"final": "direct"
},
"experimental": {
"cache_file": {
"enabled": true,
"path": "/var/lib/sing-box/cache.db"
}
}
}九、检查配置并启动服务
检查配置文件是否正确:
sing-box check -c /etc/sing-box/config.json启动服务:
rc-service sing-box start查看服务状态:
rc-service sing-box status查看日志:
tail -f /var/log/messages确认 443 端口监听:
ss -lntup | grep ':443'如果机器有防火墙或云服务器安全组,记得放行 TCP 443。
十、客户端需要填写的参数
客户端配置时,常用参数如下:
协议:VLESS
地址:你的服务器 IP 或域名
端口:443
UUID:YOUR_UUID
TLS:Reality
SNI / Server Name:mirrors.kernel.org
Public Key:YOUR_REALITY_PUBLIC_KEY
Short ID:YOUR_SHORT_ID
Flow:留空
Mux / Multiplex:开启
Brutal:按客户端支持情况开启注意:服务端配置里放的是 Reality PrivateKey,客户端配置里放的是 Reality PublicKey,不要写反。
十一、常见排查
如果 sing-box 启动失败,先检查配置:
sing-box check -c /etc/sing-box/config.json如果 443 端口被占用:
ss -lntup | grep ':443'如果 brutal 没有出现在拥塞控制列表里:
lsmod | grep brutal
uname -r
apk info | grep linux通常是当前运行内核和安装的 linux-virt-dev 版本不匹配,或者升级内核后没有重启。
附:自签名证书与普通 TLS 入站(非 Reality)
如果你没有使用 Reality,而是配置了普通的 TLS 入站(例如 VLESS + TLS 或 Hysteria2),sing-box 需要读取本地的 SSL 证书和私钥文件。启动失败时如果日志提示找不到证书文件,可以用下面的方法生成。
本节的配置方法不适用于 Reality(Reality 不需要本地证书,而是通过远程 TLS 握手完成伪装),只适用于需要本地读证书文件的普通 TLS 入站。
1. 创建证书目录并生成自签名证书
如果之前跳过了证书生成,先建好目录:
mkdir -p /etc/sing-box/ssl/用 openssl 生成一个有效期为 3650 天(10年)的自签名证书和私钥:
openssl req -x509 -nodes -days 3650 -newkey rsa:2048 \
-keyout /etc/sing-box/ssl/web.key \
-out /etc/sing-box/ssl/web.crt \
-subj "/CN=localhost"2. 确认证书文件
ls -l /etc/sing-box/ssl/正常情况下能看到 web.crt 和 web.key 两个文件。
3. 调整入站配置使用证书
在 inbounds 的 tls 段中指定证书路径。以 VLESS + TLS 为例:
{
"type": "vless",
"tag": "vless-tls-in",
"listen": "::",
"listen_port": 443,
"users": [
{
"uuid": "YOUR_UUID",
"flow": ""
}
],
"tls": {
"enabled": true,
"server_name": "你的域名",
"certificate_path": "/etc/sing-box/ssl/web.crt",
"key_path": "/etc/sing-box/ssl/web.key"
},
"multiplex": {
"enabled": true,
"padding": true,
"brutal": {
"enabled": true,
"up_mbps": 900,
"down_mbps": 900
}
}
}4. 重启服务
rc-service sing-box restart5. 客户端须知
自签名证书不会被系统信任,客户端连接时需要开启跳过证书验证(allowInsecure: true),否则客户端会因为证书无法信任而拒绝连接。
以 Xray、V2Ray 或 Clash.Meta 客户端为例,在 TLS 配置中添加:
tls:
allowInsecure: true生产环境建议使用受信任的证书(Let’s Encrypt、Cloudflare 等),仅在测试或内网使用时使用自签名证书。
