对于经常在 Linux 服务器、无桌面网关或嵌入式软路由上进行代码拉取、Docker 镜像构建与数据同步的技术人员而言,图形化客户端并不适用。sing-box 作为下一代通用代理平台,凭借极低的内存占用、出色的并发处理能力以及精简高效的架构,成为服务器端与无头环境(Headless)下的首选方案。
一、 获取官方二进制包
请始终通过 sing-box 官方开源仓库下载:
官方项目地址: GitHub SagerNet / sing-box Releases
以标准的 x86_64 架构 Linux 系统为例,可以通过终端命令获取并解压:
# 下载官方最新编译包 (示例版本,实际请替换具体版本号)
curl -Lo sing-box.tar.gz https://github.com/SagerNet/sing-box/releases/download/v1.9.0/sing-box-1.9.0-linux-amd64.tar.gz
tar -zxvf sing-box.tar.gz
sudo mv sing-box-*/sing-box /usr/local/bin/
sudo chmod +x /usr/local/bin/sing-box
二、 配置基础入站与出站(config.json)
创建配置目录并编写配置文件 /etc/sing-box/config.json。在此文件中,定义本地混合入站端口(提供 SOCKS5 与 HTTP 代理)以及指向花云专线节点的出站:
{
"log": {
"level": "info",
"timestamp": true
},
"inbounds": [
{
"type": "mixed",
"tag": "mixed-in",
"listen": "127.0.0.1",
"listen_port": 7890
}
],
"outbounds": [
{
"type": "shadowsocks",
"tag": "flowercloud-node",
"server": "your-flowercloud-node-host.com",
"server_port": 443,
"method": "aes-128-gcm",
"password": "your-password"
},
{
"type": "direct",
"tag": "direct"
}
],
"route": {
"rules": [
{
"geoip": ["cn"],
"outbound": "direct"
}
],
"auto_detect_interface": true
}
}
三、 配置 Systemd 服务实现开机自启与守护
创建服务定义文件 /etc/systemd/system/sing-box.service:
[Unit]
Description=sing-box service
After=network.target
[Service]
Type=simple
User=root
ExecStart=/usr/local/bin/sing-box run -c /etc/sing-box/config.json
Restart=on-failure
RestartSec=5s
LimitNOFILE=infinity
[Install]
WantedBy=multi-user.target
执行以下命令启用并运行服务:
sudo systemctl daemon-reload
sudo systemctl enable sing-box
sudo systemctl start sing-box
sudo systemctl status sing-box
四、 在终端中使用代理测试连通性
服务启动后,可在 bash 会话中导出环境变量进行验证:
export http_proxy="http://127.0.0.1:7890"
export https_proxy="http://127.0.0.1:7890"
# 验证公网出口 IP 是否已切换为花云专线节点
curl -i https://ipinfo.io
五、 本文常见问题(FAQ)
花云订阅链接如何直接转为 sing-box 的 JSON 格式?
花云部分订阅转换工具支持直接输出 sing-box 格式,或者可以使用开源转换器(如 Subconverter)将 Clash 订阅转换为 sing-box 格式规则。
如何在 Linux 下开启透明代理(Tun)?
在 sing-box 的 inbounds 中添加
"type": "tun" 节点,并开启 "auto_route": true 与 "strict_route": true,同时确保内核开启了 net.ipv4.ip_forward = 1 转发功能。
参考依据:依据 sing-box 官方文档与开源项目规范整理。终端操作需具备相应 Linux 系统管理员权限。