拨号字段
Fork 新增
sing-box 1.13.0 中的更改
disable_tcp_keep_alive tcp_keep_alive tcp_keep_alive_interval bind_address_no_port
sing-box 1.12.0 中的更改
sing-box 1.11.0 中的更改
network_strategy
fallback_delay
network_type
fallback_network_type
结构
{
"detour": "",
"bind_interface": "",
"inet4_bind_address": "",
"inet6_bind_address": "",
"bind_address_no_port": false,
"routing_mark": 0,
"reuse_addr": false,
"netns": "",
"connect_timeout": "",
"tcp_fast_open": false,
"tcp_multi_path": false,
"disable_tcp_keep_alive": false,
"tcp_keep_alive": "",
"tcp_keep_alive_interval": "",
"udp_fragment": false,
"domain_resolver": "", // 或 {}
"network_strategy": "",
"network_type": [],
"fallback_network_type": [],
"fallback_delay": "",
"prefer_domain": true,
// 废弃的
"domain_strategy": ""
}
当内容只有一项时,可以忽略 JSON 数组 [] 标签
字段
detour
上游出站的标签。
启用时,其他拨号字段将被忽略。
bind_interface
要绑定到的网络接口。
inet4_bind_address
要绑定的 IPv4 地址。
inet6_bind_address
要绑定的 IPv6 地址。
bind_address_no_port
自 sing-box 1.13.0 起
仅支持 Linux。
绑定到源地址时不保留端口。
这允许在完整的四元组(源 IP、源端口、目标 IP、目标端口)保持唯一的情况下,为多个连接复用同一源端口。
routing_mark
仅支持 Linux。
设置 netfilter 路由标记。
支持数字 (如 1234) 和十六进制字符串 (如 "0x1234")。
reuse_addr
重用监听地址。
netns
自 sing-box 1.12.0 起
仅支持 Linux。
设置网络命名空间,名称或路径。
connect_timeout
连接超时,采用 golang 的 Duration 格式。
持续时间字符串是一个可能有符号的序列十进制数,每个都有可选的分数和单位后缀, 例如 "300ms"、"-1.5h" 或 "2h45m"。 有效时间单位为 "ns"、"us"(或 "µs")、"ms"、"s"、"m"、"h"。
tcp_fast_open
启用 TCP Fast Open。
tcp_multi_path
需要 Go 1.21。
启用 TCP Multi Path。
disable_tcp_keep_alive
自 sing-box 1.13.0 起
禁用 TCP keep alive。
tcp_keep_alive
自 sing-box 1.13.0 起
默认值从 10m 更改为 5m。
TCP keep alive 初始周期。
默认使用 5m。
tcp_keep_alive_interval
自 sing-box 1.13.0 起
TCP keep alive 间隔。
默认使用 75s。
udp_fragment
启用 UDP 分段。
domain_resolver
outbound DNS 规则项已弃用,且将在 sing-box 1.14.0 中被移除。因此,从 sing-box 1.14.0 版本开始,所有在服务器地址中使用域名的出站/端点均需配置此项。
当只有一个 DNS 服务器已配置时,domain_resolver 或 route.default_domain_resolver 是可选的。
用于设置解析域名的域名解析器。
此选项的格式与 路由 DNS 规则动作 相同,但不包含 action 字段。
若直接将此选项设置为字符串,则等同于设置该选项的 server 字段。
| 出站/端点 | 受影响的域名 |
|---|---|
direct |
请求中的域名 |
| 其他类型 | 服务器地址中的域名 |
network_strategy
自 sing-box 1.11.0 起
仅在 Android 与 iOS 平台图形客户端中支持,并且需要 route.auto_detect_interface。
用于选择网络接口的策略。
可用值:
default(默认值):按顺序连接默认网络或network_type中指定的网络。hybrid:同时连接所有网络或network_type中指定的网络。fallback:同时连接默认网络或network_type中指定的首选网络,当不可用或超时时尝试回退网络。
对于回退模式,当首选接口失败或超时时, 将进入15秒的快速回退状态(同时连接所有首选和回退网络), 如果首选网络恢复,则立即退出。
与 bind_interface, bind_inet4_address 和 bind_inet6_address 冲突。
network_type
自 sing-box 1.11.0 起
仅在 Android 与 iOS 平台图形客户端中支持,并且需要 route.auto_detect_interface。
当使用 default 或 hybrid 网络策略时要使用的网络类型,或当使用 fallback 网络策略时要使用的首选网络类型。
可用值:wifi, cellular, ethernet, other。
默认使用设备默认网络。
fallback_network_type
自 sing-box 1.11.0 起
仅在 Android 与 iOS 平台图形客户端中支持,并且需要 route.auto_detect_interface。
当使用 fallback 网络策略时,在首选网络不可用或超时的情况下要使用的回退网络类型。
默认使用除首选网络外的所有其他网络。
fallback_delay
在生成 RFC 6555 快速回退连接之前等待的时间长度。
对于 domain_strategy,是在假设之前等待 IPv6 成功的时间量如果设置了 "prefer_ipv4",则 IPv6 配置错误并回退到 IPv4。
对于 network_strategy,对于 network_strategy,是在回退到其他接口之前等待连接成功的时间。
仅当 domain_strategy 或 network_strategy 已设置时生效。
默认使用 300ms。
prefer_domain
启用后,在连接出站之前,将连接的 IP 目标地址替换为已嗅探到的域名。
对于代理出站(vmess、trojan、vless 等),域名将转发给远端服务器,由其进行远程 DNS 解析。对于 direct/WireGuard 出站,则在本地进行解析。
组出站
prefer_domain 也可以在组出站(selector、urltest、loadbalance)上使用。在组出站上启用时,
覆盖将在分发给选定的子出站之前应用。详情参见组出站文档。
若连接尚未经过 sniff 规则动作,将在出站层面自动尝试一次最优嗅探(TCP 使用 TLS SNI / HTTP Host,UDP 使用 QUIC)。
支持两种形式:
- 布尔值:
true— 只要有可用域名,始终执行覆盖。 - 对象
{"mark": "0x1"}— 仅当连接的路由标记匹配时执行覆盖。格式与mark规则条件相同(整数、十六进制或位掩码)。
覆盖仅在以下条件同时满足时生效: 1. 连接目标当前为 IP 地址(非域名),且 2. 已成功从连接数据中嗅探到域名。
默认元数据标记
自 v1.13.0.7 起,sing-box 会为所有进入路由器且未预设标记的连接设置默认元数据标记
0x80(第 7 位)。这使 prefer_domain 支持退出(opt-out)模式:
- 使用
prefer_domain: {"mark": "0x80/0x80"}可默认对所有连接启用 prefer_domain (因为所有连接均带有第 7 位,除非被显式清除)。 - 通过
route-options规则设置"set_mark": 0可让特定连接退出—— 清除第 7 位后0x00 & 0x80 != 0x80,prefer_domain 将被跳过。
与 prefer_domain: true 相比,此模式更灵活,因为后者没有退出机制。
示例——始终优先使用域名:
示例——默认优先使用域名,对局域网地址退出(使用默认标记 0x80):
{
"outbounds": [
{
"type": "vmess",
"tag": "proxy",
"prefer_domain": {"mark": "0x80/0x80"}
},
{
"type": "direct",
"tag": "direct"
}
],
"route": {
"rules": [
{
"ip_cidr": ["10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16"],
"action": "route-options",
"set_mark": 0
},
{
"ip_cidr": ["10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16"],
"action": "route",
"outbound": "direct"
},
{
"action": "route",
"outbound": "proxy"
}
]
}
}
示例——仅在路由标记 0x1 设置时优先使用域名:
{
"outbounds": [
{
"type": "vmess",
"tag": "proxy",
"prefer_domain": {"mark": "0x1"}
}
],
"route": {
"rules": [
{
"protocol": "tls",
"action": "route-options",
"set_mark": "0x1"
},
{
"mark": "0x1",
"action": "route",
"outbound": "proxy"
}
]
}
}
domain_strategy
已在 sing-box 1.12.0 废弃
domain_strategy 已废弃且将在 sing-box 1.14.0 中被移除,参阅 迁移指南。
可选值:prefer_ipv4 prefer_ipv6 ipv4_only ipv6_only。
如果设置,域名将在请求发出之前解析为 IP。
| 出站 | 受影响的域名 | 默认回退值 |
|---|---|---|
direct |
请求中的域名 | inbound.domain_strategy |
| others | 服务器地址中的域名 | / |