Sing-Box 使用教程 (Linux)
Sing-Box 是一款功能强大的跨平台代理工具。它支持多种协议(如 Shadowsocks、VMess、Trojan、Hysteria2 等)。
仓库安装
使用仓库安装完之后会自动启动systemd服务
“Debian / APT”
sudo mkdir -p /etc/apt/keyrings &&
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 '
Types: deb
URIs: https://deb.sagernet.org/
Suites: *
Components: *
Enabled: yes
Signed-By: /etc/apt/keyrings/sagernet.asc
' | sudo tee /etc/apt/sources.list.d/sagernet.sources &&
sudo apt-get update &&
sudo apt-get install sing-box # or sing-box-beta“Redhat / DNF 5”
sudo dnf config-manager addrepo --from-repofile=https://sing-box.app/sing-box.repo &&
sudo dnf install sing-box # or sing-box-beta“Redhat / DNF 4”
sudo dnf config-manager --add-repo https://sing-box.app/sing-box.repo &&
sudo dnf -y install dnf-plugins-core &&
sudo dnf install sing-box # or sing-box-beta托管安装
| 类型 | 平台 | 命令 | 链接 |
|---|---|---|---|
| AUR | Arch Linux | ? -S sing-box | |
| nixpkgs | NixOS | nix-env -iA nixos.sing-box | |
| Homebrew | macOS / Linux | brew install sing-box | |
| APK | Alpine | apk add sing-box | |
| DEB | AOSC | apt install sing-box |
服务管理
对于带有 ystemd 的 Linux 系统,通常安装已经包含 sing-box 服务, 您可以使用以下命令管理服务:
| 行动 | 命令 |
|---|---|
| 启用 | sudo systemctl enable sing-box |
| 禁用 | sudo systemctl disable sing-box |
| 启动 | sudo systemctl start sing-box |
| 停止 | sudo systemctl stop sing-box |
| 强行停止 | sudo systemctl kill sing-box |
| 重新启动 | sudo systemctl restart sing-box |
| 查看日志 | sudo journalctl -u sing-box --output cat -e |
| 实时日志 | sudo journalctl -u sing-box --output cat -f |
下载配置文件到systemd里指定的配置路径
默认情况下,sing-box 会从 /etc/sing-box/ 目录读取配置文件。
注意: 一般需要加url参数flag到订阅链接后面,否则下载的配置文件格式不正确,参数值为sing-box
sudo curl -o /etc/sing-box/config.json '<订阅链接>?flag=sing-box'重新启动sing-box服务
sudo systemctl restart sing-box查看日志
sudo journalctl -u sing-box -fLast updated on