Skip to content

Tor — sing-box

sing-box 的 Tor 出站会 把 Tor 二进制作为子进程拉起,并通过其内 建 SOCKS 端口转发。此处的协议选项配置 sing-box 如何启动并驱动该进程 —— Tor 本身需要单独安装。

出站

type: "tor"

字段类型默认值允许值描述
executable_pathstring(PATH lookup)<file path>Tor 二进制路径。未设置时 sing-box 在 PATH 上搜索 `tor`。
extra_args[]string[]<arg>启动 Tor 时附加的命令行参数。例如 `--use-bridges`、`--ClientTransportPlugin` 等。
data_directorystring(temp dir)<dir path>Tor 的工作目录(缓存描述符、共识等)。跨重启保留可加速引导。
torrcmap[string]string{}{<option>: <value>}通过 Tor 控制协议传入的内联 torrc 选项。`ExcludeNodes`、`ExitNodes`、`StrictNodes` 等标准 torrc 键均可使用。

源码: option/tor.go:3-9 · 锚定版本 v1.13.11 (553cfa1)

为底层套接字内嵌 DialerOptions —— bind_interfacedetour 等。

示例

最小化 —— 让 sing-box 在 PATH 上找 tor 并使用默认值:

json
{
  "outbounds": [
    { "type": "tor", "tag": "tor" }
  ]
}

指定二进制并使用持久化数据目录:

json
{
  "outbounds": [
    {
      "type": "tor",
      "tag": "tor-persistent",
      "executable_path": "/usr/local/bin/tor",
      "data_directory": "/var/lib/sing-box/tor",
      "torrc": {
        "ExitNodes": "{de},{nl}",
        "StrictNodes": "1"
      }
    }
  ]
}

启用 obfs4 网桥:

json
{
  "outbounds": [
    {
      "type": "tor",
      "tag": "tor-bridged",
      "torrc": {
        "UseBridges": "1",
        "ClientTransportPlugin": "obfs4 exec /usr/bin/obfs4proxy",
        "Bridge": "obfs4 1.2.3.4:443 ABCDEF... cert=... iat-mode=0"
      }
    }
  ]
}

说明

  • 运行时需要 Tor 二进制。sing-box vendor 它。多数发行版以 tor 包形式提供;macOS 上请用 Homebrew。
  • data_directory 启动时默认使用临时目录 —— 这是最慢的设置,每次 启动都要重新引导共识。持久化该目录可在启动时节省数秒。
  • torrc 键通过 Tor 控制协议传入;值必须严格是 Tor 期望的字符串 (不会自动加引号)。多行 torrc 值请在 extra_args 中重复键。
  • 出站没有 network 字段 —— Tor 自身不支持 UDP,因此该出站按设计 只支持 TCP。

跨内核说明

  • Xray-core 没有 Tor 出站。变通方式是用 SOCKS 出站指向系统 Tor 的 SOCKS 端口。参见 Tor — Xray-core
  • mihomo 没有 Tor 出站。参见 Tor — mihomo

源码: option/tor.go:3-9 · v1.13.11 (553cfa1)

由 Argsment 出品的 Core Tutorial