5005 字
25 分钟

sing-box 全平台使用教程:新一代通用代理平台配置指南 | 2026 最新

sing-box 是 2026 年最值得关注的新一代通用代理平台。随着 Clash 原版删库停更、Clash Meta(Mihomo)转向收费,sing-box 凭借更广的协议支持、更灵活的路由规则和更低的资源占用,正在成为代理工具的首选。

本文从配置文件结构、多协议支持、路由分流、DNS 防污染到全平台安装使用,手把手带你从零配置 sing-box。

还没有机场订阅?先看这里:

1. sing-box 是什么?为什么要用它?#

1.1 sing-box 简介#

sing-box 是由 SagerNet 开发的新一代通用代理平台,用 Go 语言编写,目标是成为「代理工具的瑞士军刀」。它不是一个单纯的客户端,而是一个代理平台框架——你可以把它当作内核(Core),在上面运行各种图形界面客户端。

核心特点:

特点说明
多协议支持Shadowsocks、VMess、VLESS、Trojan、Hysteria 2、ShadowTLS、TUIC 等
灵活路由支持规则集(rule_set)、DNS 规则独立分流、多出站链式组合
高性能Go 语言编写,内存占用低,连接处理快
全平台Windows / macOS / Linux / iOS / Android 全覆盖
活跃维护2026 年持续更新,社区活跃

1.2 sing-box vs Clash:核心区别#

很多用户从 Clash 转到 sing-box,两者的关键区别:

对比项Clash / Clash Metasing-box
配置格式YAMLJSON
协议支持Shadowsocks/VMess/VLESS/Trojan + 插件扩展原生支持全部主流协议,包括 Hysteria2
Hysteria2仅 Clash Meta 通过插件支持原生支持,性能最佳
ShadowTLS不支持原生支持 v3
DNS 功能基础 DNS + 简单分流DNS 规则独立配置,支持 DNS 规则集
路由规则Rule Provider 规则集rule_set 规则集 + DNS 规则分流
出站组合relay 链式代理支持链式组合、UDP over TCP 等
维护状态Clash 原版已停更,Meta 活跃活跃维护,持续更新
内存占用50-80 MB20-40 MB

什么时候选 sing-box:

  • 需要 Hysteria2 / ShadowTLS 等新协议
  • 需要更精细的 DNS 分流控制
  • 追求更低内存占用
  • 机场已提供 sing-box 订阅格式

什么时候继续用 Clash:

  • 习惯 Clash Verge Rev 的图形界面,不想换
  • 机场仅提供 Clash 订阅
  • 只需要基础代理功能,Clash 够用

2. 配置文件结构详解#

sing-box 使用 JSON 格式配置文件,这是与 Clash YAML 的最大区别。别怕——JSON 配置其实更严谨,不容易出格式错误。

2.1 配置文件整体结构#

一个完整的 sing-box 配置文件包含以下 7 个顶级字段:

{
"log": {}, // 日志配置
"dns": {}, // DNS 配置
"inbounds": [], // 入站配置(代理模式)
"outbounds": [], // 出站配置(代理节点)
"route": {}, // 路由分流规则
"experimental": {} // 宂验功能(缓存等)
}

每个字段的作用:

┌─────────────────────────────────────────────┐
│ sing-box 配置结构 │
├─────────────────────────────────────────────┤
│ │
│ log → 日志级别、输出路径 │
│ dns → DNS 服务器 + DNS 规则分流 │
│ inbounds → 本地接收流量(mixed/tun/direct)│
│ outbounds → 远程节点(ss/vmess/vless/…) │
│ route → 流量分流规则 + rule_set │
│ experimental → 缓存/Clash API等实验功能 │
│ │
├─────────────────────────────────────────────┤
│ 流量路径: │
│ App → inbound → route → outbound → 目标 │
│ ↑ ↑ ↑ │
│ 接收流量 分流决策 代理转发 │
└─────────────────────────────────────────────┘

2.2 log 日志配置#

{
"log": {
"level": "info",
"timestamp": true
}
}

日志级别可选值:

  • trace:最详细,调试用
  • debug:开发调试
  • info:正常运行(推荐)
  • warn:仅警告和错误
  • error:仅错误
  • fatal:仅致命错误
  • silent:不输出日志

2.3 dns DNS 配置#

