裸 VPS 使用 sing-box 搭建 VMess 代理教程 本文档适用于裸 VPS 手动部署 sing-box,不使用面板、不使用域名、不使用 TLS、不使用 Reality。
配置方案:
1 VMess + TCP + none + alterId 0 + 端口 18080
不过这个vps需要找那种有国内线路的,一般很多国外服务器国内无法直连,网速也偏慢.
注意:VMess 明文 TCP 不适合长期高强度使用。长期使用建议改成 VLESS + Reality 或其他带 TLS/伪装的方案。
一、准备条件 推荐系统:
1 2 3 4 5 Debian 11 Debian 12 Ubuntu 20.04 Ubuntu 22.04 Ubuntu 24.04
需要放行端口:
需要客户端:
1 2 3 4 v2rayN v2rayNG NekoBox Shadowrocket
二、登录 VPS 本地电脑执行:
例如:
如果遇到 SSH 指纹变更警告:
1 WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!
可以先删除旧指纹:
1 ssh-keygen -f ~/.ssh/known_hosts -R '你的VPS_IP'
然后重新连接:
三、更新系统并安装基础工具 1 2 apt update apt install -y curl sudo nano ufw
如果是 Debian 10 buster,apt update 可能出现 404。可以临时切换到 archive 源:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 cp /etc/apt/sources.list /etc/apt/sources.list.bakcat > /etc/apt/sources.list <<'EOF' deb http://archive.debian.org/debian buster main contrib non-free deb http://archive.debian.org/debian buster-updates main contrib non-free deb http://archive.debian.org/debian-security buster/updates main contrib non-free EOFcat > /etc/apt/apt.conf.d/99archive <<'EOF' Acquire::Check-Valid-Until "false" ; EOF apt cleanrm -rf /var/lib/apt/lists/* apt update apt install -y curl sudo nano ufw
如果是新 VPS,更推荐直接在服务商后台重装:
1 2 3 Debian 12 Ubuntu 22.04 Ubuntu 24.04
四、安装 sing-box 添加 sing-box 官方 APT 源:
1 2 3 4 5 6 7 8 9 10 11 12 13 mkdir -p /etc/apt/keyrings curl -fsSL https://sing-box.app/gpg.key -o /etc/apt/keyrings/sagernet.ascchmod a+r /etc/apt/keyrings/sagernet.asccat > /etc/apt/sources.list.d/sagernet.sources <<'EOF' Types: deb URIs: https://deb.sagernet.org/ Suites: * Components: * Enabled: yes Signed-By: /etc/apt/keyrings/sagernet.asc EOF
更新并安装:
1 2 apt update apt install -y sing-box
检查版本:
五、生成 UUID VMess 需要一个 UUID。
执行:
1 cat /proc/sys/kernel/random/uuid
示例输出:
1 6ed43346-b4bc-4761-bf80-2fc0be4e8950
后面的配置里需要用这个 UUID。
六、写入 sing-box 配置 创建配置目录:
编辑配置文件:
1 nano /etc/sing-box/config.json
粘贴下面配置:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 { "log" : { "level" : "info" , "timestamp" : true } , "inbounds" : [ { "type" : "vmess" , "tag" : "vmess-in" , "listen" : "0.0.0.0" , "listen_port" : 18080 , "users" : [ { "name" : "my-vps" , "uuid" : "6ed43346-b4bc-4761-bf80-2fc0be4e8950" , "alterId" : 0 } ] } ] , "outbounds" : [ { "type" : "direct" , "tag" : "direct" } ] , "route" : { "final" : "direct" } }
需要修改的地方:
1 2 3 uuid:改成你自己生成的 UUID listen_port:默认 18080,可以按需修改 name:只是备注,可以随便写
保存退出:
七、检查配置并启动 sing-box 检查配置:
1 sing-box check -c /etc/sing-box/config.json
如果没有报错,启动服务:
1 2 3 systemctl enable sing-box systemctl restart sing-box systemctl status sing-box
如果看到:
说明 sing-box 已经启动成功。
查看实时日志:
1 journalctl -u sing-box --output cat -f
退出日志查看:
八、确认端口是否监听 执行:
正常应看到类似:
1 tcp LISTEN 0 4096 0.0.0.0:18080 0.0.0.0:* users:(("sing-box",pid=xxxx,fd=xx))
重点确认:
1 2 3 LISTEN 0.0.0.0:18080 sing-box
如果没有输出,说明 sing-box 没有监听成功,需要检查配置和日志。
九、放行防火墙端口 如果 VPS 使用 ufw:
1 2 3 ufw allow 18080/tcp ufw reload ufw status
如果显示:
说明 ufw 没有启用,不一定是问题。
但还需要去 VPS 服务商后台检查安全组或防火墙。
添加入站规则:
1 2 3 协议:TCP 端口:18080 来源:0.0.0.0/0
常见后台入口名称:
1 2 3 4 5 6 Firewall Security Group 防火墙 安全组 入站规则 Inbound Rules
十、本地测试端口是否开放 需要在本地电脑测试,不是在 VPS 上测试。
macOS / Linux
例如:
1 nc -vz 154.44.1.72 18080
成功结果:
1 Connection to 154.44.1.72 18080 port [tcp/*] succeeded!
Windows PowerShell 1 Test-NetConnection 你的VPS_IP -Port 18080
成功结果:
十一、v2rayN 客户端配置 添加服务器,协议选择:
填写参数:
1 2 3 4 5 6 7 8 9 10 11 12 别名:my-vps 地址:你的VPS_IP 端口:18080 用户 ID:你的 UUID 额外 ID / alterId:0 加密方式 / security:auto 传输协议 / network:tcp 伪装类型 / type:none host:空 path:空 TLS:不启用 / none / 空 Mux:Off
示例:
1 2 3 4 5 6 7 8 9 地址:154.44.1.72 端口:18080 UUID:6ed43346-b4bc-4761-bf80-2fc0be4e8950 alterId:0 security:auto network:tcp type:none TLS:空 Mux:Off
十二、VMess 导入链接示例 如果你的配置是:
1 2 3 IP:154.44.1.72 端口:18080 UUID:6ed43346-b4bc-4761-bf80-2fc0be4e8950
可以使用下面的导入链接:
1 vmess://eyJ2IjoiMiIsInBzIjoibXktdnBzIiwiYWRkIjoiMTU0LjQ0LjEuNzIiLCJwb3J0IjoiMTgwODAiLCJpZCI6IjZlZDQzMzQ2LWI0YmMtNDc2MS1iZjgwLTJmYzBiZTRlODk1MCIsImFpZCI6IjAiLCJzY3kiOiJhdXRvIiwibmV0IjoidGNwIiwidHlwZSI6Im5vbmUiLCJob3N0IjoiIiwicGF0aCI6IiIsInRscyI6IiJ9
如果 IP、端口或 UUID 不同,需要重新生成 VMess 链接。
十三、测试代理是否生效 v2rayN 中操作:
1 2 3 4 5 1. 选择节点 2. 设为活动服务器 3. 开启系统代理 4. 路由模式选择全局 5. 点击测试真连接
本地电脑测试出口 IP:
如果显示的是 VPS IP,例如:
1 2 3 4 5 6 { "ip" : "154.44.1.72" , "city" : "Los Angeles" , "region" : "California" , "country" : "US" }
说明本地流量已经走 VPS。
十四、常见排障命令 查看服务状态 1 systemctl status sing-box
查看最近日志 1 journalctl -u sing-box --output cat -e
查看实时日志 1 journalctl -u sing-box --output cat -f
检查端口监听
检查配置文件 1 sing-box check -c /etc/sing-box/config.json
查看 sing-box 实际读取哪个配置文件
如果看到:
1 ExecStart=... sing-box run -c /etc/sing-box/config.json
说明服务读取的是:
1 /etc/sing-box/config.json
如果看到:
1 ExecStart=... sing-box run -c /etc/sing-box.json
说明服务读取的是:
此时需要把配置写到实际读取的路径,或者修改 systemd 服务文件。
十五、修改配置后的标准重启流程 每次修改配置后,按下面顺序执行:
1 2 3 4 sing-box check -c /etc/sing-box/config.json systemctl restart sing-box systemctl status sing-box ss -tulnp | grep 18080
如果要看连接日志:
1 journalctl -u sing-box --output cat -f
十六、常见问题 1. apt update 报 buster 404 原因:Debian 10 buster 已经过期,主源不再提供 Release 文件。
解决方法:切换到 archive 源,或者重装 Debian 12 / Ubuntu 22.04。
2. ss -tulnp | grep 18080 没有输出 说明 sing-box 没有监听端口。
检查:
1 2 3 sing-box check -c /etc/sing-box/config.json systemctl status sing-box journalctl -u sing-box --output cat -e
3. 本地 nc 测试端口失败 可能原因:
1 2 3 4 5 1. sing-box 没启动 2. VPS 防火墙没放行 3. 服务商安全组没放行 4. 配置文件不是 systemd 实际读取的文件 5. 端口写错
检查:
1 2 ss -tulnp | grep 18080 systemctl cat sing-box
4. v2rayN 连不上 检查客户端参数是否和服务端一致:
1 2 3 4 5 6 7 8 9 10 协议:VMess 地址:VPS IP 端口:18080 UUID:服务端配置里的 uuid alterId:0 security:auto network:tcp type:none TLS:不启用 Mux:Off
5. 代理通了,但某些网站提示地区不支持 这通常不是 sing-box 配置问题,而是网站对出口 IP、ASN、账号地区、Cookie、风控策略的判断。
可以测试出口 IP:
重点看:
如果出口 IP 已经是 VPS IP,说明代理链路正常。
十七、完整客户端参数模板 1 2 3 4 5 6 7 8 9 10 协议:VMess 地址:你的 VPS IP 端口:18080 UUID:服务端 config.json 里的 uuid alterId:0 加密:auto 传输:tcp 伪装:none TLS:不启用 Mux:Off
十八、完整服务端配置模板 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 { "log" : { "level" : "info" , "timestamp" : true } , "inbounds" : [ { "type" : "vmess" , "tag" : "vmess-in" , "listen" : "0.0.0.0" , "listen_port" : 18080 , "users" : [ { "name" : "my-vps" , "uuid" : "这里填写你的UUID" , "alterId" : 0 } ] } ] , "outbounds" : [ { "type" : "direct" , "tag" : "direct" } ] , "route" : { "final" : "direct" } }
十九、总结 这套配置的核心是:
1 2 3 4 5 6 sing-box 服务端:VMess 入站 客户端:VMess TCP 端口:18080 alterId:0 TLS:关闭 传输伪装:none
最小可用条件:
1 2 3 4 5 1. sing-box 正常运行 2. VPS 监听 18080 3. 安全组放行 TCP 18080 4. 客户端 IP、端口、UUID、alterId 完全一致 5. 客户端开启系统代理或全局代理