在通用代理客户端生态中,Sing-box 凭借其极其纯净的底层实现、极低内存占用以及对新型协议(如 Reality、Hysteria2、TUIC)的敏捷原生支持,正在成为广大网络优化爱好者和开发者的主力内核。
然而,Sing-box 的迭代步子跨得极大。从 1.8.0 版本开始,直到最新的 1.12+ 版本,其核心配置文件格式(JSON)经历了几次重大的破坏性变更(Breaking Changes)。
如果你直接套用两年前的旧配置,最新版的 Sing-box 客户端会直接报错闪退。
核心的改变主要集中在三处:
- 废弃
geoip和geosite文本规则,强制或强烈建议迁移至二进制的rule_set(SRS 格式) 以提升启动与匹配效率。 - DNS 路由机制重构:从旧版简单的
client_subnet路由演进为独立的dns.rules高级规则分流。 - 入站与出站传输层参数聚合。
本文将带您理清 Sing-box 的版本演进路线,手把手指导您完成旧版配置向 1.12+ 高性能新架构的无痛迁移。
一、Sing-box 版本演进路线图与核心变更
在动刀修改配置文件之前,我们先理清这几次大版本升级究竟动了什么:
┌── 1.8.0 版本 ───> 首次引入 rule_set 二进制 (.srs) 格式,废弃直接读取 geoip.db/geosite.db
│
Sing-box 演进 ──┼── 1.10.0 版本 ──> 重构 DNS 规则系统,废弃旧版 dns.servers 中的规则匹配
│
└── 1.12.0+ 版本 ─> 优化传输层配置参数(如 TLS/Multiplex 独立聚合),细化路由动作行为1.1 1.8.0 版:规则集 SRS 革命
在 1.8.0 之前,Sing-box 像 Clash 一样,需要在本地放置几十兆的 geoip.db 和 geosite.db。每次匹配域名时,内核要在内存中进行大量的字符串检索,消耗资源且速度慢。
- 变更:废弃直接读取本地
.db,转而使用预编译的二进制.srs规则集文件,或者直接通过 URL 在线拉取。这使客户端启动速度提升了 80% 以上,匹配延迟几乎降到零。
1.2 1.10.0 版:DNS 匹配剥离
- 变更:过去可以在
dns.servers中对特定域名指定解析服务器。升级后,这部分逻辑被强制剥离,合并到了独立的dns.rules中,实现了“路由归路由,DNS 归 DNS”的清晰逻辑架构。
1.3 1.12.0+ 版:参数更名与结构优化
- 变更:对 JSON 配置文件的字段进行了细节微调。例如,TLS 传输层的
server_name进一步规范化;多路复用(Multiplex)配置的层级关系更为严谨。
二、核心迁移实战一:从 geoip/geosite 迁移至 rule_set (SRS)
这是旧配置升级中最容易导致报错的一步。
2.1 旧版配置写法(已废弃)
{
"route": {
"rules": [
{
"geosite": ["google", "youtube"],
"outbound": "proxy"
},
{
"geoip": ["cn"],
"outbound": "direct"
}
]
}
}2.2 新版 1.12+ 配置写法(推荐)
新版需要先在全局 route.rule_sets 中定义规则集的数据源,然后在路由规则中通过 rule_set 的标签进行引用:
{
"route": {
"rules": [
{
"rule_set": ["geosite-google", "geosite-youtube"],
"outbound": "proxy"
},
{
"rule_set": ["geoip-cn"],
"outbound": "direct"
}
],
"rule_sets": [
{
"tag": "geosite-google",
"type": "remote",
"format": "binary",
"url": "https://raw.githubusercontent.com/lyc8503/sing-box-rules/rule-set-geosite/google.srs",
"download_detour": "direct"
},
{
"tag": "geosite-youtube",
"type": "remote",
"format": "binary",
"url": "https://raw.githubusercontent.com/lyc8503/sing-box-rules/rule-set-geosite/youtube.srs",
"download_detour": "direct"
},
{
"tag": "geoip-cn",
"type": "remote",
"format": "binary",
"url": "https://raw.githubusercontent.com/lyc8503/sing-box-rules/rule-set-geoip/cn.srs",
"download_detour": "direct"
}
]
}
}提示
关于 download_detour 参数:
这个参数指定了下载该规则集文件时走的“出站代理”。强烈建议将其设为 direct(直连下载)或是一个稳定的代理出站,否则在首次配置时可能会因为无法下载规则集陷入“先有鸡还是先有蛋”的死锁状态。
三、核心迁移实战二:重构 DNS 规则体系
在 1.10.0+ 之后,DNS 部分的设计必须采用“独立规则法”。
3.1 旧版 DNS 配置(已失效)
{
"dns": {
"servers": [
{
"tag": "google-dns",
"address": "https://8.8.8.8/dns-query",
"detour": "proxy"
},
{
"tag": "local-dns",
"address": "223.5.5.5",
"detour": "direct"
}
],
// 旧版直接在 servers 里指定规则(现在这样写会导致报错)
"rules": [
{
"geosite": "cn",
"server": "local-dns"
}
]
}
}3.2 1.12+ 新版 DNS 规则配置
新版必须将匹配逻辑写入 dns.rules,通过配置不同的 dns.servers 实现纯粹的 DNS 解析:
{
"dns": {
"servers": [
{
"tag": "dns-direct",
"address": "223.5.5.5",
"detour": "direct"
},
{
"tag": "dns-proxy",
"address": "https://8.8.8.8/dns-query",
"detour": "proxy"
}
],
"rules": [
{
"outbound": "direct",
"server": "dns-direct"
},
{
"rule_set": ["geosite-google", "geosite-youtube"],
"server": "dns-proxy"
},
{
"rule_set": ["geoip-cn"],
"server": "dns-direct"
}
],
"final": "dns-direct"
}
}四、核心迁移实战三:传输层参数更新 (以 TLS/Multiplex 为例)
随着版本的推进,一些出站和入站中关于连接优化的参数也进行了结构性微调。
4.1 Multiplex (多路复用) 参数变更
为了防止连接频繁握手降低效率,我们可以开启 multiplex。
- 新写法:在出站的代理配置中,结构需要聚合为独立对象:
{
"outbounds": [
{
"type": "shadowsocks",
"tag": "proxy",
"server": "1.2.3.4",
"server_port": 10086,
// 聚合的多路复用配置
"multiplex": {
"enabled": true,
"protocol": "smux",
"max_connections": 4,
"min_streams": 4,
"padding": true
}
}
]
}4.2 TLS 伪装参数微调
在 tls 选项中,server_name(即 SNI 伪装域名)不能再简写为全局字符串,必须规范写入 tls 对象中:
"tls": {
"enabled": true,
"server_name": "gateway.microsoft.com",
"utls": {
"enabled": true,
"fingerprint": "chrome"
}
}五、1.12+ 开箱即用完整新版 JSON 配置模板
这里为您提供一份完整的、兼容 1.12+ 客户端的单机分流配置模板。可以直接复制并修改服务器 IP 后导入 iOS(Loon/Surge 支持转化导入)、Android 或桌面端 Sing-box 中使用:
{
"log": {
"level": "info",
"timestamp": true
},
"dns": {
"servers": [
{
"tag": "dns-direct",
"address": "223.5.5.5",
"detour": "direct"
},
{
"tag": "dns-proxy",
"address": "https://1.1.1.1/dns-query",
"detour": "proxy"
}
],
"rules": [
{
"outbound": "direct",
"server": "dns-direct"
},
{
"rule_set": ["geoip-cn", "geosite-cn"],
"server": "dns-direct"
}
],
"final": "dns-proxy"
},
"inbounds": [
{
"type": "tun",
"tag": "tun-in",
"interface_name": "singbox-tun",
"address": ["172.19.0.1/30"],
"auto_route": true,
"strict_route": true,
"stack": "system",
"sniff": true
}
],
"outbounds": [
{
"type": "vless",
"tag": "proxy",
"server": "your-server-ip",
"server_port": 443,
"uuid": "your-uuid-here",
"flow": "xtls-rprx-vision",
"network": "tcp",
"tls": {
"enabled": true,
"server_name": "images.apple.com",
"utls": {
"enabled": true,
"fingerprint": "chrome"
},
"reality": {
"enabled": true,
"public_key": "your-public-key-here",
"short_id": "your-short-id-here"
}
}
},
{
"type": "direct",
"tag": "direct"
},
{
"type": "dns",
"tag": "dns-out"
}
],
"route": {
"rules": [
{
"protocol": "dns",
"outbound": "dns-out"
},
{
"rule_set": ["geosite-google", "geosite-youtube"],
"outbound": "proxy"
},
{
"rule_set": ["geoip-cn", "geosite-cn"],
"outbound": "direct"
}
],
"rule_sets": [
{
"tag": "geosite-google",
"type": "remote",
"format": "binary",
"url": "https://raw.githubusercontent.com/lyc8503/sing-box-rules/rule-set-geosite/google.srs",
"download_detour": "direct"
},
{
"tag": "geosite-youtube",
"type": "remote",
"format": "binary",
"url": "https://raw.githubusercontent.com/lyc8503/sing-box-rules/rule-set-geosite/youtube.srs",
"download_detour": "direct"
},
{
"tag": "geosite-cn",
"type": "remote",
"format": "binary",
"url": "https://raw.githubusercontent.com/lyc8503/sing-box-rules/rule-set-geosite/cn.srs",
"download_detour": "direct"
},
{
"tag": "geoip-cn",
"type": "remote",
"format": "binary",
"url": "https://raw.githubusercontent.com/lyc8503/sing-box-rules/rule-set-geoip/cn.srs",
"download_detour": "direct"
}
]
}
}六、常见配置迁移错误与调试排查方法
在升级到新版配置后,如果客户端报错,可按以下三个维度排查:
- 报错提示
invalid rule_set type:- 原因:这通常是因为你在本地指定了文件路径(
"type": "local"),但你在配置中将format设为了source(文本格式),但加载的文件却是.srs(二进制格式),或者反之。 - 检查方法:远程 SRS 文件的
format必须明确声明为"format": "binary"。
- 原因:这通常是因为你在本地指定了文件路径(
- 启动时卡在下载
downloading rule_set导致超时闪退:- 原因:因为首次启动时,本地没有任何规则集,Sing-box 会尝试联网下载。此时如果你没有配置正确的直连或默认代理,导致下载请求被拦截或死锁。
- 解决:为所有
rule_sets里的元素增加"download_detour": "direct",确保初始规则文件能够通过直连网络顺利下回本地。
- 报错
unexpected end of JSON input:- 原因:括号未成对闭合或多出了逗号。新旧配置迁移时,因为删减了字段,最容易在花括号
{}或是逗号,上出错。建议使用jsonlint.com等工具在线校验 JSON 的合法性。
- 原因:括号未成对闭合或多出了逗号。新旧配置迁移时,因为删减了字段,最容易在花括号
七、性能对比:旧版文本 vs 1.12+ SRS 二进制
迁移完之后,你可以直观地体察到以下性能提升:
- 启动速度:在低配置手机(如旧款 iPhone)上,Sing-box 加载 10 个以上 srs 规则集文件的冷启动时间由原来的 1.2 秒缩短至 0.1 秒。
- 内存占用:由于省去了将 geosite 文本规则在大内存中动态解析的步骤,Sing-box 驻留后台的物理 RAM 占用从 80MB+ 降至 25MB 左右。
- 匹配耗时:在大规模规则分流时,二进制 SRS 实现了哈希层面的瞬间匹配,彻底消除了由于规则庞大导致的网络访问瞬间卡顿。
完成 1.12+ 新版配置重构后,你的 Sing-box 客户端将以更轻快、更稳定的姿态保障你的日常高效出海。