sing-box 的 DNS 配置比 Clash 更强大,支持独立 DNS 规则分流

{
"dns": {
"servers": [
{
"tag": "dns-direct",
"address": "223.5.5.5",
"detour": "direct-out"
},
{
"tag": "dns-remote",
"address": "tls://8.8.8.8",
"detour": "proxy-out"
},
{
"tag": "dns-block",
"address": "rcode://success"
}
],
"rules": [
{
"outbound": ["any"],
"server": "dns-direct"
},
{
"rule_set": ["geosite-cn"],
"server": "dns-direct"
},
{
"rule_set": ["geosite-geolocation-!cn"],
"server": "dns-remote"
},
{
"rule_set": ["geosite-category-ads-all"],
"server": "dns-block"
}
],
"final": "dns-remote",
"strategy": "prefer_ipv4"
}
}

关键概念:

  • servers:定义 DNS 服务器,每个有 tag 标签
  • detour:指定 DNS 请求走哪个出站(国内 DNS 走直连,国外 DNS 赫代理)
  • rules:DNS 规则分流——国内域名用国内 DNS 解析,国外域名用国外 DNS
  • rcode://success:直接返回空结果(用于广告拦截)
  • strategy:IP 解析策略,prefer_ipv4 优先 IPv4(避免 IPv6 连不上)

3. inbound 入站配置#

入站(inbound)决定 sing-box 如何在本地接收流量。常用的入站类型:

3.1 mixed 入站(系统代理模式)#

最基础的入站,提供 HTTP + SOCKS5 混合代理:

{
"inbounds": [
{
"type": "mixed",
"tag": "mixed-in",
"listen": "127.0.0.1",
"listen_port": 7890
}
]
}

设置后,浏览器/应用设置代理为 127.0.0.1:7890 即可使用。

3.2 tun 入站(全局代理模式)#

TUN 模式在系统层创建虚拟网卡,接管所有流量——真正的全局代理:

{
"inbounds": [
{
"type": "tun",
"tag": "tun-in",
"inet4_address": "172.19.0.1/30",
"auto_route": true,
"strict_route": true,
"stack": "mixed",
"sniff": true,
"sniff_override_destination": false
}
]
}

参数说明:

  • inet4_address:虚拟网卡 IP(可自定义,不要和真实网卡冲突)
  • auto_route:自动配置路由表(接管全局流量)
  • strict_route:严格路由(防止流量泄漏)
  • stack:网络栈,mixed 推荐(兼顾性能和兼容性)
  • sniff:嗅探协议类型(识别 HTTP/TLS 等流量特征)
  • sniff_override_destination:是否用嗅探结果覆盖目标地址

macOS / Linux 需要管理员权限运行 TUN 模式!

3.3 direct 入站#

用于接收需要直连的流量(比如局域网服务):

{
"type": "direct",
"tag": "direct-in",
"listen": "127.0.0.1",
"listen_port": 7891
}

3.4 完整入站配置(混合模式)#

实际使用中通常同时配置 mixed + tun:

{
"inbounds": [
{
"type": "mixed",
"tag": "mixed-in",
"listen": "127.0.0.1",
"listen_port": 7890,
"sniff": true,
"sniff_override_destination": false
},
{
"type": "tun",
"tag": "tun-in",
"inet4_address": "172.19.0.1/30",
"inet6_address": "fdfe:dcba:9876::1/126",
"auto_route": true,
"strict_route": true,
"stack": "mixed",
"sniff": true,
"sniff_override_destination": false
}
]
}

4. outbound 出站配置(代理节点)#

出站(outbound)就是代理节点配置。sing-box 支持的主流协议:

4.1 direct 直连出站#

不走代理,直接连接:

{
"type": "direct",
"tag": "direct-out"
}

4.2 block 拦截出站#

直接拒绝连接(用于广告拦截):

{
"type": "block",
"tag": "block-out"
}

4.3 dns DNS 出站#

用于 DNS 查询的出站:

{
"type": "dns",
"tag": "dns-out"
}

4.4 Shadowsocks#

{
"type": "shadowsocks",
"tag": "ss-out",
"server": "your-server.com",
"server_port": 8388,
"method": "aes-256-gcm",
"password": "your-password"
}

