Direct — sing-box
Direct 是 sing-box 的直通出站,也是一个常用的「测试回声」入站。 近期版本对出站侧做了刻意精简 —— 出站上的 override_address / override_port 已迁出协议层,由路由引擎承担。
入站
type: "direct":
| 字段 | 类型 | 默认值 | 允许值 | 描述 |
|---|---|---|---|---|
network | NetworkList | (tcp+udp) | tcp | udp | | 限定为仅 TCP 或仅 UDP。 |
override_address | string | (unset) | <host> | 改写每条已接收连接的目的地址。 |
override_port | uint16 | (unset) | <port> | 改写每条已接收连接的目的端口。 |
源码: option/direct.go:10-15 · 锚定版本 v1.13.11 (553cfa1)
内嵌 ListenOptions(监听地址、端口、嗅探等)。Direct 入站最常用作 端口转发器 —— 在某端口接收、改写目的地、再由任意出站转出。
出站
type: "direct":
| 字段 | 类型 | 默认值 | 允许值 | 描述 |
|---|---|---|---|---|
override_address | string | (rejected) | (use route actions) | sing-box 1.13 中移除。现在设置会触发指向 route action 的启动错误。 |
override_port | uint16 | (rejected) | (use route actions) | 与 override_address 相同 —— 已移除;请使用 route action。 |
proxy_protocol | uint8 | (removed) | 0 | 已完全移除。任何非零设置都会触发已弃用 / 已移除错误。 |
源码: option/direct.go:17-25 · 锚定版本 v1.13.11 (553cfa1)
出站现在只剩内嵌的 DialerOptions(bind_interface、routing_mark、 detour 等)。上面三个旧字段在配置加载时会被 拒绝:
destination override fields in direct outbound are deprecated in
sing-box 1.11.0 and removed in sing-box 1.13.0, use route options
instead示例
裸 direct 出站(最常见的情况 —— 给流量一个出口):
json
{
"outbounds": [
{ "type": "direct", "tag": "direct" }
]
}绑定到特定接口的 direct 出站:
json
{
"outbounds": [
{
"type": "direct",
"tag": "direct-eth0",
"bind_interface": "eth0"
}
]
}入站做端口转发(在 8080 上接收,改写目的为 internal:80):
json
{
"inbounds": [
{
"type": "direct",
"tag": "forward-8080",
"listen": "0.0.0.0",
"listen_port": 8080,
"override_address": "10.0.0.5",
"override_port": 80
}
]
}说明
override_address/override_port在 route action 中的替代写法 如下:json{ "route": { "rules": [ { "inbound": ["forward-8080"], "action": "route", "outbound": "direct", "override_address": "10.0.0.5", "override_port": 80 } ] } }这把同样的行为从协议层移到路由规则中,可以与路由的其他能力组合 得更整洁。
跨内核说明
- Xray-core 把这种能力称为 Freedom。它的出站暴露了丰富得多 的特性 —— TCP/TLS 分片、噪声注入、
redirect字段,参见 Freedom — Xray-core。 - mihomo 同样有精简的 Direct 形态,并会自动注入内置
DIRECT命名代理。参见 Direct — mihomo。
源码: option/direct.go:10-25 · v1.13.11 (553cfa1)
