add sing-box config

This commit is contained in:
Haitao Pan 2025-07-09 19:54:49 +08:00
parent 977b0b6263
commit c3d0e794db
7 changed files with 445 additions and 0 deletions

View File

@ -0,0 +1,95 @@
# Sing-box VLESS + Reality 一键部署脚本
该脚本用于在 Linux 服务器上快速部署一个基于 sing-box 的隐匿代理服务,采用 `VLESS + Reality` 协议,结合 systemd 自启动支持,适用于高隐蔽性代理通信场景。
---
## 🧩 功能特性
- 🚀 自动安装并配置 sing-box如未安装
- 🔐 自动生成 Reality 密钥对(无需手动管理)
- 📄 自动生成服务端配置文件(支持伪装 SNI
- ⚙️ 自动创建并启用 systemd 启动服务
- 📦 自动输出客户端配置片段,支持 Windows/macOS/Linux
---
## 🖥️ 支持平台
- 服务端Debian / Ubuntu / CentOS / Arch / 兼容 Linux 系统
- 客户端平台macOS / Windows / Linux任意 sing-box 客户端)
---
## ⚙️ 使用方式
### 一键安装(推荐)
```bash
bash <(curl -fsSL https://your.cdn/installer/install-singbox.sh) \
--ip 123.123.123.123 \
--sni www.bing.com \
--client-platform macos
参数说明:
参数 示例值 说明
--ip 123.123.123.123 当前服务器公网 IP
--sni www.bing.com Reality 伪装域名
--client-platform macos / windows / linux 客户端类型(影响输出说明)
📂 脚本行为说明
部署完成后,脚本会生成:
文件路径 说明
/etc/sing-box/config-server.json sing-box 服务端配置
/etc/systemd/system/sing-box.service systemd 启动配置
/usr/local/bin/sing-box 主程序(如未安装将自动下载)
并自动执行:
bash
复制
编辑
systemctl daemon-reload
systemctl enable --now sing-box
🔐 示例输出
部署成功后会输出如下:
css
复制
编辑
✅ 服务端已部署成功!
👉 Reality 公钥: yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
👉 ShortID: abcd
👉 UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
📦 推荐客户端配置如下:
{
"outbounds": [
{
"type": "vless",
...
}
]
}
🧱 安全建议
建议使用 Cloudflare DNS 或境外解析加快 SNI 匹配
Reality 不需要 TLS 证书即可启用加密通信
可进一步结合 iptables 或 fail2ban 做入站控制
🛠️ 后续扩展(可选)
你可以基于本项目扩展支持:
fallback 到 nginx / 80 端口
多用户(多个 UUID
动态配置(通过 API 控制)
客户端同步配置工具

View File

@ -0,0 +1,72 @@
{
"log": {
"level": "debug"
},
"dns": {
"servers": [
{
"tag": "direct_dns",
"address": "223.5.5.5",
"detour": "direct"
}
]
},
"inbounds": [
{
"type": "tun",
"tag": "tun-in",
"interface_name": "sing-tun",
"mtu": 1500,
"stack": "gvisor",
"endpoint_independent_nat": true,
"address": ["172.19.0.1/30"],
"auto_route": true,
"strict_route": true
}
],
"outbounds": [
{
"type": "direct",
"tag": "direct"
},
{
"type": "vless",
"tag": "proxy-out",
"server": "your.server.ip", // IP
"server_port": 443,
"uuid": "your-uuid", //
"flow": "",
"tls": {
"enabled": true,
"server_name": "fake-sni.com", // bing.com
"utls": {
"enabled": true,
"fingerprint": "chrome"
},
"reality": {
"enabled": true,
"public_key": "your-server-pubkey", // Reality
"short_id": "abcd" //
}
}
}
],
"route": {
"auto_detect_interface": true,
"rules": [
{
"geoip": ["cn"],
"outbound": "direct"
},
{
"ip_cidr": ["0.0.0.0/0"],
"outbound": "proxy-out"
},
{
"protocol": ["dns"],
"action": "hijack-dns"
}
]
}
}

View File

@ -0,0 +1,69 @@
{
"log": {
"level": "info"
},
"dns": {
"servers": [
{
"tag": "direct_dns",
"address": "223.5.5.5",
"detour": "direct"
}
]
},
"inbounds": [
{
"type": "tun",
"tag": "tun-in",
"interface_name": "sing-tun", // gVisor
"mtu": 1500,
"stack": "gvisor", // TCP/IP
"endpoint_independent_nat": true,
"address": [
"172.19.0.1/30"
],
"auto_route": true,
"strict_route": true
}
],
"outbounds": [
{
"type": "vless",
"tag": "proxy-out",
"server": "your.domain.com", // TLS
"server_port": 443,
"uuid": "your-uuid", // UUID
"flow": "xtls-rprx-vision", // XTLS-Vision
"tls": {
"enabled": true,
"server_name": "your.domain.com", //
"utls": {
"enabled": true,
"fingerprint": "chrome" // uTLS
}
// Reality
}
},
{
"type": "direct",
"tag": "direct"
}
],
"route": {
"auto_detect_interface": true,
"rules": [
{
"geoip": ["cn"],
"outbound": "direct" //
},
{
"ip_cidr": ["0.0.0.0/0"],
"outbound": "proxy-out" // VLESS XTLS
},
{
"protocol": ["dns"],
"action": "hijack-dns" // DNS
}
]
}
}

View File

@ -0,0 +1 @@
sing-box generate reality-keypair

View File

@ -0,0 +1,136 @@
#!/bin/bash
set -e
# 参数
SERVER_IP="$1"
SNI="$2"
CLIENT_PLATFORM="$3"
# 示例用法提示
if [[ -z "$SERVER_IP" || -z "$SNI" || -z "$CLIENT_PLATFORM" ]]; then
echo "用法: $0 --ip <服务器IP> --sni <伪装域名> --client-platform <macos|linux|windows>"
exit 1
fi
UUID=$(uuidgen)
KEYPAIR=$(sing-box generate reality-keypair)
PRIVATE_KEY=$(echo "$KEYPAIR" | grep PrivateKey | awk '{print $2}')
PUBLIC_KEY=$(echo "$KEYPAIR" | grep PublicKey | awk '{print $2}')
SHORT_ID=$(head /dev/urandom | tr -dc a-z0-9 | head -c 4)
# 安装 sing-box以 Debian 为例)
if ! command -v sing-box &>/dev/null; then
echo "🔧 安装 sing-box..."
curl -fsSL https://sing-box.app/install | bash
fi
# 创建配置目录
mkdir -p /etc/sing-box
# 写入服务端配置
cat > /etc/sing-box/config-server.json <<EOF
{
"log": {
"level": "info"
},
"inbounds": [
{
"type": "vless",
"tag": "vless-in",
"listen": "::",
"listen_port": 443,
"users": [
{
"uuid": "$UUID",
"flow": ""
}
],
"tls": {
"enabled": true,
"server_name": "$SNI",
"reality": {
"enabled": true,
"handshake": {
"server": "$SNI",
"server_port": 443
},
"private_key": "$PRIVATE_KEY",
"short_id": ["$SHORT_ID"]
}
}
}
],
"outbounds": [
{
"type": "direct",
"tag": "direct"
}
]
}
EOF
# 写入 systemd 文件
cat > /etc/systemd/system/sing-box.service <<EOF
[Unit]
Description=Sing-box Proxy Service
After=network.target
[Service]
ExecStart=/usr/local/bin/sing-box run -c /etc/sing-box/config-server.json
Restart=on-failure
LimitNOFILE=1048576
[Install]
WantedBy=multi-user.target
EOF
# 启动服务
systemctl daemon-reexec
systemctl daemon-reload
systemctl enable sing-box --now
# 客户端配置片段
echo ""
echo "✅ 服务端已部署成功!"
echo "👉 Reality 公钥: $PUBLIC_KEY"
echo "👉 ShortID: $SHORT_ID"
echo "👉 UUID: $UUID"
echo ""
echo "📦 推荐客户端配置如下:"
cat <<EOF
{
"outbounds": [
{
"type": "vless",
"tag": "proxy-out",
"server": "$SERVER_IP",
"server_port": 443,
"uuid": "$UUID",
"flow": "",
"tls": {
"enabled": true,
"server_name": "$SNI",
"utls": {
"enabled": true,
"fingerprint": "chrome"
},
"reality": {
"enabled": true,
"public_key": "$PUBLIC_KEY",
"short_id": "$SHORT_ID"
}
}
}
]
}
EOF
# 可选:根据客户端平台提醒适配位置
if [[ "$CLIENT_PLATFORM" == "macos" || "$CLIENT_PLATFORM" == "linux" ]]; then
echo -e "\n📂 请将此配置合并到你的 sing-box 客户端配置文件中,如 ~/.config/sing-box/config.json"
elif [[ "$CLIENT_PLATFORM" == "windows" ]]; then
echo -e "\n📂 请将此配置合并到你的 Windows sing-box GUI 或 config.json 文件中"
fi

View File

@ -0,0 +1,34 @@
{
"log": {
"level": "info"
},
"inbounds": [
{
"type": "vless",
"listen": "::",
"listen_port": 443,
"users": [
{
"uuid": "your-uuid",
"flow": "xtls-rprx-vision"
}
],
"tls": {
"enabled": true,
"server_name": "your.domain.com", //
"certificates": [
{
"certificate_file": "/etc/ssl/certs/fullchain.pem",
"key_file": "/etc/ssl/private/privkey.pem"
}
]
}
}
],
"outbounds": [
{
"type": "direct"
}
]
}

View File

@ -0,0 +1,38 @@
{
"log": {
"level": "info"
},
"inbounds": [
{
"type": "vless",
"tag": "vless-in",
"listen": "::",
"listen_port": 443,
"users": [
{
"uuid": "your-uuid", //
"flow": ""
}
],
"tls": {
"enabled": true,
"server_name": "fake-sni.com", //
"reality": {
"enabled": true,
"handshake": {
"server": "fake-sni.com", //
"server_port": 443
},
"private_key": "your-private-key", // Reality
"short_id": ["abcd"] //
}
}
}
],
"outbounds": [
{
"type": "direct",
"tag": "direct"
}
]
}