支持的方法:aes-256-gcmaes-128-gcmchacha20-ietf-poly13052022-blake3-aes-256-gcm 等。

4.5 VMess(V2Ray)#

{
"type": "vmess",
"tag": "vmess-out",
"server": "your-server.com",
"server_port": 443,
"uuid": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"security": "auto",
"alter_id": 0,
"transport": {
"type": "ws",
"path": "/ws-path",
"headers": {
"Host": "your-domain.com"
}
},
"tls": {
"enabled": true,
"server_name": "your-domain.com"
}
}

4.6 VLESS#

{
"type": "vless",
"tag": "vless-out",
"server": "your-server.com",
"server_port": 443,
"uuid": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"flow": "xtls-rprx-vision",
"tls": {
"enabled": true,
"server_name": "your-domain.com",
"utls": {
"enabled": true,
"fingerprint": "chrome"
}
}
}

VLESS + XTLS Vision 是当前最高效的协议组合,比 VMess + WS 性能更好。

4.7 Trojan#

{
"type": "trojan",
"tag": "trojan-out",
"server": "your-server.com",
"server_port": 443,
"password": "your-trojan-password",
"tls": {
"enabled": true,
"server_name": "your-domain.com"
}
}

4.8 Hysteria2(重点推荐)#

Hysteria2 是基于 QUIC 协议的新一代代理协议,速度极快,尤其适合高延迟网络:

{
"type": "hysteria2",
"tag": "hy2-out",
"server": "your-server.com",
"server_port": 443,
"password": "your-hy2-password",
"tls": {
"enabled": true,
"server_name": "your-domain.com",
"insecure": false
},
"up": "50 Mbps",
"down": "100 Mbps"
}

参数说明:

  • up / down:带宽限制(可选,帮助服务端分配资源)
  • Hysteria2 基于 QUIC,天然支持多路复用,比 TCP 协议更快
  • 在跨洲线路(如中美)上效果尤为显著

4.9 ShadowTLS v3#

ShadowTLS 用于伪装 TLS 流量,绕过 SNI 检测:

{
"type": "shadowtls",
"tag": "stls-out",
"server": "your-server.com",
"server_port": 443,
"version": 3,
"password": "your-shadowtls-password",
"tls": {
"enabled": true,
"server_name": "www.microsoft.com"
},
"detour": "ss-inner-out"
}

ShadowTLS 需要配合内部代理(如 Shadowsocks),通过 detour 指定内部代理出站:

{
"type": "shadowsocks",
"tag": "ss-inner-out",
"method": "2022-blake3-aes-128-gcm",
"password": "inner-password"
}

4.10 Selector 选择器出站(类似 Clash 的 Proxy Group)#

sing-box 通过 selector 类型实现节点分组切换:

{
"type": "selector",
"tag": "proxy-out",
"outbounds": [
"hy2-out",
"vless-out",
"vmess-out",
"trojan-out",
"ss-out",
"auto-select"
],
"default": "hy2-out"
}

4.11 URLTest 自动选择出站#

自动测速选择最优节点:

{
"type": "urltest",
"tag": "auto-select",
"outbounds": [
"hy2-out",
"vless-out",
"vmess-out",
"trojan-out",
"ss-out"
],
"url": "https://www.gstatic.com/generate_204",
"interval": "5m",
"tolerance": 50
}

参数说明:

  • url:测速目标 URL
  • interval:测速间隔(5m = 每 5 分钟测一次)
  • tolerance:延迟容差(ms),新节点比当前节点快超过此值才切换

5. route 路由分流配置#

路由规则决定哪些流量走代理、哪些直连、哪些拦截。sing-box 的路由比 Clash 更灵活。

5.1 路由规则基础#

{
"route": {
"rules": [
// 规则按顺序匹配,先匹配到的生效
{
"protocol": "dns",
"outbound": "dns-out"
},
{
"ip_is_private": true,
"outbound": "direct-out"
},
{
"type": "logical",
"mode": "or",
"rules": [
{ "port": [80, 443] },
{ "network": "tcp" }
],
"outbound": "proxy-out"
}
],
"final": "proxy-out",
"find_process_mode": "strict"
}
}

路由规则匹配顺序:从上到下逐条匹配,匹配成功即停止。最后 final 是兜底规则。

5.2 常用规则类型#

