22 KiB
title, description, date, categories, tags
| title | description | date | categories | tags | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 分享 ShellCrash 搭载 sing-boxr 内核采用 ruleset 方案的一套配置 | 此配置搭载 sing-boxr 内核,采用 <code>rule_set</code> 规则搭配 .srs 规则集文件 | 2024-08-22 19:45:26 +0800 |
|
|
声明 {: .prompt-warning }
- 请根据自身情况进行修改,适合自己的方案才是最好的方案,如无特殊需求,可以照搬
- 此方案适用于 ShellCrash(以 ARM64 架构为例,且安装路径为
/data/ShellCrash{: .filepath}) - 本方案绕过了 CNIP 且 IP 在国内的未知域名也会被绕过
- 本方案不搭配 AdGuard Home,在 DNS 层拦截广告
- 本人将路由器设置了每天早上 6 点重启,使得《六》中设置的定时任务生效
- 本教程搭载 sing-box 内核 reF1nd-Testing 版
一、 生成配置文件 .json 文件直链
具体方法此处不再赘述,请看《生成带有自定义出站和规则的 sing-boxr 配置文件直链-ruleset 方案》,贴一下我使用的配置:
{
"providers": [
{
"tag": "🛫 机场订阅",
"type": "remote",
// 修改为你的 Clash 订阅链接
"url": "https://example.com/xxx/xxx&flag=clash",
"path": "./providers/airport.yaml",
// 若出现获取不了机场节点的情况,可删除此配置项
"user_agent": "clash.meta",
"include": "(?i)(🇭🇰|港|hk|hongkong|hong kong|🇹🇼|台|tw|taiwan|tai wan|🇯🇵|日|jp|japan|🇸🇬|新|sg|singapore|🇺🇸|美|us|unitedstates|united states)",
"health_check": {
"enabled": true,
"url": "https://www.gstatic.com/generate_204"
}
},
{
"tag": "🆓 免费订阅",
"type": "remote",
// 修改为你的 sing-box 订阅链接
"url": "https://example.com/xxx/xxx",
"path": "./providers/free.json",
"update_interval": "12h",
"health_check": {
"enabled": true,
"url": "https://www.gstatic.com/generate_204"
}
}
],
"outbounds": [
{ "tag": "节点选择", "type": "selector", "outbounds": [ "香港节点", "台湾节点", "日本节点", "新加坡节点", "美国节点", "免费节点", "🆚 vless 节点" ] },
{ "tag": "网络测试", "type": "selector", "outbounds": [ "节点选择", "香港节点", "台湾节点", "日本节点", "新加坡节点", "美国节点", "免费节点", "🆚 vless 节点" ] },
{ "tag": "游戏平台", "type": "selector", "outbounds": [ "节点选择", "香港节点", "台湾节点", "日本节点", "新加坡节点", "美国节点", "🆚 vless 节点" ] },
{ "tag": "AI 平台", "type": "selector", "outbounds": [ "节点选择", "香港节点", "台湾节点", "日本节点", "新加坡节点", "美国节点", "🆚 vless 节点" ] },
{ "tag": "游戏服务", "type": "selector", "outbounds": [ "全球直连", "节点选择" ] },
{ "tag": "微软服务", "type": "selector", "outbounds": [ "全球直连", "节点选择" ] },
{ "tag": "谷歌服务", "type": "selector", "outbounds": [ "全球直连", "节点选择" ] },
{ "tag": "苹果服务", "type": "selector", "outbounds": [ "全球直连", "节点选择" ] },
{ "tag": "国外域名", "type": "selector", "outbounds": [ "节点选择", "香港节点", "台湾节点", "日本节点", "新加坡节点", "美国节点", "免费节点", "🆚 vless 节点" ] },
{ "tag": "电报消息", "type": "selector", "outbounds": [ "节点选择", "香港节点", "台湾节点", "日本节点", "新加坡节点", "美国节点", "免费节点", "🆚 vless 节点" ] },
{ "tag": "私有网络", "type": "selector", "outbounds": [ "全球直连" ] },
{ "tag": "漏网之鱼", "type": "selector", "outbounds": [ "节点选择", "香港节点", "台湾节点", "日本节点", "新加坡节点", "美国节点", "免费节点", "🆚 vless 节点", "全球直连" ] },
{ "tag": "全球直连", "type": "selector", "outbounds": [ "DIRECT" ] },
{ "tag": "DIRECT", "type": "direct" },
{ "tag": "GLOBAL", "type": "selector", "outbounds": [ "节点选择", "DIRECT" ] },
// 若没有单个出站节点,须删除所有 `🆚 vless 节点` 相关内容
{
"tag": "🆚 vless 节点",
"type": "vless",
"server": "example.com",
"server_port": 443,
"uuid": "{uuid}",
"network": "tcp",
"tls": { "enabled": true, "server_name": "example.com", "insecure": false },
"transport": { "type": "ws", "path": "/?ed=2048", "headers": { "Host": "example.com" } }
},
{ "tag": "香港节点", "type": "urltest", "providers": [ "🛫 机场订阅" ], "include": "(?i)(🇭🇰|港|hk|hongkong|hong kong)" },
{ "tag": "台湾节点", "type": "urltest", "providers": [ "🛫 机场订阅" ], "include": "(?i)(🇹🇼|台|tw|taiwan|tai wan)" },
{ "tag": "日本节点", "type": "urltest", "providers": [ "🛫 机场订阅" ], "include": "(?i)(🇯🇵|日|jp|japan)" },
{ "tag": "新加坡节点", "type": "urltest", "providers": [ "🛫 机场订阅" ], "include": "(?i)(🇸🇬|新|sg|singapore)" },
{ "tag": "美国节点", "type": "urltest", "tolerance": 100, "providers": [ "🛫 机场订阅" ], "include": "(?i)(🇺🇸|美|us|unitedstates|united states)" },
{ "tag": "免费节点", "type": "urltest", "tolerance": 100, "providers": [ "🆓 免费订阅" ] }
],
"route": {
"rules": [
{ "rule_set": [ "private" ], "outbound": "私有网络" },
{ "rule_set": [ "microsoft-cn" ], "outbound": "微软服务" },
{ "rule_set": [ "apple-cn" ], "outbound": "苹果服务" },
{ "rule_set": [ "google-cn" ], "outbound": "谷歌服务" },
{ "rule_set": [ "games-cn" ], "outbound": "游戏服务" },
{ "rule_set": [ "games" ], "outbound": "游戏平台" },
{ "rule_set": [ "ai" ], "outbound": "AI 平台" },
{ "rule_set": [ "networktest" ], "outbound": "网络测试" },
{ "rule_set": [ "proxy" ], "outbound": "国外域名" },
{ "ip_is_private": true, "outbound": "私有网络" },
{ "rule_set": [ "cnip" ], "outbound": "全球直连" },
{ "rule_set": [ "telegramip" ], "outbound": "电报消息" }
],
"rule_set": [
{
"tag": "ads",
"type": "remote",
"format": "binary",
"path": "./ruleset/ads.srs",
"url": "https://github.com/DustinWin/ruleset_geodata/releases/download/sing-box-ruleset/ads.srs"
},
{
"tag": "private",
"type": "remote",
"format": "binary",
"path": "./ruleset/private.srs",
"url": "https://github.com/DustinWin/ruleset_geodata/releases/download/sing-box-ruleset/private.srs"
},
{
"tag": "microsoft-cn",
"type": "remote",
"format": "binary",
"path": "./ruleset/microsoft-cn.srs",
"url": "https://github.com/DustinWin/ruleset_geodata/releases/download/sing-box-ruleset/microsoft-cn.srs"
},
{
"tag": "apple-cn",
"type": "remote",
"format": "binary",
"path": "./ruleset/apple-cn.srs",
"url": "https://github.com/DustinWin/ruleset_geodata/releases/download/sing-box-ruleset/apple-cn.srs"
},
{
"tag": "google-cn",
"type": "remote",
"format": "binary",
"path": "./ruleset/google-cn.srs",
"url": "https://github.com/DustinWin/ruleset_geodata/releases/download/sing-box-ruleset/google-cn.srs"
},
{
"tag": "games-cn",
"type": "remote",
"format": "binary",
"path": "./ruleset/games-cn.srs",
"url": "https://github.com/DustinWin/ruleset_geodata/releases/download/sing-box-ruleset/games-cn.srs"
},
{
"tag": "games",
"type": "remote",
"format": "binary",
"path": "./ruleset/games.srs",
"url": "https://github.com/DustinWin/ruleset_geodata/releases/download/sing-box-ruleset/games.srs"
},
{
"tag": "ai",
"type": "remote",
"format": "binary",
"path": "./ruleset/ai.srs",
"url": "https://github.com/DustinWin/ruleset_geodata/releases/download/sing-box-ruleset/ai.srs"
},
{
"tag": "networktest",
"type": "remote",
"format": "binary",
"path": "./ruleset/networktest.srs",
"url": "https://github.com/DustinWin/ruleset_geodata/releases/download/sing-box-ruleset/networktest.srs"
},
{
"tag": "proxy",
"type": "remote",
"format": "binary",
"path": "./ruleset/proxy.srs",
"url": "https://github.com/DustinWin/ruleset_geodata/releases/download/sing-box-ruleset/proxy.srs"
},
{
"tag": "cn",
"type": "remote",
"format": "binary",
"path": "./ruleset/cn.srs",
"url": "https://github.com/DustinWin/ruleset_geodata/releases/download/sing-box-ruleset/cn.srs"
},
{
"tag": "cnip",
"type": "remote",
"format": "binary",
"path": "./ruleset/cnip.srs",
"url": "https://github.com/DustinWin/ruleset_geodata/releases/download/sing-box-ruleset/cnip.srs"
},
{
"tag": "telegramip",
"type": "remote",
"format": "binary",
"path": "./ruleset/telegramip.srs",
"url": "https://github.com/DustinWin/ruleset_geodata/releases/download/sing-box-ruleset/telegramip.srs"
}
],
"final": "漏网之鱼"
}
}
outbounds私货 {: .prompt-tip }
注:
- ① 本
outbounds配置中,将不同的节点类型(如:Shadowsocks和Trojan)分别配置"type": "urltest"进行延迟测试(可进入 zashboard → 代理 → 设置 → 管理隐藏代理组,设置隐藏以简化 Dashboard 面板中的显示)。再将延迟测试最低的策略组配置"type": "loadbalance"进行负载均衡供用户选择使用 - ② 将不同的优选节点分别配置
"fallback": { "enabled": true }进行故障转移(可进入 zashboard → 代理 → 设置 → 管理隐藏代理组,设置隐藏以简化 Dashboard 面板中的显示)。再将故障转移后的策略组配置"type": "urltest"进行延迟测试供用户选择使用
{
"outbounds": [
{ "tag": "香港节点", "type": "loadbalance", "strategy": "consistent-hashing", "outbounds": [ "香港-ss", "香港-trojan" ] },
{ "tag": "香港-ss", "type": "urltest", "providers": [ "🛫 机场订阅" ], "include": "(?i)((🇭🇰|港|hk|hongkong|hong kong).*ss)" },
{ "tag": "香港-trojan", "type": "urltest", "providers": [ "🛫 机场订阅" ], "include": "(?i)(🇭🇰|港|hk|hongkong|hong kong)", "exclude": "(?i)(ss)" },
{ "tag": "台湾节点", "type": "loadbalance", "strategy": "consistent-hashing", "outbounds": [ "台湾-ss", "台湾-trojan" ] },
{ "tag": "台湾-ss", "type": "urltest", "providers": [ "🛫 机场订阅" ], "include": "(?i)((🇹🇼|台|tw|taiwan|tai wan).*ss)" },
{ "tag": "台湾-trojan", "type": "urltest", "providers": [ "🛫 机场订阅" ], "include": "(?i)(🇹🇼|台|tw|taiwan|tai wan)", "exclude": "(?i)(ss)" },
{ "tag": "日本节点", "type": "loadbalance", "strategy": "consistent-hashing", "outbounds": [ "日本-ss", "日本-trojan" ] },
{ "tag": "日本-ss", "type": "urltest", "providers": [ "🛫 机场订阅" ], "include": "(?i)((🇯🇵|日|jp|japan).*ss)" },
{ "tag": "日本-trojan", "type": "urltest", "providers": [ "🛫 机场订阅" ], "include": "(?i)(🇯🇵|日|jp|japan)", "exclude": "(?i)(ss)" },
{ "tag": "新加坡节点", "type": "loadbalance", "strategy": "consistent-hashing", "outbounds": [ "新加坡-ss", "新加坡-trojan" ] },
{ "tag": "新加坡-ss", "type": "urltest", "providers": [ "🛫 机场订阅" ], "include": "(?i)((🇸🇬|新|sg|singapore).*ss)" },
{ "tag": "新加坡-trojan", "type": "urltest", "providers": [ "🛫 机场订阅" ], "include": "(?i)(🇸🇬|新|sg|singapore)", "exclude": "(?i)(ss)" },
{ "tag": "美国节点", "type": "loadbalance", "strategy": "consistent-hashing", "outbounds": [ "美国-ss", "美国-trojan" ] },
{ "tag": "美国-ss", "type": "urltest", "tolerance": 100, "providers": [ "🛫 机场订阅" ], "include": "(?i)((🇺🇸|美|us|unitedstates|united states).*ss)" },
{ "tag": "美国-trojan", "type": "urltest", "tolerance": 100, "providers": [ "🛫 机场订阅" ], "include": "(?i)(🇺🇸|美|us|unitedstates|united states)", "exclude": "(?i)(ss)" },
{ "tag": "免费节点", "type": "urltest", "tolerance": 100, "outbounds": [ "移动优选节点", "CF 优选节点" ] },
{ "tag": "移动优选节点", "type": "urltest", "tolerance": 100, "providers": [ "🆓 免费订阅" ], "include": "(?i)(cmcc)", "fallback": { "enabled": true, "max_delay": "400ms" } },
{ "tag": "CF 优选节点", "type": "urltest", "tolerance": 100, "providers": [ "🆓 免费订阅" ], "include": "(?i)(cfip)", "fallback": { "enabled": true, "max_delay": "400ms" } }
]
}
二、 导入 sing-box reF1nd 版内核和 CN_IP 文件
连接 SSH 后执行如下命令:
curl -sS -o /tmp/CrashCore.upx -L https://ghfast.top/https://github.com/DustinWin/proxy-tools/releases/download/sing-box/sing-box-ref1nd-testing-linux-arm64.upx
curl -sS -o $CRASHDIR/cn_ip.txt -L https://cdn.jsdelivr.net/gh/DustinWin/geoip@ips/cn_ipv4.txt
curl -sS -o $CRASHDIR/cn_ipv6.txt -L https://cdn.jsdelivr.net/gh/DustinWin/geoip@ips/cn_ipv6.txt
sc
此时脚本会自动“发现可用的内核文件”,选择 1 加载,后选择 5 Sing-Box-reF1nd 内核
三、 编辑 dns.json 文件
连接 SSH 后执行命令 vi $CRASHDIR/jsons/dns.json,按一下 Ins 键(Insert 键),粘贴如下内容:
- 注:推荐将
client_subnet设置为当前宽带运营商分配的默认 DNS(可进入光猫或路由器拨号页面查看,或者前往公共 DNS 大全查询)的 IP 段,如默认 DNS 为211.137.58.20,可设置为211.137.58.0/24
{
"dns": {
"servers": [
{
"tag": "hosts",
"type": "hosts",
"predefined": {
"dns.alidns.com": [ "223.5.5.5", "223.6.6.6", "2400:3200::1", "2400:3200:baba::1" ],
"doh.pub": [ "1.12.12.12", "120.53.53.53" ],
"dns.google": [ "8.8.8.8", "8.8.4.4", "2001:4860:4860::8888", "2001:4860:4860::8844" ],
"cloudflare-dns.com": [ "1.1.1.1", "1.0.0.1", "2606:4700:4700::1111", "2606:4700:4700::1001" ]
}
},
{ "tag": "dns_resolver", "type": "local" },
{ "tag": "dns_alidns", "type": "quic", "server": "dns.alidns.com", "domain_resolver": "hosts" },
{ "tag": "dns_dnspod", "type": "https", "server": "doh.pub", "domain_resolver": "hosts" },
{ "tag": "dns_google", "type": "https", "server": "dns.google", "domain_resolver": "hosts", "detour": "GLOBAL" },
{ "tag": "dns_cloudflare", "type": "https", "server": "cloudflare-dns.com", "domain_resolver": "hosts", "detour": "GLOBAL" },
{ "tag": "dns_direct", "type": "group", "servers": [ "dns_alidns", "dns_dnspod" ] },
{ "tag": "dns_proxy", "type": "group", "servers": [ "dns_google", "dns_cloudflare" ] },
{ "tag": "dns_fakeip", "type": "fakeip", "inet4_range": "198.18.0.0/15", "inet6_range": "fc00::/16" }
],
"rules": [
{ "clash_mode": [ "Direct" ], "server": "dns_direct" },
{ "clash_mode": [ "Global" ], "server": "dns_proxy" },
{ "rule_set": [ "private" ], "server": "dns_resolver" },
{ "rule_set": [ "ads" ], "action": "predefined" },
{ "rule_set": [ "microsoft-cn", "apple-cn", "google-cn", "games-cn" ], "server": "dns_direct" },
{ "rule_set": [ "games", "ai", "proxy" ], "query_type": [ "A", "AAAA" ], "server": "dns_fakeip" },
{ "rule_set": [ "cn" ], "server": "dns_direct" },
{ "action": "evaluate", "server": "dns_direct" },
{ "match_response": true, "rule_set": [ "cnip" ], "action": "respond" }
],
"final": "dns_direct",
"strategy": "prefer_ipv4",
"optimistic": true,
"reverse_mapping": true,
"cache_client_subnet": true
}
}
按一下 Esc 键(退出键),输入英文冒号 :,继续输入 wq 并回车
DNS私货 {: .prompt-tip }
注:
- ① 本
dns配置中,国内域名走国内 DNS 解析,国外域名走fakeip,未知域名也走fakeip,在匹配rule_set:cnip规则时会先由国外 DNS 解析且配置client_subnet提高了兼容性,解析出 IP 在国内则走国内 IP规则,否则走漏网之鱼规则(有效解决了“心理 DNS 泄露问题”,详见《搭载 sing-boxr 内核配置 DNS 不泄露教程-ruleset 方案》) - ② 推荐将
client_subnet设置为当前宽带运营商分配的默认 DNS(可进入光猫或路由器拨号页面查看,或者前往公共 DNS 大全查询)的 IP 段,如默认 DNS 为211.137.58.20,可设置为211.137.58.0/24
{
"dns": {
"servers": [
{
"tag": "hosts",
"type": "hosts",
"predefined": {
"dns.alidns.com": [ "223.5.5.5", "223.6.6.6", "2400:3200::1", "2400:3200:baba::1" ],
"doh.pub": [ "1.12.12.12", "120.53.53.53" ],
"dns.google": [ "8.8.8.8", "8.8.4.4", "2001:4860:4860::8888", "2001:4860:4860::8844" ],
"dns11.quad9.net": [ "9.9.9.11", "149.112.112.11", "2620:fe::11", "2620:fe::fe:11" ]
}
},
{ "tag": "dns_resolver", "type": "local" },
{ "tag": "dns_alidns", "type": "quic", "server": "dns.alidns.com", "domain_resolver": "hosts" },
{ "tag": "dns_dnspod", "type": "https", "server": "doh.pub", "domain_resolver": "hosts" },
{ "tag": "dns_google", "type": "https", "server": "dns.google", "domain_resolver": "hosts", "detour": "GLOBAL" },
{ "tag": "dns_quad9", "type": "quic", "server": "dns11.quad9.net", "domain_resolver": "hosts", "detour": "GLOBAL" },
{ "tag": "dns_direct", "type": "group", "servers": [ "dns_alidns", "dns_dnspod" ] },
{ "tag": "dns_proxy", "type": "group", "servers": [ "dns_google", "dns_quad9" ] },
{ "tag": "dns_fakeip", "type": "fakeip", "inet4_range": "198.18.0.0/15", "inet6_range": "fc00::/16" }
],
"rules": [
{ "clash_mode": [ "Direct" ], "server": "dns_direct" },
{ "clash_mode": [ "Global" ], "server": "dns_proxy" },
{ "rule_set": [ "private" ], "server": "dns_resolver" },
{ "rule_set": [ "ads" ], "action": "predefined" },
{ "rule_set": [ "microsoft-cn", "apple-cn", "google-cn", "games-cn" ], "server": "dns_direct" },
{ "rule_set": [ "games", "ai", "proxy" ], "query_type": [ "A", "AAAA" ], "server": "dns_fakeip" },
{ "rule_set": [ "cn" ], "server": "dns_direct" },
// 推荐将 `client_subnet` 设置为当前宽带运营商分配的默认 DNS 的 IP 段
{ "action": "evaluate", "server": "dns_proxy", "client_subnet": "211.137.58.0/24" },
{ "match_response": true, "rule_set": [ "cnip" ], "action": "respond" }
],
"final": "dns_proxy",
"strategy": "prefer_ipv4",
"optimistic": true,
"reverse_mapping": true,
"cache_client_subnet": true
}
}
四、 编辑 services.json 文件
连接 SSH 后执行命令 vi $CRASHDIR/jsons/services.json,按一下 Ins 键(Insert 键),粘贴如下内容:
{
"services": [
{
"type": "api",
"listen": "::",
"listen_port": 9999,
"secret": "",
"access_control_allow_private_network": true
}
]
}
按一下 Esc 键(退出键),输入英文冒号 :,继续输入 wq 并回车
五、 编辑 experimental.json 文件
连接 SSH 后执行命令 vi $CRASHDIR/jsons/experimental.json,按一下 Ins 键(Insert 键),粘贴如下内容:
{
"experimental": {
"cache_file": {
"enabled": true,
"store_fakeip": true
},
"clash_api": {
"external_controller": "0.0.0.0:9090",
"secret": "",
"access_control_allow_private_network": true
},
"urltest_unified_delay": true
}
}
按一下 Esc 键(退出键),输入英文冒号 :,继续输入 wq 并回车
六、 添加定时任务
可参考《ShellCrash 搭载 sing-boxr 内核的配置-ruleset 方案/添加定时任务》
七、 设置部分
-
设置可参考《ShellCrash 搭载 sing-boxr 内核的配置-ruleset 方案/设置部分》,此处只列举配置的不同之处
-
进入 ShellCrash 配置脚本 → 2) 功能设置 → 2) DNS 设置 → 9) 修改 DNS 服务器,设置如下:

-
进入 2) 功能设置 → 6) 自定义端口及密钥 → 5) 修改面板访问端口,修改为
9090
八、 访问 Dashboard 面板
- 打开 zashboard 在线面板地址 http://board.zash.run.place 后,可直接在“Clash API”标签里将“主机”修改为
192.168.31.1,点击“提交”即可访问 Dashboard - 进入设置 → 后端设置,点击“+”图标,切换到“sing-box API”标签,将“主机”和“端口分别修改为
192.168.31.1和9999并点击“提交” - 通过切换后端配置可以分别使用 Clash API(支持“代理提供商”和“规则提供商”的更新)和 sing-box API Dashboard 面板
推荐设置 {: .prompt-tip }
- 进入 zashboard → 代理 → 代理设置 → 管理隐藏代理组,隐藏不必要显示的代理组
- 进入 zashboard → 设置 → 代理设置 → 外观 → 自定义图标,设置“组名”和“URL”,“URL”可参考 icon 文件
- 进入 zashboard → 设置 → 后端设置 → 修改后端配置,可设置“标签 (可选)”来快速识别不同设备