本文介绍 sing-box 作为透明网关的安装方法
[TOC]
一、脚本部署 sing-box
脚本在 GitHub,虚拟机需具备科学上网能力
步骤 1: 新建 Debian 或 Ubuntu 虚拟机,运行安装脚本
wget https://raw.githubusercontent.com/herozmy/StoreHouse/refs/heads/latest/install.sh && bash install.sh
步骤 2: 输入 y 确认

步骤 3: 输入 3 安装 sing-box

步骤 4: 选择核心版本
- VPS 用户:选择 1.官方核心
- 机场用户:选择 3.reF1nd 核心

步骤 5: 输入 y 确认,粘贴订阅链接

步骤 6: 回车确认

步骤 7: 安装成功后,输入 proxytool 管理服务

步骤 8: 打开 UI 面板

访问提示的地址,输入 sing-box 所在 VM 的 IP:9090 即可打开 UI 面板。

脚本也可安装 mihomo 裸核,自行探索。
二、手动部署 sing-box 官方核心
使用 sing-box 裸核需要 4 个步骤:
- 准备 sing-box 二进制程序
- 准备配置文件
- 创建 systemd 服务文件
- 安装并配置 nftables
建议使用 Debian 或 Ubuntu 虚拟机,本文以 Debian 13 为例(1 核/1G 内存/8G 硬盘) 配置文件、systemd 服务文件、nftables 配置文件来自 @Ron 大佬
(1)安装 sing-box 程序
步骤 1: 更新系统
apt update
apt install curl wget unzip
apt upgrade -y
reboot
步骤 2: 修改时区
dpkg-reconfigure tzdata
步骤 3: 安装 sing-box(3 种方式,新手建议选 1 或 2)
方式 1: 下载预编译版本(虚拟机需科学,x86 架构,默认 1.12.12)
wget https://github.com/SagerNet/sing-box/releases/download/v1.12.12/sing-box-1.12.12-linux-amd64.tar.gz && \
tar -xzf sing-box-1.12.12-linux-amd64.tar.gz && \
mv sing-box-1.12.12-linux-amd64/sing-box /usr/local/bin/ && \
chmod +x /usr/local/bin/sing-box && \
rm -r sing-box-1.12.12-linux-amd64 sing-box-1.12.12-linux-amd64.tar.gz
方式 2: 手动下载
- 访问 sing-box releases
- 下载对应架构的版本
- 解压后将 sing-box 上传到 /usr/local/bin/
- 赋予执行权限:
chmod +x /usr/local/bin/sing-box
方式 3: 编译安装最新版
apt -y install curl git build-essential libssl-dev libevent-dev zlib1g-dev gcc-mingw-w64
curl -L https://go.dev/dl/go1.25.1.linux-amd64.tar.gz -o go1.25.1.linux-amd64.tar.gz
tar -C /usr/local -xzf go1.25.1.linux-amd64.tar.gz
echo 'export PATH=$PATH:/usr/local/go/bin' > /etc/profile.d/golang.sh
source /etc/profile.d/golang.sh
go install -v -tags with_quic,with_grpc,with_dhcp,with_wireguard,with_ech,with_utls,with_reality_server,with_clash_api,with_gvisor,with_v2ray_api,with_lwip,with_acme github.com/sagernet/sing-box/cmd/sing-box@latest
如需特定版本,将 latest 改为版本号(如 v1.12.0):
go install -v -tags with_quic,with_grpc,with_dhcp,with_wireguard,with_utls,with_clash_api,with_gvisor,with_v2ray_api,with_lwip,with_acme github.com/sagernet/sing-box/cmd/[email protected]
cp $(go env GOPATH)/bin/sing-box /usr/local/bin/
(2)准备配置文件
步骤 1: 创建配置目录
mkdir -p /usr/local/etc/sing-box/conf
步骤 2: 下载配置模板
访问 GitHub 仓库 下载 6 个文件到 /usr/local/etc/sing-box/conf/
或使用命令下载:
cd /usr/local/etc/sing-box/conf
wget https://raw.githubusercontent.com/jasonxtt/file/refs/heads/main/sing-box/conf/00_log.json \
https://raw.githubusercontent.com/jasonxtt/file/refs/heads/main/sing-box/conf/01_experimental.json \
https://raw.githubusercontent.com/jasonxtt/file/refs/heads/main/sing-box/conf/02_dns.json \
https://raw.githubusercontent.com/jasonxtt/file/refs/heads/main/sing-box/conf/03_inbounds.json \
https://raw.githubusercontent.com/jasonxtt/file/refs/heads/main/sing-box/conf/04_outbound.json \
https://raw.githubusercontent.com/jasonxtt/file/refs/heads/main/sing-box/conf/05_route.json
步骤 3: 下载 ruleset 文件
cd /usr/local/etc/sing-box
wget https://raw.githubusercontent.com/jasonxtt/file/refs/heads/main/sing-box/script/singbox_rule_updata.sh
chmod +x singbox_rule_updata.sh
./singbox_rule_updata.sh
步骤 4: 修改配置文件
仅需修改 /usr/local/etc/sing-box/conf/04_outbound.json,添加节点信息。
注意:
- Proxy 分组名称不要修改
- 确保节点正常,否则无法下载 UI
- 修改 GLOBAL 策略组顺序可调整 UI 显示顺序
步骤 5: 测试配置
/usr/local/bin/sing-box run -C /usr/local/etc/sing-box/conf/
无报错则按 Ctrl+C 取消,继续下一步。
(3)创建 sing-box 启动服务
cd /etc/systemd/system/
wget https://raw.githubusercontent.com/jasonxtt/file/refs/heads/main/sing-box/service/sing-box.service
systemctl daemon-reload
systemctl enable sing-box --now
检查运行状态:
systemctl status sing-box
显示绿色 active (running) 表示正常运行。
(4)安装并配置 nftables
步骤 1: 安装 nftables
apt install nftables -y
步骤 2: 下载配置文件
cd /etc
mv nftables.conf nftables.conf.bak
wget https://raw.githubusercontent.com/jasonxtt/file/refs/heads/main/sing-box/nftables/nftables.conf
步骤 3: 修改配置
编辑 /etc/nftables.conf:
- 将 10.0.0.0/8 替换为自己的内网 IP 段
- 如 fakeip 段不是 28.0.0.0/8 和 f2b0::/18,自行搜索替换
步骤 4: 启用 nftables
nft flush ruleset
nft -f /etc/nftables.conf
nft list ruleset
systemctl enable --now nftables
systemctl restart nftables
默认 TCP 使用 redirect,UDP 使用 tproxy。
切换脚本: @Ron 大佬写的 nftables 规则切换脚本
- 选项 1:tcp-redirect、udp-tproxy
- 选项 2:tcp/udp 都用 tproxy
使用前需修改脚本中的内网 IP 段和 fakeIP 段。
至此,sing-box 安装完毕。