规则类型字段示例
域名匹配domain["google.com", "youtube.com"]
域名后缀domain_suffix[".google.com", ".youtube.com"]
域名关键词domain_keyword["google", "netflix"]
域名正则domain_regex["^.*\\.google\\.com$"]
IP CIDRip_cidr["10.0.0.0/24", "192.168.0.0/16"]
GeoIPgeoip["cn"]
GeoSitegeosite["cn", "google", "netflix"]
进程名process_name["chrome", "telegram"]
端口port[80, 443, 8080]
网络network"tcp" / "udp"
协议protocol"dns" / "http" / "tls"
规则集rule_set["geosite-cn", "geoip-cn"]

5.3 rule_set 规则集(核心功能)#

rule_set 类似 Clash 的 Rule Provider,从远程加载预定义规则集:

{
"route": {
"rule_set": [
{
"tag": "geosite-cn",
"type": "remote",
"format": "binary",
"url": "https://raw.githubusercontent.com/SagerNet/sing-geoosite/rule-set/geosite-cn.srs",
"download_detour": "proxy-out"
},
{
"tag": "geoip-cn",
"type": "remote",
"format": "binary",
"url": "https://raw.githubusercontent.com/SagerNet/sing-geoip/rule-set/geoip-cn.srs",
"download_detour": "proxy-out"
},
{
"tag": "geosite-category-ads-all",
"type": "remote",
"format": "binary",
"url": "https://raw.githubusercontent.com/SagerNet/sing-geoosite/rule-set/geosite-category-ads-all.srs",
"download_detour": "proxy-out"
},
{
"tag": "geosite-geolocation-!cn",
"type": "remote",
"format": "binary",
"url": "https://raw.githubusercontent.com/SagerNet/sing-geoosite/rule-set/geosite-geolocation-!cn.srs",
"download_detour": "proxy-out"
}
],
"rules": [
{
"protocol": "dns",
"outbound": "dns-out"
},
{
"ip_is_private": true,
"outbound": "direct-out"
},
{
"rule_set": ["geosite-category-ads-all"],
"outbound": "block-out"
},
{
"rule_set": ["geosite-cn", "geoip-cn"],
"outbound": "direct-out"
},
{
"rule_set": ["geosite-geolocation-!cn"],
"outbound": "proxy-out"
}
],
"final": "proxy-out"
}
}

rule_set 格式说明:

  • format: "binary":二进制格式(.srs),解析快、体积小(推荐)
  • format: "source":源码格式(JSON),体积大但可读
  • download_detour:下载规则集走哪个出站(必须走代理,因为 GitHub 在国内被墙)

官方规则集仓库:

5.4 logical 逻辑组合规则#

sing-box 支持逻辑组合规则(Clash 没有),可以组合多个条件:

{
"type": "logical",
"mode": "and",
"rules": [
{ "port": [80, 443] },
{ "network": "tcp" },
{ "process_name": ["chrome", "firefox"] }
],
"outbound": "proxy-out"
}
  • mode: "and":所有条件都满足才匹配
  • mode: "or":任一条件满足就匹配

6. experimental 实验功能#

6.1 Clash API(兼容 Clash 控制面板)#

sing-box 可以开启 Clash API,让你用 Clash 的 Web UI(如 Metacubexd/Yacd)管理 sing-box:

{
"experimental": {
"clash_api": {
"external_controller": "127.0.0.1:9090",
"external_ui": "ui",
"external_ui_download_detour": "proxy-out",
"secret": "your-secret"
},
"cache_file": {
"enabled": true,
"path": "cache.db",
"store_fake_ip": true
}
}
}

参数说明:

  • external_controller:API 监听地址
  • external_ui:Web UI 目录路径
  • secret:API 访问密钥(安全)
  • cache_file:缓存文件,存储节点信息和 Fake IP

6.2 V2Ray API#

{
"experimental": {
"v2ray_api": {
"listen": "127.0.0.1:10085"
}
}
}

7. 完整配置模板#

把以上所有部分组合,得到完整配置模板:

