Skip to content

Dokodemo / 端口转发 — sing-box

使用 Direct 入站

sing-box 没有专门的 dokodemo 或 tunnel 入站。 Direct 入站 覆盖同类场景 —— 在某端口接收、 可选地覆盖目的地,再由路由引擎或 override_address / override_port 决定流量去向。

静态端口转发

json
{
  "inbounds": [
    {
      "type": "direct",
      "tag": "dns-forward",
      "listen": "0.0.0.0",
      "listen_port": 5353,
      "override_address": "1.1.1.1",
      "override_port": 53
    }
  ],
  "outbounds": [
    { "type": "direct", "tag": "direct" }
  ]
}

TPROXY 接收器

在 Linux 透明代理模式下,按常规设置入站的 tcp_fast_open 与嗅探 选项,并使用 redirect 入站。入站字段集合见 Direct — sing-box,恢复原始目的地的做法见上游 Route 文档。

多端口转发

sing-box 没有内置的 portMap 字段。要把每个端口转发到不同目标, 每端口声明一个 Direct 入站:

json
{
  "inbounds": [
    {
      "type": "direct",
      "tag": "fwd-80",
      "listen_port": 80,
      "override_address": "10.0.0.10",
      "override_port": 80
    },
    {
      "type": "direct",
      "tag": "fwd-443",
      "listen_port": 443,
      "override_address": "10.0.0.10",
      "override_port": 443
    },
    {
      "type": "direct",
      "tag": "fwd-53",
      "network": "udp",
      "listen_port": 5353,
      "override_address": "1.1.1.1",
      "override_port": 53
    }
  ]
}

跨内核说明

  • Xray-core 有专用的 dokodemo-door 协议,单个入站内即可使用 portMap 做多端口转发。参见 Dokodemo — Xray-core
  • mihomo 提供 listeners:type: tunnel 以及顶层 tunnels: 块。参见 Tunnel — mihomo

由 Argsment 出品的 Core Tutorial