在 Windows 配置 sing-box 的订阅和路由
在 Windows 使用 sing-box 时,可以先选择命令行或图形客户端,再准备配置与订阅。
调试时先分清流量从哪个入站进来、怎样匹配路由以及由哪个出站发出。
sing-box 的入站、DNS、路由和出站
将每一处配置与对应的连接阶段对照,便于查找故障。
入站(Inbounds)
入站指定请求如何进入 sing-box,可区分代理监听端口和 TUN。
DNS 路由(DNS Subsystem)
在 DNS 段核对解析上游与相应的规则。
路由与规则集(Route & Rule-Set)
路由规则用于决定命中的流量走哪个出站。 .srs 检查配置是否正确引用规则集。
出站(Outbounds)
出站指定请求的下一跳。查看所选节点协议,例如 VLESS 或 Shadowsocks。
Windows 命令行与图形客户端
按日常管理方式选择 CLI 或 GUI。
在 Windows 终端启动 sing-box
- 在 sing-box 的 GitHub Releases 查看 Windows 构建。
sing-box-x.y.z-windows-amd64.zip按设备架构选择对应文件。 - 解压到用户有访问权限的目录。
C:\Tools\sing-box准备好命令中引用的路径。 - 核对程序文件名。
sing-box.exe确保终端调用的是预期文件。 - 将配置文件放在指定路径。
config.json检查启动参数指向该配置。 - 在终端启动 sing-box。
sing-box.exe run查看加载配置时输出的日志。
GUI for sing-box 与 NekoBox for Windows
图形方式便于查看节点与配置是否导入。
- GUI for sing-box|在图形界面核对配置及连接状态。
- NekoBox for Windows|检查当前使用的核心与导入格式。
config.json 的配置项
修改前核对入站、DNS、路由与出站所用的名称。
config.json 示例
{ "log": { "level": "info", "timestamp": true }, "dns": { "servers": [ { "tag": "dns-remote", "address": "", "address_resolver": "dns-direct", "strategy": "ipv4_only", "detour": "select-proxy" }, { "tag": "dns-direct", "address": "223.5.5.5", "strategy": "ipv4_only", "detour": "direct" }, { "tag": "dns-fakeip", "address": "fakeip" } ], "rules": [ { "outbound": "any", "server": "dns-direct" }, { "rule_set": "geosite-cn", "server": "dns-direct" }, { "query_type": ["A", "AAAA"], "server": "dns-fakeip" } ], "fakeip": { "enabled": true, "inet4_range": "198.18.0.0/15" }, "strategy": "ipv4_only" }, "inbounds": [ { "type": "mixed", "tag": "mixed-in", "listen": "127.0.0.1", "listen_port": 2080, "sniff": true }, { "type": "tun", "tag": "tun-in", "interface_name": "singbox-tun", "inet4_address": "172.19.0.1/30", "auto_route": true, "strict_route": true, "stack": "system", "sniff": true } ], "outbounds": [ { "type": "selector", "tag": "select-proxy", "outbounds": [ "auto-urltest", "香港 01 专线", "日本 01 专线", "direct" ], "default": "auto-urltest" }, { "type": "urltest", "tag": "auto-urltest", "outbounds": [ "香港 01 专线", "日本 01 专线" ], "url": "", "interval": "3m", "tolerance": 50 }, { "type": "vless", "tag": "香港 01 专线", "server": "hk01.example.com", "server_port": 443, "uuid": "e9b8b0e6-8c8f-4d3b-8211-1a2b3c4d5e6f", "flow": "xtls-rprx-vision", "tls": { "enabled": true, "server_name": "gateway.icloud.com", "reality": { "enabled": true, "public_key": "YOUR_REALITY_PUBLIC_KEY_HERE", "short_id": "0123456789abcdef" }, "utls": { "enabled": true, "fingerprint": "chrome" } } }, { "type": "direct", "tag": "direct" }, { "type": "block", "tag": "block" }, { "type": "dns", "tag": "dns-out" } ], "route": { "rule_set": [ { "tag": "geosite-cn", "type": "remote", "format": "binary", "url": "", "download_detour": "select-proxy" }, { "tag": "geoip-cn", "type": "remote", "format": "binary", "url": "", "download_detour": "select-proxy" } ], "rules": [ { "protocol": "dns", "outbound": "dns-out" }, { "ip_is_private": true, "outbound": "direct" }, { "rule_set": "geosite-cn", "outbound": "direct" }, { "rule_set": "geoip-cn", "outbound": "direct" } ], "auto_detect_interface": true, "final": "select-proxy" }}Rule-Set 与 SRS 规则集
规则集独立管理时,先确认主配置能找到所用文件。
SRS 文件的引用
在加载 SRS 前核对格式与配置标识。
- 需要分发编译后的规则时,核对文件是否为 SRS。
.srs - 引用本地规则集时,核对文件路径和格式。
.srs - 远程规则更新|核对远程规则集的更新项。
route.rule_settype: remote检查下载和载入的日志。
Windows 上的 TUN 虚拟网卡
启用前明确哪些程序的流量要由 TUN 接管。
检查 TUN 及路由字段
逐项检查 TUN 入站和路由配置。 inbounds 对照实际的网卡与出站。
stack: "system"核对 TUN 当前使用的网络栈。auto_route: true查看自动添加路由的设置。strict_route: true核对严格路由的配置。auto_detect_interface: true确认是否指定了用于出站的网卡行为。route
Clash API 与 Web 仪表盘
通过控制接口查看状态之前,先核对访问范围。
experimental.clash_api 配置
在 config.json 中定位该项。 检查监听地址。
{ "experimental": { "clash_api": { "external_controller": "127.0.0.1:9090", "external_ui": "metacubexd", "external_ui_download_url": "", "external_ui_download_detour": "select-proxy", "secret": "MySuperSecretKey2026", "default_mode": "rule" } }}在 Web 仪表盘查看活动连接
打开 Web 仪表盘前,先确认控制接口的监听地址与访问设置。
- 可按当前连接的目标地址与出站名称检查分流。
对 Windows 进程设置路由
需要区分多个应用时,先确认进程名称是否不同。
process_name 的匹配项
对照 Windows 显示的进程名检查规则。 route.rules 确认规则匹配后使用哪个出站。
[ { "process_name": ["git.exe", "ssh.exe", "curl.exe"], "outbound": "select-proxy" }, { "process_name": ["WeChat.exe", "QQ.exe", "DingTalk.exe"], "outbound": "direct" }, { "process_name": ["steam.exe", "cs2.exe", "ApexLegends.exe"], "outbound": "香港 01 专线" }]把 JSON 规则集编译成 SRS
自建规则集时,先准备规则源文件。
编辑 JSON 规则集
在本地准备 JSON 文件。 my-company-rules.json 检查其中的规则语法。
{ "version": 1, "rules": [ { "domain": [ "corp.internal.net", "gitlab.dev.local" ], "domain_suffix": [ ".internal.cloud", ".devcluster.com" ], "ip_cidr": [ "10.200.0.0/16", "172.28.0.0/14" ] } ]}用 sing-box 命令生成 SRS
在 Windows 终端运行编译命令。 rule-set compile 留意输入与输出路径。
# 将 JSON 规则集编译为二进制 .srs 文件C:Toolssing-boxsing-box.exe rule-set compile --output my-company-rules.srs my-company-rules.jsonWrite-Host "私有二进制规则集已成功完成预编译构建!" -ForegroundColor Green在主配置中引用编译后的文件。 route.rule_settype: localmy-company-rules.srs 核对规则集标记。
DNS 与 Fake-IP 设置
域名解析异常时先看当前使用的 DNS 上游。
Fake-IP 的解析与匹配
打开 Fake-IP 时,查看域名访问所用的 DNS 结果。 198.18.0.0/15 再检查路由是否按预期匹配。
多个出站的连接检查
分别查看各个出站的连接状态。
Fallback 出站配置示例
配置中可先核对备选出站名称及探测目标。
{ "type": "urltest", "tag": "fallback-cluster", "outbounds": [ "香港 01 专线 (首选)", "日本 01 专线 (备用)", "新加坡 01 专线 (容灾)" ], "url": "", "interval": "3m", "tolerance": 50}Windows 后台服务的状态检查
唤醒后如连接异常,先查看 sing-box 进程状态。
Windows 唤醒后的连接检查
下面的示例用于查看后台服务运行状态。
# sing-box 唤醒自愈与网络健康测试脚本$ServiceName = "SingBoxService"try { $Status = (Get-Service -Name $ServiceName -ErrorAction Stop).Status if ($Status -ne "Running") { Write-Host "检测到服务异常中断,正在尝试拉起服务..." -ForegroundColor Yellow Restart-Service -Name $ServiceName -Force }} catch { Write-Host "未找到后台服务,直接测试核心进程..." -ForegroundColor Cyan}
# 刷新本地 DNS 缓存并验证网关连通性Clear-DnsClientCache$TestResult = Test-Connection -TargetName "172.19.0.1" -Count 2 -Quietif ($TestResult) { Write-Host "TUN 虚拟网卡通信健康,网络漫游通道就绪!" -ForegroundColor Green} else { Write-Host "虚拟网卡网关响应异常,请检查 Wintun 驱动状态!" -ForegroundColor Red}检查订阅资源的配置
使用配置示例前,先与当前 sing-box 客户端支持的格式对照。
{ "outbound_providers": [ { "type": "remote", "tag": "airport-primary", "download_url": "", "path": "./providers/primary.json", "download_interval": "12h", "download_detour": "direct" } ]}Windows 上的服务管理与语法检查
命令行启动失败时,先查看配置检查结果。
使用 NSSM 管理 sing-box 服务
核对 NSSM 服务所引用的程序、配置路径和启动目录。
# 下载并调用 nssm.exe 注册 sing-box 后台服务nssm install SingBoxService "C:Toolssing-boxsing-box.exe" "run -c C:Toolssing-boxconfig.json"nssm set SingBoxService AppDirectory "C:Toolssing-box"nssm set SingBoxService Start SERVICE_AUTO_STARTnssm set SingBoxService AppStdout "C:Toolssing-boxstdout.log"nssm set SingBoxService AppStderr "C:Toolssing-boxstderr.log"
# 启动该系统服务Start-Service SingBoxServiceWrite-Host "sing-box 已成功注册为 Windows 系统后台自愈服务!" -ForegroundColor Green修改配置后的语法检查
重启前先运行语法检查。 config.json 用终端输出确认配置是否通过。
# 验证 sing-box 配置语法与规则合法性C:Toolssing-boxsing-box.exe check -c C:Toolssing-boxconfig.json若检查有报错,先处理错误。 configuration check successful 保存后再次检查。
sing-box、Xray-core 与 Clash 系核心
用配置格式和规则集类型区分各核心。
| 项目 | sing-box | Xray-core | Mihomo(Clash.Meta) | Clash Premium |
|---|---|---|---|---|
| 开发语言 | Go | Go(源自 V2Ray) | Go(源自 Clash) | Go |
| 配置格式 | JSON | JSON | YAML | YAML |
| 规则集 | SRS | DAT | MRS 与文本 Provider | 文本 Rules |
Windows 上的 sing-box 故障场景
启动时提示 JSON 语法错误
检查配置文件里括号和逗号是否配对。 config.jsonfatal error: failed to parse config: invalid character '}' looking for beginning of value
outbounds
- 在 VS Code 打开配置并查看报错位置。
config.json - 去掉多余的末尾逗号后保存。
- 重跑配置检查。
sing-box check -c config.json通过后再启动服务。
启用 TUN 后网络断开
检查 TUN 自动路由启用后,节点连接是否被送回虚拟网卡。 auto_route: true
routeauto_detect_interface: true
- 网络断开时,可先退出 sing-box 并检查是否恢复。
sing-box.exe - 核对实际的出站网卡和路由选项。
route"auto_detect_interface": true调整后再比较。
远程 SRS 规则下载失败
先查规则集地址是否可访问。 downloading rule-set: geosite-cncontext deadline exceeded
查看是否有下载超时。
- 查看远程规则集使用的下载出站。
download_detour: "select-proxy" - 已有对应的 SRS 文件时,核对本地引用路径。
geosite-cn.srsgeoip-cn.srsremotelocal
Reality 握手失败与系统时间
连接使用 VLESS-Reality 时,核对 Windows 显示的时间。 sing-box.exe
- 在 PowerShell 检查时间同步。
w32tm /resync /force核对同步结果。
sing-box Windows 常见问题
config.json 报语法错误怎么定位?
按报错的行和列检查引号、括号和末尾逗号,修改后再运行配置检查。
为什么关闭控制台窗口后 sing-box 会停止?
在 CMD 或 PowerShell 中前台启动时,关闭窗口会结束对应进程。需要持续运行时可检查 Windows 服务设置。 sing-box.exe run
更新 sing-box 前要备份哪些文件?
保留 、引用的规则集和原可执行文件,再核对 GitHub Releases 的变更说明。 sing-box.execonfig.json.srs
局域网内的 sing-box 监听设置
检查监听地址时,先确认需要连接的设备范围。
mixed 入站的监听地址
查看配置示例中的监听地址、端口以及可连接的设备。 127.0.0.10.0.0.0
{ "type": "mixed", "tag": "mixed-lan-in", "listen": "0.0.0.0", "listen_port": 2080, "sniff": true, "users": []}Windows 防火墙入站设置
检查防火墙规则覆盖的网络范围。
# 在 Windows 防火墙中放行 sing-box 混合代理端口入站连接New-NetFirewallRule -DisplayName "SingBox LAN Inbound" -Direction Inbound -LocalPort 2080 -Protocol TCP -Action AllowWrite-Host "局域网入站代理端口 2080 已成功放行!" -ForegroundColor Green查设备的代理设置时,确认填写的是本机局域网地址和对应端口。 192.168.1.1502080
用日志定位网络问题
排障时根据问题范围调节日志级别。
config.json 中的日志级别
查看日志设置项。 config.jsonlog 调整前保存现有配置。
warn日常运行可查看警告和错误级别。errordebug联调时可用更详细的日志查到规则命中信息。trace
配置文件和运行状态的复查
每次修改先验证配置,再检查启动日志、连接和规则命中。
- 开启 TUN 后,通过日志核对出站网卡是否正确。
auto_detect_interface
分享文章
将这篇文章分享给其他人。