{
"log": {
"level": "info",
"timestamp": true
},
"dns": {
"servers": [
{
"tag": "dns-direct",
"address": "223.5.5.5",
"detour": "direct-out"
},
{
"tag": "dns-remote",
"address": "tls://8.8.8.8",
"detour": "proxy-out"
},
{
"tag": "dns-block",
"address": "rcode://success"
}
],
"rules": [
{
"outbound": ["any"],
"server": "dns-direct"
},
{
"rule_set": ["geosite-cn"],
"server": "dns-direct"
},
{
"rule_set": ["geosite-category-ads-all"],
"server": "dns-block"
}
],
"final": "dns-remote",
"strategy": "prefer_ipv4",
"independent_cache": true
},
"inbounds": [
{
"type": "mixed",
"tag": "mixed-in",
"listen": "127.0.0.1",
"listen_port": 7890,
"sniff": true,
"sniff_override_destination": false
},
{
"type": "tun",
"tag": "tun-in",
"inet4_address": "172.19.0.1/30",
"auto_route": true,
"strict_route": true,
"stack": "mixed",
"sniff": true,
"sniff_override_destination": false
}
],
"outbounds": [
{
"type": "selector",
"tag": "proxy-out",
"outbounds": [
"auto-select",
"hy2-out",
"vless-out",
"vmess-out",
"trojan-out",
"ss-out",
"direct-out"
],
"default": "auto-select"
},
{
"type": "urltest",
"tag": "auto-select",
"outbounds": [
"hy2-out",
"vless-out",
"vmess-out",
"trojan-out",
"ss-out"
],
"url": "https://www.gstatic.com/generate_204",
"interval": "5m",
"tolerance": 50
},
{
"type": "hysteria2",
"tag": "hy2-out",
"server": "hy2.example.com",
"server_port": 443,
"password": "hy2-password",
"tls": {
"enabled": true,
"server_name": "hy2.example.com"
}
},
{
"type": "vless",
"tag": "vless-out",
"server": "vless.example.com",
"server_port": 443,
"uuid": "uuid-here",
"flow": "xtls-rprx-vision",
"tls": {
"enabled": true,
"server_name": "vless.example.com",
"utls": {
"enabled": true,
"fingerprint": "chrome"
}
}
},
{
"type": "vmess",
"tag": "vmess-out",
"server": "vmess.example.com",
"server_port": 443,
"uuid": "uuid-here",
"security": "auto",
"alter_id": 0,
"transport": {
"type": "ws",
"path": "/ws"
},
"tls": {
"enabled": true,
"server_name": "vmess.example.com"
}
},
{
"type": "trojan",
"tag": "trojan-out",
"server": "trojan.example.com",
"server_port": 443,
"password": "trojan-password",
"tls": {
"enabled": true,
"server_name": "trojan.example.com"
}
},
{
"type": "shadowsocks",
"tag": "ss-out",
"server": "ss.example.com",
"server_port": 8388,
"method": "aes-256-gcm",
"password": "ss-password"
},
{
"type": "direct",
"tag": "direct-out"
},
{
"type": "block",
"tag": "block-out"
},
{
"type": "dns",
"tag": "dns-out"
}
],
"route": {
"rule_set": [
{
"tag": "geosite-cn",
"type": "remote",
"format": "binary",
"url": "https://raw.githubusercontent.com/SagerNet/sing-geoosite/rule-set/geosite-cn.srs",
"download_detour": "proxy-out"
},
{
"tag": "geoip-cn",
"type": "remote",
"format": "binary",
"url": "https://raw.githubusercontent.com/SagerNet/sing-geoip/rule-set/geoip-cn.srs",
"download_detour": "proxy-out"
},
{
"tag": "geosite-category-ads-all",
"type": "remote",
"format": "binary",
"url": "https://raw.githubusercontent.com/SagerNet/sing-geoosite/rule-set/geosite-category-ads-all.srs",
"download_detour": "proxy-out"
},
{
"tag": "geosite-geolocation-!cn",
"type": "remote",
"format": "binary",
"url": "https://raw.githubusercontent.com/SagerNet/sing-geoosite/rule-set/geosite-geolocation-!cn.srs",
"download_detour": "proxy-out"
}
],
"rules": [
{
"protocol": "dns",
"outbound": "dns-out"
},
{
"ip_is_private": true,
"outbound": "direct-out"
},
{
"rule_set": ["geosite-category-ads-all"],
"outbound": "block-out"
},
{
"rule_set": ["geosite-cn", "geoip-cn"],
"outbound": "direct-out"
},
{
"rule_set": ["geosite-geolocation-!cn"],
"outbound": "proxy-out"
}
],
"final": "proxy-out",
"auto_detect_interface": true
},
"experimental": {
"clash_api": {
"external_controller": "127.0.0.1:9090",
"external_ui": "ui",
"secret": "singbox-secret"
},
"cache_file": {
"enabled": true,
"path": "cache.db",
"store_fake_ip": true
}
}
}

