Linux 接入指南
Ubuntu / Debian / Arch / Fedora 通吃 · sing-box CLI 守护进程
🦊 推荐方案:sing-box + systemd 守护
Linux 上最干净的方案是 sing-box CLI + systemd service。一次配好,开机自启,零界面零依赖,吃内存 ~30MB。
你的 sing-box 订阅 URL:
🐧 Ubuntu / Debian 安装
-
添加 sing-box 官方源
sudo curl -fsSL https://sing-box.app/gpg.key -o /etc/apt/keyrings/sagernet.asc sudo chmod a+r /etc/apt/keyrings/sagernet.asc echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/sagernet.asc] https://deb.sagernet.org/ * *" | sudo tee /etc/apt/sources.list.d/sagernet.list sudo apt update && sudo apt install -y sing-box -
下载你的订阅配置
sudo mkdir -p /etc/sing-box sudo curl -L "[订阅URL]" -o /etc/sing-box/config.json sudo chmod 600 /etc/sing-box/config.json -
启动 + 自启
sudo systemctl enable --now sing-box sudo systemctl status sing-box # 看 active (running) -
测试
curl -x socks5://127.0.0.1:1080 https://ipinfo.io # 看到 country=DE 即成功
🎩 Arch / Manjaro 安装
sudo pacman -S sing-box
sudo curl -L "[订阅URL]" -o /etc/sing-box/config.json
sudo systemctl enable --now sing-box
或用 AUR:yay -S sing-box-beta 拿到最新 beta 版。
🎓 Fedora / RHEL / CentOS 安装
sudo dnf config-manager --add-repo https://sing-box.app/sing-box.repo
sudo dnf install sing-box
sudo curl -L "[订阅URL]" -o /etc/sing-box/config.json
sudo systemctl enable --now sing-box
🌐 把整机流量都走代理(TUN 模式)
默认配置只开 SOCKS5 (127.0.0.1:1080) + HTTP (127.0.0.1:1081) 代理,需要应用单独配置代理才走。如果想整机透明代理(所有 TCP/UDP 包都走 VPN,包括 apt 更新、git clone、Docker pull),需要 TUN 模式。
编辑 /etc/sing-box/config.json,在 inbounds 里加:
{
"type": "tun",
"tag": "tun-in",
"interface_name": "sing-tun",
"inet4_address": "172.19.0.1/30",
"auto_route": true,
"strict_route": true,
"stack": "system"
}
sudo systemctl restart sing-box
重启后整机就走代理了。验证:curl https://ipinfo.io(不用 -x)应该直接返回德国 IP。
🐳 Docker 用户
如果你想用 Docker 跑 sing-box(不污染宿主系统),用官方镜像:
docker run -d --name sing-box --restart=always \
--network host --cap-add NET_ADMIN \
-v /etc/sing-box:/etc/sing-box:ro \
ghcr.io/sagernet/sing-box:latest \
run -c /etc/sing-box/config.json
📦 GUI 选项
如果你的 Linux 桌面(GNOME / KDE)想要图形界面:
下完直接双击 .AppImage 或 sudo dpkg -i *.deb 安装。导入订阅流程跟 Mac / Win 一样。
🆘 常见问题
systemctl status sing-box 显示 failed?
看 journalctl -u sing-box -n 50 找错误。常见:(1) config.json 格式错(用 sing-box check -c /etc/sing-box/config.json 验证);(2) 端口被占(改 inbounds 端口);(3) TUN 模式缺 NET_ADMIN cap。
怎么自动更新订阅?
写 cron:
0 4 * * * curl -L "你的订阅 URL" -o /etc/sing-box/config.json && systemctl restart sing-box每天凌晨 4 点拉新配置。WSL2 里能用吗?
能,但 TUN 模式有兼容性问题。WSL2 推荐直接用 Windows 宿主的 Clash Verge,WSL 里 export http_proxy=http://localhost:7897 即可。
纯命令行能测速吗?
curl -x socks5://127.0.0.1:1080 -w "%{speed_download}\n" -o /dev/null -s https://speed.cloudflare.com/__down?bytes=104857600 跑 100MB 下载测速。
能不能只对某个进程开代理?
用 proxychains-ng:sudo apt install proxychains4,编辑 /etc/proxychains.conf 加 socks5 127.0.0.1 1080,然后 proxychains4 git clone ...。