使用 sing-box 搭建 Shadowsocks over ShadowTLS

适用场景:需要抗主动探测的代理传输方式,用 sing-box 同时提供 ShadowTLS 伪装层与 Shadowsocks 入站。你会学到原理、安装、服务端配置与客户端接入。

原理说明

这种方案本质上是通过 shadow-tls 传输 Shadowsocks 流量。

  • 客户端先与服务端建立 shadow-tls 连接。
  • 然后在这条连接中继续传输 Shadowsocks 数据。
  • 服务端解开 shadow-tls 后,再把数据交给本地的 Shadowsocks 入站处理。

安装 sing-box

官方安装文档: sing-box 安装说明

Debian / Ubuntu

bash <(curl -fsSL https://sing-box.app/deb-install.sh)

CentOS

bash <(curl -fsSL https://sing-box.app/rpm-install.sh)

服务端配置示例

{
  "log": {
    "disabled": false,
    "level": "error",
    "timestamp": true
  },
  "inbounds": [
    {
      "type": "shadowtls",
      "tag": "st-in",
      "version": 3,
      "listen": "xx.xx.xx.xx",
      "listen_port": 50000,
      "detour": "ss-in",
      "users": [
        {
          "name": "sekai",
          "password": "111111"
        }
      ],
      "handshake": {
        "server": "www.tesla.com",
        "server_port": 443
      },
      "handshake_for_server_name": {
        "example.com": {
          "server": "www.tesla.com",
          "server_port": 443
        }
      },
      "strict_mode": false
    },
    {
      "type": "shadowsocks",
      "tag": "ss-in",
      "listen": "127.0.0.1",
      "listen_port": 50051,
      "method": "aes-128-gcm",
      "password": "111111",
      "multiplex": {}
    }
  ],
  "outbounds": [
    {
      "type": "direct",
      "tag": "direct"
    }
  ]
}

配置要点:

  • shadowtls 入站的 detour 指向 ss-in,即把解包后的流量交给 Shadowsocks 入站处理。
  • handshakeserver / server_port 是 TLS 握手伪装目标,请换成可达的合法站点。
  • strict_modefalse 时兼容性更好,true 时更严格但可能影响部分客户端。
  • Shadowsocks 入站只监听 127.0.0.1,不直接对外暴露。

Surge 配置参考

配置截图 1配置截图 2

验证与自查

  1. systemctl status sing-box 显示 active(running)
  2. ss -lntup | grep 50000 确认 ShadowTLS 入站端口监听正常
  3. 客户端(sing-box / Surge)用 ShadowTLS + Shadowsocks 配置连接成功,curl ip.sb 出口为服务端 IP
  4. journalctl -u sing-box -e 无 error 日志

参考