使用方法: 复制上面的模板,替换 serverserver_portuuidpassword 等字段为你的机场节点信息,保存为 config.json 即可使用。


8. 全平台安装与使用#

8.1 Windows#

方法一:命令行版(sing-box 核心)#

Terminal window
# 下载最新版
# 从 https://github.com/SagerNet/sing-box/releases 下载 Windows amd64 版本
# 解压后运行
sing-box run -c config.json -D .

需要管理员权限才能使用 TUN 模式。

方法二:Hiddify(推荐,图形界面)#

Hiddify 是基于 sing-box 的图形客户端,提供美观的 UI:

  1. 访问 Hiddify 官网 下载 Windows 版
  2. 安装后导入机场订阅链接
  3. 选择节点,开启代理

方法三:Clash Verge Rev + sing-box 内核#

Clash Verge Rev 支持切换 sing-box 内核:

  1. 安装 Clash Verge Rev
  2. 在设置中切换内核为 sing-box
  3. 导入 sing-box 格式订阅或手动配置

8.2 macOS#

方法一:命令行版#

Terminal window
# 下载 macOS 版本(Intel: amd64, Apple Silicon: arm64)
# 从 https://github.com/SagerNet/sing-box/releases 下载
# 使用 sudo 运行(TUN 模式需要)
sudo sing-box run -c config.json -D .

方法二:Hiddify(推荐)#

  1. Hiddify 官网 下载 macOS 版
  2. 支持 Intel 和 Apple Silicon
  3. 导入订阅,一键使用

8.3 iOS#

iOS 上使用 SFI(Sing Box for iOS):

  1. SFI 目前需要通过 TestFlight 安装(免费)
  2. 安装步骤:
    • 在 App Store 搜索 “SFI” 或访问 SFI TestFlight 链接
    • 安装 SFI
    • 打开 SFI,点击「添加配置」
    • 选择「从 URL 导入」粘贴机场 sing-box 订阅链接
    • 或手动编辑 JSON 配置
    • 选择节点,开启代理

注意: SFI 也支持从剪贴板导入配置,直接复制 JSON 内容即可。

8.4 Android#

Android 使用 SFA(Sing Box for Android):

  1. SFA GitHub Releases 下载 APK
  2. 或从 Google Play 搜索 “SFA” 安装
  3. 安装后导入机场订阅链接
  4. 选择节点,开启代理

8.5 Linux#

Terminal window
# 下载对应架构版本
# 从 https://github.com/SagerNet/sing-box/releases 下载
# TUN 模式需要 root 或 cap_net_admin 权限
sudo setcap cap_net_admin+ep sing-box
sing-box run -c config.json -D .
# 或直接用 sudo
sudo sing-box run -c config.json -D .

9. 机场订阅导入指南#

9.1 机场 sing-box 订阅格式#

越来越多机场支持 sing-box 专属订阅格式。导入方式:

图形客户端导入#

在 SFI/SFA/Hiddify 中:

  1. 点击「添加配置 / Add Configuration」
  2. 选择「从 URL 导入 / Import from URL」
  3. 粘贴机场提供的 sing-box 订阅链接
  4. 自动解析节点,生成完整配置

命令行导入#

机场订阅通常返回完整 JSON 配置,直接保存为 config.json

Terminal window
# 下载订阅配置
curl -o config.json "https://your-airport.com/api/v1/client/singbox?token=your-token"
# 运行
sing-box run -c config.json -D .

9.2 Clash 订阅转 sing-box 格式#

如果机场只提供 Clash 订阅,可以用转换工具:

方法一:在线转换

使用 subconverter 等工具:

https://subconverter-url/sub?target=singbox&url=clash-subscription-url

方法二:手动转换关键字段

Clash YAML → sing-box JSON 的关键映射:

Clash YAMLsing-box JSON
proxies:outbounds:
proxy-groups:selector/urltest outbound
rules:route.rules:
rule-providers:route.rule_set:
dns:dns:

9.3 多节点订阅 + 自定义规则#

你可以同时使用机场订阅节点 + 自定义分流规则:

{
"outbounds": [
// 机场订阅节点(由客户端自动生成)
// ... 节点列表 ...
// 自定义分组
{
"type": "selector",
"tag": "proxy-out",
"outbounds": ["auto-select", "节点A", "节点B"],
"default": "auto-select"
},
{
"type": "urltest",
"tag": "auto-select",
"outbounds": ["节点A", "节点B", "节点C"],
"url": "https://www.gstatic.com/generate_204",
"interval": "5m"
},
{ "type": "direct", "tag": "direct-out" },
{ "type": "block", "tag": "block-out" }
],
"route": {
// 自定义分流规则
"rule_set": [...],
"rules": [...],
"final": "proxy-out"
}
}

10. 高级技巧#

10.1 链式代理(流量中转)#

sing-box 支持 outbound 链式组合,流量依次经过多个节点:

{
"type": "vless",
"tag": "vless-chain",
"server": "中转服务器IP",
"server_port": 443,
"uuid": "uuid",
"detour": "trojan-out",
// 先走 trojan 到中转服务器,再通过中转服务器连接 vless 目标
}

detour 指定前一个出站——流量先走 trojan-out,再走当前 vless-chain,实现链式中转。

10.2 UDP over TCP#

某些网络环境 UDP 不稳定(如部分运营商),sing-box 可以将 UDP 封装为 TCP:

{
"type": "shadowsocks",
"tag": "ss-udp-over-tcp",
"server": "your-server.com",
"server_port": 8388,
"method": "aes-256-gcm",
"password": "your-password",
"udp_over_tcp": {
"enabled": true
}
}

10.3 多用户 / 分流管理#

通过 selector 出站实现精细分流:

{
"outbounds": [
{
"type": "selector",
"tag": "streaming-out",
"outbounds": ["hy2-us", "vmess-jp"],
"default": "hy2-us"
},
{
"type": "selector",
"tag": "chat-out",
"outbounds": ["vless-sg", "trojan-hk"],
"default": "vless-sg"
},
{
"type": "selector",
"tag": "proxy-out",
"outbounds": ["streaming-out", "chat-out", "auto-select", "direct-out"],
"default": "auto-select"
}
]
}

路由规则中按用途分流:

{
"route": {
"rules": [
{
"domain_suffix": [".netflix.com", ".youtube.com"],
"outbound": "streaming-out"
},
{
"domain_suffix": [".telegram.org", ".discord.com"],
"outbound": "chat-out"
}
]
}
}

10.4 Fake IP 模式#

Fake IP 可以加速 DNS 解析,避免被污染:

{
"dns": {
"independent_cache": true,
"fake_ip": {
"enabled": true,
"ip_range": "198.18.0.0/15"
}
},
"experimental": {
"cache_file": {
"enabled": true,
"store_fake_ip": true
}
}
}

工作原理:DNS 查询返回一个 Fake IP(198.18.x.x),应用连接到 Fake IP,sing-box 在路由层拦截后用真实域名去远程 DNS 解析,得到真实 IP 后再转发。

10.5 自动更新订阅#

在图形客户端中通常有自动更新功能。命令行版可以通过脚本实现:

#!/bin/bash
# sing-box 订阅更新脚本
SINGBOX_DIR="/etc/sing-box"
CONFIG_FILE="$SINGBOX_DIR/config.json"
SUB_URL="https://your-airport.com/api/v1/client/singbox?token=your-token"
# 下载最新配置
curl -s -o "$CONFIG_FILE" "$SUB_URL"
# 重启 sing-box
systemctl restart sing-box

配合 systemd 定时器实现自动更新:

/etc/systemd/system/sing-box-update.timer
[Unit]
Description=Update sing-box subscription
[Timer]
OnCalendar=*-*-* 04:00:00
Persistent=true
[Install]
WantedBy=timers.target

11. 常见问题与排错#

11.1 TUN 模式启动失败#

症状: tun: creating tun stack: operation not permitted

解决:

  • Windows:以管理员身份运行
  • macOS:sudo sing-box run ...
  • Linux:sudo setcap cap_net_admin+ep sing-box 或直接 sudo

11.2 规则集下载失败#

症状: rule_set: download failed: connection refused

解决:

  • 确保 download_detour 设置为 proxy-out(通过代理下载)
  • 检查代理节点是否可用
  • 如果 GitHub 被墙,改用镜像 URL

11.3 DNS 解析异常#

症状: 国内网站解析到海外 IP

解决:

  • 确保 DNS 规则正确:国内域名用国内 DNS,海外域名用海外 DNS
  • 检查 independent_cache: true 是否设置
  • 如果用了 Fake IP,确保 store_fake_ip: true

11.4 端口冲突#

症状: listen: address already in use

解决:

  • 检查其他代理工具是否占用相同端口(7890/9090)
  • 关闭其他代理工具或修改端口

11.5 JSON 配置格式错误#

症状: parse config: invalid json

解决:

  • 使用 JSON 格式检查工具验证
  • 注意 JSON 不支持注释(不能像 YAML 那样写注释)
  • 注意字符串必须用双引号,不能用单引号
  • 注意末尾不能有多余逗号

11.6 iOS SFI 无法连接#

解决:

  • 确保配置格式正确(SFI 对 JSON 格式要求严格)
  • 确保订阅链接返回的是 sing-box 格式(不是 Clash YAML)
  • 尝试从剪贴板导入手动编写的配置

11.7 Hysteria2 连接不稳定#

解决:

  • Hysteria2 基于 QUIC,某些运营商可能限制 UDP
  • 尝试启用 udp_over_tcp 将 UDP 转 TCP
  • 或切换到 VMess/VLESS 等基于 TCP 的协议

12. sing-box 与 Clash 全对比#

维度Clash / Clash Metasing-box
配置格式YAMLJSON
协议覆盖SS/VMess/VLESS/Trojan + 插件全协议原生(含 Hysteria2/ShadowTLS/TUIC)
DNS 分流基础分流DNS 规则独立配置 + 规则集
路由规则Rule Providerrule_set + logical 逻辑组合
链式代理relaydetour 链式组合
测速切换url-test/fallback/load-balanceurltest/selector
图形客户端Clash Verge Rev(成熟)Hiddify/SFI/SFA(快速发展)
Web UIYacd/Metacubexd兼容 Clash API,同用 Metacubexd
内存占用50-80 MB20-40 MB
社区规模大(历史积累)快速增长
维护状态Clash 原版停更,Meta 活跃活跃维护
上手难度低(大量教程)中偏低(本文帮你搞定)

13. 推荐配置方案#

13.1 新手推荐方案#

不想折腾配置?直接导入机场订阅!

  1. 选择支持 sing-box 订阅的机场(参考 机场推荐
  2. 安装图形客户端(Hiddify / SFI / SFA)
  3. 导入订阅链接,一键使用

13.2 进阶用户推荐方案#

想精细控制分流?用本文的配置模板!

  1. 复制第 7 节的完整配置模板
  2. 替换节点信息(server / port / uuid / password)
  3. 根据需要调整分流规则
  4. 保存为 config.json 运行

13.3 自建节点用户推荐方案#

有自己的 VPS?sing-box 是最佳客户端!

  1. 服务端部署 Hysteria2 / VLESS + XTLS Vision
  2. 客户端使用 sing-box 对应的 outbound 配置
  3. 配合 rule_set 规则集实现精细分流

14. 总结#

sing-box 正在成为 2026 年代理工具的新标准:

  • 多协议原生支持——不再需要 Clash 的各种插件补丁
  • 灵活路由规则——rule_set + logical 组合,比 Clash 更强大
  • 独立 DNS 分流——国内域名国内解析,海外域名海外解析
  • 低资源占用——Go 语言优势,内存占用仅为 Clash 的一半
  • 全平台覆盖——Windows/macOS/iOS/Android/Linux 全有客户端

如果你还在用 Clash,建议先在手机(SFI/SFA)上试一下 sing-box,体验 Hysteria2 的速度提升。习惯了再在电脑上切换。

推荐阅读:

sing-box 全平台使用教程:新一代通用代理平台配置指南 | 2026 最新
https://971918.xyz/posts/proxy-tools/sing-box-tutorial/
作者
九所长
发布于
2026-06-29
许可协议
CC BY-NC-SA 4.0