Sync all projects

This commit is contained in:
github-actions[bot]
2026-06-29 03:41:14 +00:00
parent 529cd7c625
commit 8b025e0766
11717 changed files with 6370622 additions and 0 deletions
+1
View File
@@ -0,0 +1 @@
@@ -0,0 +1,71 @@
---
title: 搭载 mihomo 内核进行 DNS 分流教程-geodata 方案
description: 此教程搭载 mihomo 内核并使用其特性进行 DNS 分流,即指定国内域名 <code>geosite:cn</code> 走国内 DNS 解析,其它域名包括国外域名都走 <code>fake-ip</code>
date: 2024-08-21 08:48:20 +0800
categories: [DNS 配置, DNS 分流]
tags: [Clash, mihomo, 进阶, DNS, DNS 分流]
---
> 说明
{: .prompt-tip }
1. 使用 [ShellCrash](https://github.com/juewuy/ShellCrash) 搭配 [AdGuard Home](https://github.com/AdguardTeam/AdGuardHome) 并将 AdGuard Home 作为上游时不要使用该方法
2. 本教程以 ShellCrash 为例,其它客户端亦可参考
3. 本教程搭载 [mihomo 内核 Meta 版](https://github.com/MetaCubeX/mihomo/tree/Meta)(导入内核方法可参考《[ShellCrash 和 AdGuard Home 快速安装教程/导入 mihomo 内核 或 sing-box 内核](https://proxy-tutorials.dustinwin.us.kg/posts/pin-toolsinstall/#%E4%BA%8C-%E5%AF%BC%E5%85%A5-mihomo-%E5%86%85%E6%A0%B8-%E6%88%96-sing-box-%E5%86%85%E6%A0%B8)》)
4. DNS 分流简单来说就是**指定国内域名走国内 DNS 解析,国外域名走 `fake-ip`**。未知域名走 `fake-ip`(在匹配 `GEOIP:cn` 规则时会由国内 DNS 解析,解析出 IP 在国内则走 `国内 IP` 规则,否则走 `漏网之鱼` 规则)
5. 部分用户觉得未知域名处理方式会导致 DNS 泄露,可参考《[搭载 mihomo 内核配置 DNS 不泄露教程-geodata 方案](https://proxy-tutorials.dustinwin.us.kg/posts/dnsnoleaks-mihomo-geodata)》
## 一、 导入路由规则文件
geosite.dat 文件须包含 `fakeip-filter``cn``proxy`,推荐导入我定制的[路由规则文件](https://github.com/DustinWin/ruleset_geodata?tab=readme-ov-file#%E4%B8%80-geodata-%E6%96%87%E4%BB%B6%E8%AF%B4%E6%98%8E)
## 二、 DNS 分流配置
1. 进入 ShellCrash 配置脚本 → 2) 功能设置 → 2) DNS 设置 → 9) 修改 DNS 服务器,将“DIRECT-DNS”、“PROXY-DNS”和“DEFAULT-DNS”都设置为 `null`
<img src="/assets/img/dns/dns-null.png" alt="ShellCrash DNS 进阶设置" width="60%" />
2. 连接 SSH 后执行命令 `vi $CRASHDIR/yamls/user.yaml`,按一下 Ins 键(Insert 键),粘贴如下内容:
```yaml
hosts:
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:
enable: true
prefer-h3: true
ipv6: true
listen: 0.0.0.0:1053
enhanced-mode: fake-ip
fake-ip-range: 28.0.0.0/8
fake-ip-range6: fc00::/16
fake-ip-filter: [geosite:fakeip-filter,cn]
nameserver:
- quic://dns.alidns.com:853
- https://dns.pub/dns-query
```
或者
```yaml
hosts:
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:
enable: true
prefer-h3: true
ipv6: true
listen: 0.0.0.0:1053
enhanced-mode: fake-ip
fake-ip-range: 28.0.0.0/8
fake-ip-range6: fc00::/16
fake-ip-filter-mode: rule
fake-ip-filter:
- GEOSITE,fakeip-filter,real-ip
- GEOSITE,proxy,fake-ip
- GEOSITE,cn,real-ip
- MATCH,fake-ip
nameserver:
- quic://dns.alidns.com:853
- https://dns.pub/dns-query
```
按一下 Esc 键(退出键),输入英文冒号 `:`,继续输入 `wq` 并回车
@@ -0,0 +1,98 @@
---
title: 搭载 mihomo 内核进行 DNS 分流教程-ruleset 方案
description: 此教程搭载 mihomo 内核并使用其特性进行 DNS 分流,即指定国内域名 <code>rule-set:cn</code> 走国内 DNS 解析,其它域名包括国外域名都走 <code>fake-ip</code>
date: 2024-08-21 07:52:58 +0800
categories: [DNS 配置, DNS 分流]
tags: [Clash, mihomo, 进阶, DNS, DNS 分流]
---
> 说明
{: .prompt-tip }
1. 使用 [ShellCrash](https://github.com/juewuy/ShellCrash) 搭配 [AdGuard Home](https://github.com/AdguardTeam/AdGuardHome) 并将 AdGuard Home 作为上游时不要使用该方法
2. 本教程以 ShellCrash 为例,其它客户端亦可参考
3. 本教程搭载 [mihomo 内核 Meta 版](https://github.com/MetaCubeX/mihomo/tree/Meta)(导入内核方法可参考《[ShellCrash 和 AdGuard Home 快速安装教程/导入 mihomo 内核 或 sing-box 内核](https://proxy-tutorials.dustinwin.us.kg/posts/pin-toolsinstall/#%E4%BA%8C-%E5%AF%BC%E5%85%A5-mihomo-%E5%86%85%E6%A0%B8-%E6%88%96-sing-box-%E5%86%85%E6%A0%B8)》)
4. DNS 分流简单来说就是**指定国内域名走国内 DNS 解析,国外域名走 `fake-ip`**。未知域名走 `fake-ip`(在匹配 `RULE-SET:cnip` 规则时会由国内 DNS 解析,解析出 IP 在国内则走 `国内 IP` 规则,否则走 `漏网之鱼` 规则)
5. 部分用户觉得未知域名处理方式会导致 DNS 泄露,可参考《[搭载 mihomo 内核配置 DNS 不泄露教程-ruleset 方案](https://proxy-tutorials.dustinwin.us.kg/posts/dnsnoleaks-mihomo-ruleset)》
## 一、 导入规则集合文件
`rule-providers` 须添加 `fakeip-filter``cn``proxy`,如下:
```yaml
rule-providers:
fakeip-filter:
type: http
behavior: domain
format: mrs
path: ./ruleset/fakeip-filter.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/fakeip-filter.mrs"
interval: 86400
cn:
type: http
behavior: domain
format: mrs
path: ./ruleset/cn.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/cn.mrs"
interval: 86400
proxy:
type: http
behavior: domain
format: mrs
path: ./ruleset/proxy.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/proxy.mrs"
interval: 86400
```
## 二、 DNS 分流配置
1. 进入 ShellCrash 配置脚本 → 2) 功能设置 → 2) DNS 设置 → 9) 修改 DNS 服务器,将“DIRECT-DNS”、“PROXY-DNS”和“DEFAULT-DNS”都设置为 `null`
<img src="/assets/img/dns/dns-null.png" alt="ShellCrash DNS 进阶设置" width="60%" />
2. 连接 SSH 后执行命令 `vi $CRASHDIR/yamls/user.yaml`,按一下 Ins 键(Insert 键),粘贴如下内容:
```yaml
hosts:
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:
enable: true
prefer-h3: true
ipv6: true
listen: 0.0.0.0:1053
enhanced-mode: fake-ip
fake-ip-range: 28.0.0.0/8
fake-ip-range6: fc00::/16
fake-ip-filter: [rule-set:fakeip-filter,cn]
nameserver:
- quic://dns.alidns.com:853
- https://dns.pub/dns-query
```
或者
```yaml
hosts:
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:
enable: true
prefer-h3: true
ipv6: true
listen: 0.0.0.0:1053
enhanced-mode: fake-ip
fake-ip-range: 28.0.0.0/8
fake-ip-range6: fc00::/16
fake-ip-filter-mode: rule
fake-ip-filter:
- RULE-SET,fakeip-filter,real-ip
- RULE-SET,proxy,fake-ip
- RULE-SET,cn,real-ip
- MATCH,fake-ip
nameserver:
- quic://dns.alidns.com:853
- https://dns.pub/dns-query
```
按一下 Esc 键(退出键),输入英文冒号 `:`,继续输入 `wq` 并回车
@@ -0,0 +1,138 @@
---
title: 搭载 mihomo 内核配置 DNS 不泄露教程-geodata 方案
description: 此教程搭载 mihomo 内核并使用其特性防止 DNS 泄露,即针对未知域名走国外 DNS 解析
date: 2024-08-21 08:18:30 +0800
categories: [DNS 配置, DNS 防泄漏]
tags: [Clash, mihomo, 进阶, DNS, DNS 泄露]
---
> 说明
{: .prompt-tip }
1. 此方案彻底防止了 DNS 泄露(未知域名在匹配 `GEOIP:cn` 规则时会由国外 DNS 解析且配置 `ecs`,解析出 IP 在国内则走 `国内 IP` 规则,否则走 `漏网之鱼` 规则),兼容性高,可放心使用
2. 本教程以 [ShellCrash](https://github.com/juewuy/ShellCrash) 为例,其它客户端亦可参考
3. 本教程搭载 [mihomo 内核 Meta 版](https://github.com/MetaCubeX/mihomo/tree/Meta)(导入内核方法可参考《[ShellCrash 和 AdGuard Home 快速安装教程/导入 mihomo 内核 或 sing-box 内核](https://proxy-tutorials.dustinwin.us.kg/posts/pin-toolsinstall/#%E4%BA%8C-%E5%AF%BC%E5%85%A5-mihomo-%E5%86%85%E6%A0%B8-%E6%88%96-sing-box-%E5%86%85%E6%A0%B8)》)
4. 可进入 <https://ipleak.net> 测试 DNS 是否泄露,“DNS Addresses” 栏目下没有中国国旗(因 `ipleak.net` 属未知域名,默认走 `漏网之鱼` 规则),即代表 DNS 没有发生泄露
## 一、 导入路由规则文件
geosite.dat 文件须包含 `fakeip-filter``cn``proxy`,推荐导入我定制的[路由规则文件](https://github.com/DustinWin/ruleset_geodata?tab=readme-ov-file#%E4%B8%80-geodata-%E6%96%87%E4%BB%B6%E8%AF%B4%E6%98%8E)
## 二、 ShellCrash 防泄漏配置
进入 ShellCrash 配置脚本 → 2) 功能设置 → 2) DNS 设置 → 9) 修改 DNS 服务器,将“DIRECT-DNS”、“PROXY-DNS”和“DEFAULT-DNS”都设置为 `null`
<img src="/assets/img/dns/dns-null.png" alt="ShellCrash 设置" width="60%" />
## 三、 DNS 防泄漏配置
### 1. DNS 模式为 `mix`(推荐)
连接 SSH 后执行 `vi $CRASHDIR/yamls/user.yaml`,按一下 Ins 键(Insert 键),粘贴如下内容:
>推荐将 `ecs` 设置为当前宽带运营商分配的默认 DNS(可进入光猫或路由器拨号页面查看,或者前往[公共 DNS 大全](https://toolb.cn/publicdns)查询)的 IP 段,如默认 DNS 为 `211.137.58.20`,可设置为 `211.137.58.0/24`
{: .prompt-info }
```yaml
hosts:
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]
dns:
enable: true
ipv6: true
listen: 0.0.0.0:1053
enhanced-mode: fake-ip
fake-ip-range: 28.0.0.0/8
fake-ip-range6: fc00::/16
fake-ip-filter-mode: rule
fake-ip-filter:
- GEOSITE,fakeip-filter,real-ip
- GEOSITE,proxy,fake-ip
- GEOSITE,cn,real-ip
- MATCH,fake-ip
respect-rules: true
nameserver:
# 推荐将 `ecs` 设置为当前宽带运营商分配的默认 DNS 的 IP 段
- 'https://dns.google/dns-query#ecs=211.137.58.0/24&ecs-override=true'
- 'quic://dns11.quad9.net:853#ecs=211.137.58.0/24&ecs-override=true'
proxy-server-nameserver:
- quic://dns.alidns.com:853
- https://dns.pub/dns-query
direct-nameserver:
- quic://dns.alidns.com:853
- https://dns.pub/dns-query
direct-nameserver-follow-policy: true
nameserver-policy:
'geosite:fakeip-filter,cn':
- quic://dns.alidns.com:853
- https://dns.pub/dns-query
```
按一下 Esc 键(退出键),输入英文冒号 `:`,继续输入 `wq` 并回车
### 2. DNS 模式为 `fake-ip`(不推荐)
- ① 额外编辑配置文件,在《[生成带有自定义策略组和规则的 mihomo 配置文件直链-geodata 方案/添加模板](https://proxy-tutorials.dustinwin.us.kg/posts/link-mihomo-geodata/#%E4%BA%8C-%E6%B7%BB%E5%8A%A0%E6%A8%A1%E6%9D%BF)》编辑 .yaml 配置文件时,将 `rules` 里的所有 `GEOIP` 规则末尾加上 `no-resolve`,即修改为:
```yaml
- GEOIP,telegram,📲 电报消息,no-resolve
- GEOIP,private,🔒 私有网络,no-resolve
- GEOIP,cn,🀄️ 国内 IP,no-resolve
```
- ② 连接 SSH 后执行 `vi $CRASHDIR/yamls/user.yaml`,按一下 Ins 键(Insert 键),粘贴如下内容:
```yaml
hosts:
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:
enable: true
prefer-h3: true
ipv6: true
listen: 0.0.0.0:1053
enhanced-mode: fake-ip
fake-ip-range: 28.0.0.0/8
fake-ip-range6: fc00::/16
fake-ip-filter: [geosite:fakeip-filter]
nameserver:
- quic://dns.alidns.com:853
- https://dns.pub/dns-query
```
按一下 Esc 键(退出键),输入英文冒号 `:`,继续输入 `wq` 并回车
### 3. DNS 模式为 `redir-host`
连接 SSH 后执行 `vi $CRASHDIR/yamls/user.yaml`,按一下 Ins 键(Insert 键),粘贴如下内容:
>推荐将 `ecs` 设置为当前宽带运营商分配的默认 DNS(可进入光猫或路由器拨号页面查看,或者前往[公共 DNS 大全](https://toolb.cn/publicdns)查询)的 IP 段,如默认 DNS 为 `211.137.58.20`,可设置为 `211.137.58.0/24`
{: .prompt-info }
```yaml
hosts:
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]
dns:
enable: true
ipv6: true
listen: 0.0.0.0:1053
enhanced-mode: fake-ip
fake-ip-range: 28.0.0.0/8
fake-ip-range6: fc00::/16
fake-ip-filter: ['+.*']
respect-rules: true
nameserver:
# 推荐将 `ecs` 设置为当前宽带运营商分配的默认 DNS 的 IP 段
- 'https://dns.google/dns-query#ecs=211.137.58.0/24&ecs-override=true'
- 'quic://dns11.quad9.net:853#ecs=211.137.58.0/24&ecs-override=true'
proxy-server-nameserver:
- quic://dns.alidns.com:853
- https://dns.pub/dns-query
direct-nameserver:
- quic://dns.alidns.com:853
- https://dns.pub/dns-query
direct-nameserver-follow-policy: true
nameserver-policy:
'geosite:cn':
- quic://dns.alidns.com:853
- https://dns.pub/dns-query
```
按一下 Esc 键(退出键),输入英文冒号 `:`,继续输入 `wq` 并回车
@@ -0,0 +1,167 @@
---
title: 搭载 mihomo 内核配置 DNS 不泄露教程-ruleset 方案
description: 此教程搭载 mihomo 内核并使用其特性防止 DNS 泄露,即针对未知域名走国外 DNS 解析
date: 2024-08-21 07:52:58 +0800
categories: [DNS 配置, DNS 防泄漏]
tags: [Clash, mihomo, 进阶, DNS, DNS 泄露]
---
> 说明
{: .prompt-tip }
1. 此方案彻底防止了 DNS 泄露(未知域名在匹配 `RULE-SET:cnip` 规则时会由国外 DNS 解析且配置 `ecs`,解析出 IP 在国内则走 `国内 IP` 规则,否则走 `漏网之鱼` 规则),兼容性高,可放心使用
2. 本教程以 [ShellCrash](https://github.com/juewuy/ShellCrash) 为例,其它客户端亦可参考
3. 本教程搭载 [mihomo 内核 Meta 版](https://github.com/MetaCubeX/mihomo/tree/Meta)(导入内核方法可参考《[ShellCrash 和 AdGuard Home 快速安装教程/导入 mihomo 内核 或 sing-box 内核](https://proxy-tutorials.dustinwin.us.kg/posts/pin-toolsinstall/#%E4%BA%8C-%E5%AF%BC%E5%85%A5-mihomo-%E5%86%85%E6%A0%B8-%E6%88%96-sing-box-%E5%86%85%E6%A0%B8)》)
4. 可进入 <https://ipleak.net> 测试 DNS 是否泄露,“DNS Addresses” 栏目下没有中国国旗(因 `ipleak.net` 属未知域名,默认走 `漏网之鱼` 规则),即代表 DNS 没有发生泄露
## 一、 导入规则集合文件
`rule-providers` 须添加 `fakeip-filter``cn``proxy`,如下:
```yaml
rule-providers:
fakeip-filter:
type: http
behavior: domain
format: mrs
path: ./ruleset/fakeip-filter.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/fakeip-filter.mrs"
interval: 86400
cn:
type: http
behavior: domain
format: mrs
path: ./ruleset/cn.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/cn.mrs"
interval: 86400
proxy:
type: http
behavior: domain
format: mrs
path: ./ruleset/proxy.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/proxy.mrs"
interval: 86400
```
## 二、 ShellCrash 防泄漏配置
进入 ShellCrash 配置脚本 → 2) 功能设置 → 2) DNS 设置 → 9) 修改 DNS 服务器,将“DIRECT-DNS”、“PROXY-DNS”和“DEFAULT-DNS”都设置为 `null`
<img src="/assets/img/dns/dns-null.png" alt="ShellCrash 设置" width="60%" />
## 三、 DNS 防泄漏配置
### 1. DNS 模式为 `mix`(推荐)
连接 SSH 后执行 `vi $CRASHDIR/yamls/user.yaml`,按一下 Ins 键(Insert 键),粘贴如下内容:
>推荐将 `ecs` 设置为当前宽带运营商分配的默认 DNS(可进入光猫或路由器拨号页面查看,或者前往[公共 DNS 大全](https://toolb.cn/publicdns)查询)的 IP 段,如默认 DNS 为 `211.137.58.20`,可设置为 `211.137.58.0/24`
{: .prompt-info }
```yaml
hosts:
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]
dns:
enable: true
ipv6: true
listen: 0.0.0.0:1053
enhanced-mode: fake-ip
fake-ip-range: 28.0.0.0/8
fake-ip-range6: fc00::/16
fake-ip-filter-mode: rule
fake-ip-filter:
- RULE-SET,fakeip-filter,real-ip
- RULE-SET,proxy,fake-ip
- RULE-SET,cn,real-ip
- MATCH,fake-ip
respect-rules: true
nameserver:
# 推荐将 `ecs` 设置为当前宽带运营商分配的默认 DNS 的 IP 段
- 'https://dns.google/dns-query#ecs=211.137.58.0/24&ecs-override=true'
- 'quic://dns11.quad9.net:853#ecs=211.137.58.0/24&ecs-override=true'
proxy-server-nameserver:
- quic://dns.alidns.com:853
- https://dns.pub/dns-query
direct-nameserver:
- quic://dns.alidns.com:853
- https://dns.pub/dns-query
direct-nameserver-follow-policy: true
nameserver-policy:
'rule-set:fakeip-filter,cn':
- quic://dns.alidns.com:853
- https://dns.pub/dns-query
```
按一下 Esc 键(退出键),输入英文冒号 `:`,继续输入 `wq` 并回车
### 2. DNS 模式为 `fake-ip`(不推荐)
- ① 额外编辑配置文件
在《[生成带有自定义策略组和规则的 mihomo 配置文件直链-ruleset 方案/添加模板](https://proxy-tutorials.dustinwin.us.kg/posts/link-mihomo-ruleset/#%E4%BA%8C-%E6%B7%BB%E5%8A%A0%E6%A8%A1%E6%9D%BF)》编辑 .yaml 配置文件时,将 `rules` 里所有 IP 相关的规则末尾加上 `no-resolve`,即修改为:
```yaml
- RULE-SET,telegramip,📲 电报消息,no-resolve
- RULE-SET,privateip,🔒 私有网络,no-resolve
- RULE-SET,cnip,🀄️ 国内 IP,no-resolve
```
- ② 连接 SSH 后执行 `vi $CRASHDIR/yamls/user.yaml`,按一下 Ins 键(Insert 键),粘贴如下内容:
```yaml
hosts:
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:
enable: true
prefer-h3: true
ipv6: true
listen: 0.0.0.0:1053
enhanced-mode: fake-ip
fake-ip-range: 28.0.0.0/8
fake-ip-range6: fc00::/16
fake-ip-filter: [rule-set:fakeip-filter]
nameserver:
- quic://dns.alidns.com:853
- https://dns.pub/dns-query
```
按一下 Esc 键(退出键),输入英文冒号 `:`,继续输入 `wq` 并回车
### 3. DNS 模式为 `redir-host`
连接 SSH 后执行 `vi $CRASHDIR/yamls/user.yaml`,按一下 Ins 键(Insert 键),粘贴如下内容:
>推荐将 `ecs` 设置为当前宽带运营商分配的默认 DNS(可进入光猫或路由器拨号页面查看,或者前往[公共 DNS 大全](https://toolb.cn/publicdns)查询)的 IP 段,如默认 DNS 为 `211.137.58.20`,可设置为 `211.137.58.0/24`
{: .prompt-info }
```yaml
hosts:
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]
dns:
enable: true
ipv6: true
listen: 0.0.0.0:1053
enhanced-mode: fake-ip
fake-ip-range: 28.0.0.0/8
fake-ip-range6: fc00::/16
fake-ip-filter: ['+.*']
respect-rules: true
nameserver:
# 推荐将 `ecs` 设置为当前宽带运营商分配的默认 DNS 的 IP 段
- 'https://dns.google/dns-query#ecs=211.137.58.0/24&ecs-override=true'
- 'quic://dns11.quad9.net:853#ecs=211.137.58.0/24&ecs-override=true'
proxy-server-nameserver:
- quic://dns.alidns.com:853
- https://dns.pub/dns-query
direct-nameserver:
- quic://dns.alidns.com:853
- https://dns.pub/dns-query
direct-nameserver-follow-policy: true
nameserver-policy:
'rule-set:cn':
- quic://dns.alidns.com:853
- https://dns.pub/dns-query
```
按一下 Esc 键(退出键),输入英文冒号 `:`,继续输入 `wq` 并回车
+315
View File
@@ -0,0 +1,315 @@
---
title: 生成带有自定义策略组和规则的 mihomo 配置文件直链-geodata 方案
description: 此教程搭载 mihomo 内核,采用 <code>GEOSITE</code> 和 <code>GEOIP</code> 规则搭配 geosite.dat 和 geoip.dat(或 Country.mmdb)路由规则文件
date: 2024-08-21 07:12:24 +0800
categories: [直链配置, mihomo 直链]
tags: [Clash, mihomo, 直链, 订阅, geodata, geosite, 基础]
---
> 说明
{: .prompt-tip }
1. 本教程可以生成扩展名为 .yaml 配置文件直链,可以**一键导入使用了 [mihomo](https://github.com/MetaCubeX/mihomo) 内核的客户端**
如:[ShellCrash](https://github.com/juewuy/ShellCrash)、[OpenClash](https://github.com/vernesong/OpenClash) 和 [Clash Verge](https://github.com/clash-verge-rev/clash-verge-rev) 等,详见[支持 mihomo 的工具](https://wiki.metacubex.one/startup/client)
2. 生成的订阅链接地址不会改变,支持更新订阅,**支持国内访问,支持同步机场节点**
3. 生成的订阅链接**自带规则集**,规则集来源 [DustinWin/ruleset_geodata/geodata](https://github.com/DustinWin/ruleset_geodata?tab=readme-ov-file#%E4%B8%80-geodata-%E6%96%87%E4%BB%B6%E8%AF%B4%E6%98%8E)
4. 请先**确定自己机场的订阅链接是否为 Clash 订阅链接**,若不是,需前往[肥羊在线订阅转换工具](https://suburl.v1.mk)进行转换,“生成类型”选择“Clash”,其它参数保持默认即可,转换后的订阅链接需要在末尾添加 `&flag=clash`,然后添加到 .yaml 文件代理集合 `proxy-providers``url`
5. 推荐使用 [Visual Studio Code](https://code.visualstudio.com/Download) 等专业编辑器来修改配置文件
6. ShellCrash 支持本地导入配置文件,可以直接将下方的 .yaml 直链文件内容复制到 `$CRASHDIR/yamls/config.yaml`{: .filepath} 文件中,可代替通过 ShellCrash 配置脚本 → 6) 配置文件管理 → a) 添加提供者
## 一、 准备编辑 .yaml 直链文件
### 1. 注册 [Gist](https://gist.github.com)
进入 <https://gist.github.com> 网站并注册
### 2. 打开编辑页面
登录并打开 Gist 可以直接编辑文件,或者点击页面右上角头像左边的“+”图标新建文件
### 3. 输入描述和完整文件名
“Gist description...”输入描述,随意填写;“Filename including extension...”输入完整文件名**包括扩展名**,如 mihomolink.yaml
<img src="/assets/img/link/file-extension-yaml.png" alt="输入描述和完整文件名" width="60%" />
## 二、 添加模板
### 1. 白名单模式(没有命中规则的网络流量统统使用代理,适用于服务器线路网络质量稳定、快速,不缺服务器流量的用户,推荐)
```yaml
# 代理集合(获取机场订阅链接内的所有节点)
proxy-providers:
🛫 机场订阅 1:
type: http
# 机场订阅链接,使用 Clash 链接
url: "https://example.com/xxx/xxx&flag=clash"
path: ./proxies/airport1.yaml
interval: 86400
# 初步筛选需要的节点,可有效减轻路由器压力,支持正则表达式,不筛选可删除此配置项
filter: "(?i)(🇭🇰|港|hk|hongkong|hong kong|🇹🇼|台|tw|taiwan|tai wan|🇯🇵|日|jp|japan|🇸🇬|新|sg|singapore|🇺🇸|美|us|unitedstates|united states)"
# 初步排除不需要的节点,支持正则表达式,若不排除可删除此配置项
exclude-filter: "高倍|直连|×10"
health-check:
enable: true
url: https://www.gstatic.com/generate_204
interval: 600
override:
# 为节点名称添加固定前缀,如节点名称原为“香港节点”会变成“🛫 机场订阅 1-香港节点”;推荐有多个机场时使用
additional-prefix: "🛫 机场订阅 1-"
# 为节点名称添加固定后缀,如节点名称原为“香港节点”会变成“香港节点-🛫 机场订阅 1”;推荐有多个机场时使用
additional-suffix: "-🛫 机场订阅 1"
🛫 机场订阅 2:
type: http
url: "https://example.com/xxx/xxx&flag=clash"
path: ./proxies/airport2.yaml
interval: 43200
filter: "(?i)(🇭🇰|港|hk|hongkong|hong kong|🇹🇼|台|tw|taiwan|tai wan|🇯🇵|日|jp|japan|🇸🇬|新|sg|singapore|🇺🇸|美|us|unitedstates|united states)"
exclude-filter: "高倍|直连|×10"
health-check:
enable: true
url: https://www.gstatic.com/generate_204
interval: 600
override:
# 为节点名称添加固定前缀,如节点名称原为“香港节点”会变成“🛫 机场订阅 2-香港节点”;推荐有多个机场时使用
additional-prefix: "🛫 机场订阅 2-"
# 为节点名称添加固定后缀,如节点名称原为“香港节点”会变成“香港节点-🛫 机场订阅 2”;推荐有多个机场时使用
additional-suffix: "-🛫 机场订阅 2"
# 单个出站代理节点(以 vless 为例)
proxies:
- name: 🆓 免费节点
type: vless
server: example.com
port: 443
uuid: {uuid}
network: ws
tls: true
udp: false
sni: example.com
client-fingerprint: chrome
ws-opts:
path: "/?ed=2048"
headers:
host: example.com
## 策略组
proxy-groups:
# 手动选择国家或地区节点;根据“国家或地区策略组”名称对 `proxies` 值进行增删改,须一一对应
- {name: 🚀 节点选择, type: select, proxies: [♻️ 自动选择, 👉 手动选择, 🇭🇰 香港节点, 🇹🇼 台湾节点, 🇯🇵 日本节点, 🇸🇬 新加坡节点, 🇺🇸 美国节点, 🆓 免费节点]}
# 选择`🎯 全球直连`为测试本地网络(运营商网络速度和 IPv6 支持情况),可选择其它节点用于测试机场节点速度和 IPv6 支持情况
- {name: 📈 网络测试, type: select, proxies: [🎯 全球直连, 🚀 节点选择, 🇭🇰 香港节点, 🇹🇼 台湾节点, 🇯🇵 日本节点, 🇸🇬 新加坡节点, 🇺🇸 美国节点, 🆓 免费节点]}
- {name: 🕹️ 游戏平台, type: select, proxies: [🚀 节点选择, 🇭🇰 香港节点, 🇹🇼 台湾节点, 🇯🇵 日本节点, 🇸🇬 新加坡节点, 🇺🇸 美国节点]}
- {name: 🤖 AI 平台, type: select, proxies: [🚀 节点选择, 🇭🇰 香港节点, 🇹🇼 台湾节点, 🇯🇵 日本节点, 🇸🇬 新加坡节点, 🇺🇸 美国节点]}
- {name: 🎮 游戏服务, type: select, proxies: [🎯 全球直连, 🚀 节点选择]}
- {name: 🪟 微软服务, type: select, proxies: [🎯 全球直连, 🚀 节点选择]}
- {name: 🇬 谷歌服务, type: select, proxies: [🎯 全球直连, 🚀 节点选择]}
- {name: 🍎 苹果服务, type: select, proxies: [🎯 全球直连, 🚀 节点选择]}
- {name: 🌍 国外媒体, type: select, proxies: [🚀 节点选择, 🇭🇰 香港节点, 🇹🇼 台湾节点, 🇯🇵 日本节点, 🇸🇬 新加坡节点, 🇺🇸 美国节点]}
- {name: 🇨🇳 国内域名, type: select, proxies: [🎯 全球直连, 🚀 节点选择]}
- {name: 🀄️ 国内 IP, type: select, proxies: [🎯 全球直连, 🚀 节点选择]}
- {name: 🌎 国外域名, type: select, proxies: [🚀 节点选择, 🇭🇰 香港节点, 🇹🇼 台湾节点, 🇯🇵 日本节点, 🇸🇬 新加坡节点, 🇺🇸 美国节点, 🆓 免费节点]}
- {name: 📲 电报消息, type: select, proxies: [🚀 节点选择, 🇭🇰 香港节点, 🇹🇼 台湾节点, 🇯🇵 日本节点, 🇸🇬 新加坡节点, 🇺🇸 美国节点, 🆓 免费节点]}
# 若在面板 Dashboard 中需隐藏该策略组,可添加 `hidden: true` 配置项
- {name: 🔒 私有网络, type: select, proxies: [🎯 全球直连], hidden: true}
# 若机场的 UDP 质量不是很好,导致某游戏无法登录或进入房间,可添加 `disable-udp: true` 配置项解决
- {name: 🐟 漏网之鱼, type: select, proxies: [🚀 节点选择, 🇭🇰 香港节点, 🇹🇼 台湾节点, 🇯🇵 日本节点, 🇸🇬 新加坡节点, 🇺🇸 美国节点, 🆓 免费节点, 🎯 全球直连]}
- {name: 🛑 广告域名, type: select, proxies: [🔴 全球拦截, 🟢 全球绕过]}
- {name: 🔴 全球拦截, type: select, proxies: [REJECT], hidden: true}
- {name: 🟢 全球绕过, type: select, proxies: [PASS], hidden: true}
- {name: 🎯 全球直连, type: select, proxies: [DIRECT], hidden: true}
# ----------------国家或地区策略组---------------------
# 自动选择节点,即按照 url 测试结果使用延迟最低的节点;测试后容差大于 50ms 才会切换到延迟低的那个节点;筛选出“香港”节点,支持正则表达式
- {name: 🇭🇰 香港节点, type: url-test, tolerance: 50, use: [🛫 机场订阅 1, 🛫 机场订阅 2], filter: "(?i)(🇭🇰|港|hk|hongkong|hong kong)"}
# 节点自动回退,默认选择第一个节点,节点超时后则会按代理顺序选择下一个可用节点,以此类推。也被叫做“故障转移”
- {name: 🇹🇼 台湾节点, type: fallback, use: [🛫 机场订阅 1, 🛫 机场订阅 2], filter: "(?i)(🇹🇼|台|tw|taiwan|tai wan)"}
# 节点负载均衡,即将请求均匀分配到多个节点上,优点是更稳定,速度可能有提升;将相同的目标地址请求分配给该策略组内的同一个节点;推荐在节点复用比较多的情况下使用
- {name: 🇯🇵 日本节点, type: load-balance, strategy: consistent-hashing, use: [🛫 机场订阅 1, 🛫 机场订阅 2], filter: "(?i)(🇯🇵|日|jp|japan)"}
# 可使用 `include-all: true` 代替 `use: [🛫 机场订阅 1, 🛫 机场订阅 2, ...]`,意思为引入所有出站代理以及代理集合
- {name: 🇸🇬 新加坡节点, type: url-test, tolerance: 50, include-all: true, filter: "(?i)(🇸🇬|新|sg|singapore)"}
- {name: 🇺🇸 美国节点, type: url-test, tolerance: 100, use: [🛫 机场订阅 1, 🛫 机场订阅 2], filter: "(?i)(🇺🇸|美|us|unitedstates|united states)"}
- {name: ♻️ 自动选择, type: url-test, tolerance: 100, include-all: true}
- {name: 👉 手动选择, type: select, include-all: true}
# 规则
rules:
# 自定义规则优先放前面
- GEOSITE,private,🔒 私有网络
- GEOSITE,ads,🛑 广告域名
# 为了使 P2P 流量(BT 下载)走直连,可添加一条 `DST-PORT` 规则(ShellCrash 会默认启用“只代理常用端口”,可删除此条 `DST-PORT`)
- DST-PORT,6881-6889,🎯 全球直连
- GEOSITE,microsoft-cn,🪟 微软服务
- GEOSITE,apple-cn,🍎 苹果服务
- GEOSITE,google-cn,🇬 谷歌服务
- GEOSITE,games-cn,🎮 游戏服务
- GEOSITE,games,🕹️ 游戏平台
- GEOSITE,media,🌍 国外媒体
- GEOSITE,ai,🤖 AI 平台
- GEOSITE,networktest,📈 网络测试
- GEOSITE,proxy,🌎 国外域名
- GEOSITE,cn,🇨🇳 国内域名
- GEOIP,private,🔒 私有网络,no-resolve
- GEOIP,cn,🀄️ 国内 IP
- GEOIP,telegram,📲 电报消息,no-resolve
- GEOIP,media,🌍 国外媒体
- MATCH,🐟 漏网之鱼
```
将模板内容复制到自己 Gist 新建的 .yaml 文件中
### 2. 黑名单模式(只有命中规则的网络流量才使用代理,适用于服务器线路网络质量不稳定或不够快,或服务器流量紧缺的用户。通常也是软路由用户、家庭网关用户的常用模式)
```yaml
# 代理集合(获取机场订阅链接内的所有节点)
proxy-providers:
🛫 机场订阅 1:
type: http
# 机场订阅链接,使用 Clash 链接
url: "https://example.com/xxx/xxx=1&flag=clash"
path: ./proxies/airport1.yaml
interval: 86400
# 初步筛选需要的节点,可有效减轻路由器压力,支持正则表达式,不筛选可删除此配置项
filter: "(?i)(🇭🇰|港|hk|hongkong|hong kong|🇹🇼|台|tw|taiwan|tai wan|🇯🇵|日|jp|japan|🇸🇬|新|sg|singapore|🇺🇸|美|us|unitedstates|united states)"
# 初步排除不需要的节点,支持正则表达式,若不排除可删除此配置项
exclude-filter: "高倍|直连|×10"
health-check:
enable: true
url: https://www.gstatic.com/generate_204
interval: 600
override:
# 为节点名称添加固定前缀,如节点名称原为“香港节点”会变成“🛫 机场订阅 1-香港节点”;推荐有多个机场时使用
additional-prefix: "🛫 机场订阅 1-"
# 为节点名称添加固定后缀,如节点名称原为“香港节点”会变成“香港节点-🛫 机场订阅 1”;推荐有多个机场时使用
additional-suffix: "-🛫 机场订阅 1"
🛫 机场订阅 2:
type: http
url: "https://example.com/xxx/xxx=2&flag=clash"
path: ./proxies/airport2.yaml
interval: 43200
filter: "(?i)(🇭🇰|港|hk|hongkong|hong kong|🇹🇼|台|tw|taiwan|tai wan|🇯🇵|日|jp|japan|🇸🇬|新|sg|singapore|🇺🇸|美|us|unitedstates|united states)"
exclude-filter: "高倍|直连|×10"
health-check:
enable: true
url: https://www.gstatic.com/generate_204
interval: 600
override:
# 为节点名称添加固定前缀,如节点名称原为“香港节点”会变成“🛫 机场订阅 2-香港节点”;推荐有多个机场时使用
additional-prefix: "🛫 机场订阅 2-"
# 为节点名称添加固定后缀,如节点名称原为“香港节点”会变成“香港节点-🛫 机场订阅 2”;推荐有多个机场时使用
additional-suffix: "-🛫 机场订阅 2"
# 单个出站代理节点(以 vless 为例)
proxies:
- name: 🆓 免费节点
type: vless
server: example.com
port: 443
uuid: {uuid}
network: ws
tls: true
udp: false
sni: example.com
client-fingerprint: chrome
ws-opts:
path: "/?ed=2048"
headers:
host: example.com
# 策略组
proxy-groups:
# 手动选择国家或地区节点;根据“国家或地区策略组”名称对 `proxies` 值进行增删改,须一一对应
- {name: 🚀 节点选择, type: select, proxies: [♻️ 自动选择, 👉 手动选择, 🇭🇰 香港节点, 🇹🇼 台湾节点, 🇯🇵 日本节点, 🇸🇬 新加坡节点, 🇺🇸 美国节点, 🆓 免费节点]}
# 选择`🎯 全球直连`为测试本地网络(运营商网络速度和 IPv6 支持情况),可选择其它节点用于测试机场节点速度和 IPv6 支持情况
- {name: 📈 网络测试, type: select, proxies: [🎯 全球直连, 🚀 节点选择, 🇭🇰 香港节点, 🇹🇼 台湾节点, 🇯🇵 日本节点, 🇸🇬 新加坡节点, 🇺🇸 美国节点, 🆓 免费节点]}
- {name: 🕹️ 游戏平台, type: select, proxies: [🚀 节点选择, 🇭🇰 香港节点, 🇹🇼 台湾节点, 🇯🇵 日本节点, 🇸🇬 新加坡节点, 🇺🇸 美国节点]}
- {name: 🤖 AI 平台, type: select, proxies: [🚀 节点选择, 🇭🇰 香港节点, 🇹🇼 台湾节点, 🇯🇵 日本节点, 🇸🇬 新加坡节点, 🇺🇸 美国节点]}
- {name: 🌍 国外媒体, type: select, proxies: [🚀 节点选择, 🇭🇰 香港节点, 🇹🇼 台湾节点, 🇯🇵 日本节点, 🇸🇬 新加坡节点, 🇺🇸 美国节点]}
- {name: 🌎 国外域名, type: select, proxies: [🚀 节点选择, 🇭🇰 香港节点, 🇹🇼 台湾节点, 🇯🇵 日本节点, 🇸🇬 新加坡节点, 🇺🇸 美国节点, 🆓 免费节点]}
- {name: 📲 电报消息, type: select, proxies: [🚀 节点选择, 🇭🇰 香港节点, 🇹🇼 台湾节点, 🇯🇵 日本节点, 🇸🇬 新加坡节点, 🇺🇸 美国节点, 🆓 免费节点]}
# 若在面板 Dashboard 中需隐藏该策略组,可添加 `hidden: true` 配置项
- {name: 🔒 私有网络, type: select, proxies: [🎯 全球直连], hidden: true}
- {name: 🐟 漏网之鱼, type: select, proxies: [🎯 全球直连, 🚀 节点选择, 🇭🇰 香港节点, 🇹🇼 台湾节点, 🇯🇵 日本节点, 🇸🇬 新加坡节点, 🇺🇸 美国节点, 🆓 免费节点]}
- {name: 🛑 广告域名, type: select, proxies: [🔴 全球拦截, 🟢 全球绕过]}
- {name: 🔴 全球拦截, type: select, proxies: [REJECT], hidden: true}
- {name: 🟢 全球绕过, type: select, proxies: [PASS], hidden: true}
- {name: 🎯 全球直连, type: select, proxies: [DIRECT], hidden: true}
# ----------------国家或地区策略组---------------------
# 自动选择节点,即按照 url 测试结果使用延迟最低的节点;测试后容差大于 50ms 才会切换到延迟低的那个节点;筛选出“香港”节点,支持正则表达式
- {name: 🇭🇰 香港节点, type: url-test, tolerance: 50, use: [🛫 机场订阅 1, 🛫 机场订阅 2], filter: "(?i)(🇭🇰|港|hk|hongkong|hong kong)"}
# 节点自动回退,默认选择第一个节点,节点超时后则会按代理顺序选择下一个可用节点,以此类推。也被叫做“故障转移”
- {name: 🇹🇼 台湾节点, type: fallback, use: [🛫 机场订阅 1, 🛫 机场订阅 2], filter: "(?i)(🇹🇼|台|tw|taiwan|tai wan)"}
# 节点负载均衡,即将请求均匀分配到多个节点上,优点是更稳定,速度可能有提升;将相同的目标地址请求分配给该策略组内的同一个节点;推荐在节点复用比较多的情况下使用
- {name: 🇯🇵 日本节点, type: load-balance, strategy: consistent-hashing, use: [🛫 机场订阅 1, 🛫 机场订阅 2], filter: "(?i)(🇯🇵|日|jp|japan)"}
# 可使用 `include-all: true` 代替 `use: [🛫 机场订阅 1, 🛫 机场订阅 2, ...]`,意思为引入所有出站代理以及代理集合
- {name: 🇸🇬 新加坡节点, type: url-test, tolerance: 50, include-all: true, filter: "(?i)(🇸🇬|新|sg|singapore)"}
- {name: 🇺🇸 美国节点, type: url-test, tolerance: 100, use: [🛫 机场订阅 1, 🛫 机场订阅 2], filter: "(?i)(🇺🇸|美|us|unitedstates|united states)"}
- {name: ♻️ 自动选择, type: url-test, tolerance: 100, include-all: true}
- {name: 👉 手动选择, type: select, include-all: true}
# 规则
rules:
# 自定义规则优先放前面
- GEOSITE,private,🔒 私有网络
- GEOSITE,ads,🛑 广告域名
- GEOSITE,games,🕹️ 游戏平台
- GEOSITE,media,🌍 国外媒体
- GEOSITE,ai,🤖 AI 平台
- GEOSITE,networktest,📈 网络测试
- GEOSITE,tld-proxy,🌎 国外域名
- GEOSITE,gfw,🌎 国外域名
- GEOIP,telegram,📲 电报消息,no-resolve
- GEOIP,media,🌍 国外媒体
- MATCH,🐟 漏网之鱼
```
将模板内容复制到自己 Gist 新建的 .yaml 文件中
## 三、 修改模板
1. 将代理集合 `proxy-providers` 中的 `url` 链接改成自己机场的订阅链接(必须为 Clash 订阅链接,详见《说明 4》)
2. 确定自己机场中有哪些国家或地区的节点,然后对 `proxy-groups` 中的 “**国家或地区策略组**”以及 `proxies` 里的国家或地区进行增删改
- 注:两者中的国家或地区必须一一对应,新增就全部新增,删除就全部删除,修改就全部修改(重要)
3. 在“国家或地区策略组”中的 `filter` 支持[正则表达式](https://www.lddgo.net/string/golangregex),可以精确地筛选出指定的国家或地区节点
例如:我想筛选出“香港 IPLC”节点,`filter` 可以这样写:`filter: "香港.*IPLC|IPLC.*香港"`
- 小窍门:使用 [ChatGPT](https://chatgpt.com) 等 AI 工具查询符合自己要求的正则表达式
4.`🚀 节点选择` 策略组下的 `proxies` 里,可以将最稳定的节点放在最前面,配置完成后会自动选择最稳定的节点
5. 在“国家或地区策略组”里,`type``url-test` 就是自动选择延迟最低的节点,将 `url-test` 改成 `select` 就是手动选择节点
举个例子:我想让 [Netflix](https://www.netflix.com/) 和 [Disney+](https://www.disneyplus.com/) 等国外媒体自动选择延迟最低的新加坡节点,这个需求怎么写?
注:
- ① 以下只是节选,请酌情套用
- ② 本教程搭配的路由规则文件包含有 `media``geosite:media``geoip:media` 已包含所有主流国外媒体)
```yaml
# 策略组
proxy-groups:
# 默认选择新加坡节点
- {name: 🌍 国外媒体, type: select, proxies: [🇸🇬 新加坡节点]}
# 自动选择延迟最低的新加坡节点;容差大于 50ms 才会切换到延迟低的那个节点
- {name: 🇸🇬 新加坡节点, type: url-test, tolerance: 50, include-all: true, filter: "(?i)(🇸🇬|新|sg|singapore)"}
# 规则
rules:
# 自定义规则优先放前面
- GEOSITE,media,🌍 国外媒体
- GEOIP,media,🌍 国外媒体
```
> 若有其它需求,可导入 [MetaCubeX/meta-rules-dat](https://github.com/MetaCubeX/meta-rules-dat) 路由规则文件,并分别进入 [MetaCubeX/meta-rules-dat/meta/geo](https://github.com/MetaCubeX/meta-rules-dat/tree/meta/geo) 的 *geosite* 和 *geoip* 目录搜索关键字,通过能够搜索到的关键字来编写规则
{: .prompt-tip }
## 四、 生成 .yaml 文件链接
1. 编辑完成后,点击右下角的“Create secret gist”按钮,然后点击右上角的“Raw”按钮
<img src="/assets/img/link/click-raw-yaml.png" alt="生成 .yaml 文件链接 1" width="60%" />
2. 取出地址栏中的网址,删除后面的一串随机码,**完成后该 .yaml 文件直链才是最终生成的订阅链接**,该订阅链接地址不会改变,在不更改文件名的情况下即使编辑该 .yaml 文件并提交了 n 次也不会改变。举个例子,这是原地址:
`https://gist.githubusercontent.com/DustinWin/3d1a5039fc6f88a1da44f8e0b1c8e181/raw/6e9d5fbbaf3b1f721eb9245e7944b2ca39512705/mihomolink.yaml`
删除后面的一串随机码(当前编辑该文件生成的随机码“6e9d5fbbaf3b1f721eb9245e7944b2ca39512705”)
<img src="/assets/img/link/2705-yaml.png" alt="生成 .yaml 文件链接 2" width="60%" />
删除后变成:
`https://gist.githubusercontent.com/DustinWin/3d1a5039fc6f88a1da44f8e0b1c8e181/raw/mihomolink.yaml`
- 注:若无法直连访问,可在链接上添加 `https://ghfast.top/` 前缀,即:将链接改为 `https://ghfast.top/https://gist.githubusercontent.com/DustinWin/3d1a5039fc6f88a1da44f8e0b1c8e181/raw/mihomolink.yaml`
## 五、 导入订阅链接(以 ShellCrash 导入订阅链接为例)
1. 进入 ShellCrash 配置脚本 → a) 添加提供者 → 1) 设置名称或代号,如输入“mihomo”;后进入 2) 设置链接或路径,粘贴最终生成的订阅链接,选择“a) 保存此提供者”
2. 进入 6) 配置文件管理 → 6) 配置文件管理 → c) 在线生成配置文件 → 6) 自定义浏览器 UA,选择“2) 不使用 UA”
3. 进入 6) 配置文件管理 → 1) mihomo,选择“e) 在线获取此配置文件”即可
4. 具体设置请参考《[ShellCrash 搭载 mihomo 内核的配置-geodata 方案](https://proxy-tutorials.dustinwin.us.kg/posts/toolsettings-shellcrash-mihomo-geodata)》
+570
View File
@@ -0,0 +1,570 @@
---
title: 生成带有自定义策略组和规则的 mihomo 配置文件直链-ruleset 方案
description: 此教程搭载 mihomo 内核,采用 <code>RULE-SET</code> 规则搭配 .list 和 .mrs 规则集合文件
date: 2024-08-21 07:41:24 +0800
categories: [直链配置, mihomo 直链]
tags: [Clash, mihomo, 直链, 订阅, ruleset, rule-set, 基础]
---
> 说明
{: .prompt-tip }
1. 本教程可以生成扩展名为 .yaml 配置文件直链,可以**一键导入使用了 [mihomo](https://github.com/MetaCubeX/mihomo) 内核的客户端**
如:[ShellCrash](https://github.com/juewuy/ShellCrash)、[OpenClash](https://github.com/vernesong/OpenClash)、[Clash Verge](https://github.com/MetaCubeX/clash-verge) 和 [Clash.Meta for Android](https://github.com/MetaCubeX/ClashMetaForAndroid) 等,详见[支持 mihomo 的工具](https://wiki.metacubex.one/startup/client)
2. 生成的订阅链接地址不会改变,支持更新订阅,**支持国内访问,支持同步机场节点**
3. 生成的订阅链接**自带规则集**,规则集来源 [DustinWin/ruleset_geodata/ruleset](https://github.com/DustinWin/ruleset_geodata#%E4%BA%8C-ruleset-%E8%A7%84%E5%88%99%E9%9B%86%E6%96%87%E4%BB%B6%E8%AF%B4%E6%98%8E)
4. 请先**确定自己机场的订阅链接是否为 Clash 订阅链接**,若不是,需前往[肥羊在线订阅转换工具](https://suburl.v1.mk)进行转换,“生成类型”选择“Clash”,其它参数保持默认即可,转换后的订阅链接需要在末尾添加`&flag=clash`,然后添加到 .yaml 文件代理集合 `proxy-providers``url`
5. 推荐使用 [Visual Studio Code](https://code.visualstudio.com/Download) 等专业编辑器来修改配置文件
6. ShellCrash 支持本地导入配置文件,可以直接将下方的 .yaml 直链文件内容复制到 `$CRASHDIR/yamls/config.yaml`{: .filepath} 文件中,可代替通过 ShellCrash 配置脚本 → 6) 配置文件管理 → a) 添加提供者
## 一、 准备编辑 .yaml 直链文件
### 1. 注册 [Gist](https://gist.github.com)
进入 <https://gist.github.com> 网站并注册
### 2. 打开编辑页面
登录并打开 Gist 可以直接编辑文件,或者点击页面右上角头像左边的“+”图标新建文件
### 3. 输入描述和完整文件名
“Gist description...”输入描述,随意填写;“Filename including extension...”输入完整文件名**包括扩展名**,如 mihomolink.yaml
<img src="/assets/img/link/file-extension-yaml.png" alt="输入描述和完整文件名" width="60%" />
## 二、 添加模板
### 1. 白名单模式(没有命中规则的网络流量统统使用代理,适用于服务器线路网络质量稳定、快速,不缺服务器流量的用户,推荐)
```yaml
# 代理集合(获取机场订阅链接内的所有节点)
proxy-providers:
🛫 机场订阅 1:
type: http
# 机场订阅链接,使用 Clash 链接
url: "https://example.com/xxx/xxx&flag=clash"
path: ./proxies/airport1.yaml
interval: 86400
# 初步筛选需要的节点,可有效减轻路由器压力,支持正则表达式,不筛选可删除此配置项
filter: "(?i)(🇭🇰|港|hk|hongkong|hong kong|🇹🇼|台|tw|taiwan|tai wan|🇯🇵|日|jp|japan|🇸🇬|新|sg|singapore|🇺🇸|美|us|unitedstates|united states)"
# 初步排除不需要的节点,支持正则表达式,若不排除可删除此配置项
exclude-filter: "高倍|直连|×10"
health-check:
enable: true
url: https://www.gstatic.com/generate_204
interval: 600
override:
# 为节点名称添加固定前缀,如节点名称原为“香港节点”会变成“🛫 机场订阅 1-香港节点”;推荐有多个机场时使用
additional-prefix: "🛫 机场订阅 1-"
# 为节点名称添加固定后缀,如节点名称原为“香港节点”会变成“香港节点-🛫 机场订阅 1”;推荐有多个机场时使用
additional-suffix: "-🛫 机场订阅 1"
🛫 机场订阅 2:
type: http
url: "https://example.com/xxx/xxx&flag=clash"
path: ./proxies/airport2.yaml
interval: 43200
filter: "(?i)(🇭🇰|港|hk|hongkong|hong kong|🇹🇼|台|tw|taiwan|tai wan|🇯🇵|日|jp|japan|🇸🇬|新|sg|singapore|🇺🇸|美|us|unitedstates|united states)"
exclude-filter: "高倍|直连|×10"
health-check:
enable: true
url: https://www.gstatic.com/generate_204
interval: 600
override:
# 为节点名称添加固定前缀,如节点名称原为“香港节点”会变成“🛫 机场订阅 2-香港节点”;推荐有多个机场时使用
additional-prefix: "🛫 机场订阅 2-"
# 为节点名称添加固定后缀,如节点名称原为“香港节点”会变成“香港节点-🛫 机场订阅 2”;推荐有多个机场时使用
additional-suffix: "-🛫 机场订阅 2"
# 单个出站代理节点(以 vless 为例)
proxies:
- name: 🆓 免费节点
type: vless
server: example.com
port: 443
uuid: {uuid}
network: ws
tls: true
udp: false
sni: example.com
client-fingerprint: chrome
ws-opts:
path: "/?ed=2048"
headers:
host: example.com
# 策略组
proxy-groups:
# 手动选择国家或地区节点;根据“国家或地区策略组”名称对 `proxies` 值进行增删改,须一一对应
- {name: 🚀 节点选择, type: select, proxies: [♻️ 自动选择, 👉 手动选择, 🇭🇰 香港节点, 🇹🇼 台湾节点, 🇯🇵 日本节点, 🇸🇬 新加坡节点, 🇺🇸 美国节点, 🆓 免费节点]}
# 选择`🎯 全球直连`为测试本地网络(运营商网络速度和 IPv6 支持情况),可选择其它节点用于测试机场节点速度和 IPv6 支持情况
- {name: 📈 网络测试, type: select, proxies: [🎯 全球直连, 🚀 节点选择, 🇭🇰 香港节点, 🇹🇼 台湾节点, 🇯🇵 日本节点, 🇸🇬 新加坡节点, 🇺🇸 美国节点, 🆓 免费节点]}
- {name: 🕹️ 游戏平台, type: select, proxies: [🚀 节点选择, 🇭🇰 香港节点, 🇹🇼 台湾节点, 🇯🇵 日本节点, 🇸🇬 新加坡节点, 🇺🇸 美国节点]}
- {name: 🤖 AI 平台, type: select, proxies: [🚀 节点选择, 🇭🇰 香港节点, 🇹🇼 台湾节点, 🇯🇵 日本节点, 🇸🇬 新加坡节点, 🇺🇸 美国节点]}
- {name: 🎮 游戏服务, type: select, proxies: [🎯 全球直连, 🚀 节点选择]}
- {name: 🪟 微软服务, type: select, proxies: [🎯 全球直连, 🚀 节点选择]}
- {name: 🇬 谷歌服务, type: select, proxies: [🎯 全球直连, 🚀 节点选择]}
- {name: 🍎 苹果服务, type: select, proxies: [🎯 全球直连, 🚀 节点选择]}
- {name: 🌍 国外媒体, type: select, proxies: [🚀 节点选择, 🇭🇰 香港节点, 🇹🇼 台湾节点, 🇯🇵 日本节点, 🇸🇬 新加坡节点, 🇺🇸 美国节点]}
- {name: 🇨🇳 国内域名, type: select, proxies: [🎯 全球直连, 🚀 节点选择]}
- {name: 🀄️ 国内 IP, type: select, proxies: [🎯 全球直连, 🚀 节点选择]}
- {name: 🌎 国外域名, type: select, proxies: [🚀 节点选择, 🇭🇰 香港节点, 🇹🇼 台湾节点, 🇯🇵 日本节点, 🇸🇬 新加坡节点, 🇺🇸 美国节点, 🆓 免费节点]}
- {name: 📲 电报消息, type: select, proxies: [🚀 节点选择, 🇭🇰 香港节点, 🇹🇼 台湾节点, 🇯🇵 日本节点, 🇸🇬 新加坡节点, 🇺🇸 美国节点, 🆓 免费节点]}
# 若使用 ShellCrash,由于无法判断本机进程(默认 `find-process-mode: off`),需删除此条 `⬇️ 直连软件`;若在面板 Dashboard 中需隐藏该策略组,可添加 `hidden: true` 配置项
- {name: ⬇️ 直连软件, type: select, proxies: [🎯 全球直连], hidden: true}
- {name: 🔒 私有网络, type: select, proxies: [🎯 全球直连], hidden: true}
# 若机场的 UDP 质量不是很好,导致某游戏无法登录或进入房间,可添加 `disable-udp: true` 配置项解决
- {name: 🐟 漏网之鱼, type: select, proxies: [🚀 节点选择, 🇭🇰 香港节点, 🇹🇼 台湾节点, 🇯🇵 日本节点, 🇸🇬 新加坡节点, 🇺🇸 美国节点, 🆓 免费节点, 🎯 全球直连]}
- {name: 🛑 广告域名, type: select, proxies: [🔴 全球拦截, 🟢 全球绕过]}
- {name: 🔴 全球拦截, type: select, proxies: [REJECT], hidden: true}
- {name: 🟢 全球绕过, type: select, proxies: [PASS], hidden: true}
- {name: 🎯 全球直连, type: select, proxies: [DIRECT], hidden: true}
# ----------------国家或地区策略组---------------------
# 自动选择节点,即按照 url 测试结果使用延迟最低的节点;测试后容差大于 50ms 才会切换到延迟低的那个节点;筛选出“香港”节点,支持正则表达式
- {name: 🇭🇰 香港节点, type: url-test, tolerance: 50, use: [🛫 机场订阅 1, 🛫 机场订阅 2], filter: "(?i)(🇭🇰|港|hk|hongkong|hong kong)"}
# 节点自动回退,默认选择第一个节点,节点超时后则会按代理顺序选择下一个可用节点,以此类推。也被叫做“故障转移”
- {name: 🇹🇼 台湾节点, type: fallback, use: [🛫 机场订阅 1, 🛫 机场订阅 2], filter: "(?i)(🇹🇼|台|tw|taiwan|tai wan)"}
# 节点负载均衡,即将请求均匀分配到多个节点上,优点是更稳定,速度可能有提升;将相同顶级域名的请求分配给策略组内的同一个代理节点;推荐在节点复用比较多的情况下使用
- {name: 🇯🇵 日本节点, type: load-balance, strategy: consistent-hashing, use: [🛫 机场订阅 1, 🛫 机场订阅 2], filter: "(?i)(🇯🇵|日|jp|japan)"}
# 可使用 `include-all: true` 代替 `use: [🛫 机场订阅 1, 🛫 机场订阅 2, ...]`,意思为引入所有出站代理以及代理集合
- {name: 🇸🇬 新加坡节点, type: url-test, tolerance: 50, include-all: true, filter: "(?i)(🇸🇬|新|sg|singapore)"}
- {name: 🇺🇸 美国节点, type: url-test, tolerance: 100, use: [🛫 机场订阅 1, 🛫 机场订阅 2], filter: "(?i)(🇺🇸|美|us|unitedstates|united states)"}
- {name: ♻️ 自动选择, type: url-test, tolerance: 100, include-all: true}
- {name: 👉 手动选择, type: select, include-all: true}
# 规则集(yaml 文件每天自动更新)
rule-providers:
ads:
type: http
behavior: domain
format: mrs
path: ./ruleset/ads.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/ads.mrs"
interval: 86400
private:
type: http
behavior: domain
format: mrs
path: ./ruleset/private.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/private.mrs"
interval: 86400
# 若使用 ShellCrash,由于无法判断本机进程(默认 `find-process-mode: off`),需删除此条 `applications`
applications:
type: http
behavior: classical
format: text
path: ./ruleset/applications.list
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/applications.list"
interval: 86400
microsoft-cn:
type: http
behavior: domain
format: mrs
path: ./ruleset/microsoft-cn.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/microsoft-cn.mrs"
interval: 86400
apple-cn:
type: http
behavior: domain
format: mrs
path: ./ruleset/apple-cn.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/apple-cn.mrs"
interval: 86400
google-cn:
type: http
behavior: domain
format: mrs
path: ./ruleset/google-cn.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/google-cn.mrs"
interval: 86400
games-cn:
type: http
behavior: domain
format: mrs
path: ./ruleset/games-cn.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/games-cn.mrs"
interval: 86400
games:
type: http
behavior: domain
format: mrs
path: ./ruleset/games.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/games.mrs"
interval: 86400
media:
type: http
behavior: domain
format: mrs
path: ./ruleset/media.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/media.mrs"
interval: 86400
ai:
type: http
behavior: domain
format: mrs
path: ./ruleset/ai.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/ai.mrs"
interval: 86400
networktest:
type: http
behavior: domain
format: mrs
path: ./ruleset/networktest.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/networktest.mrs"
interval: 86400
proxy:
type: http
behavior: domain
format: mrs
path: ./ruleset/proxy.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/proxy.mrs"
interval: 86400
cn:
type: http
behavior: domain
format: mrs
path: ./ruleset/cn.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/cn.mrs"
interval: 86400
privateip:
type: http
behavior: ipcidr
format: mrs
path: ./ruleset/privateip.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/privateip.mrs"
interval: 86400
cnip:
type: http
behavior: ipcidr
format: mrs
path: ./ruleset/cnip.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/cnip.mrs"
interval: 86400
telegramip:
type: http
behavior: ipcidr
format: mrs
path: ./ruleset/telegramip.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/telegramip.mrs"
interval: 86400
mediaip:
type: http
behavior: ipcidr
format: mrs
path: ./ruleset/mediaip.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/mediaip.mrs"
interval: 86400
# 规则
rules:
# 自定义规则优先放前面
- RULE-SET,private,🔒 私有网络
- RULE-SET,ads,🛑 广告域名
# 为了使 P2P 流量(BT 下载)走直连,可添加一条 `DST-PORT` 规则(ShellCrash 会默认启用“只代理常用端口”,可删除此条 `DST-PORT`)
- DST-PORT,6881-6889,🎯 全球直连
# 若使用 ShellCrash,由于无法判断本机进程(默认 `find-process-mode: off`),需删除此条 `RULE-SET`
- RULE-SET,applications,⬇️ 直连软件
- RULE-SET,microsoft-cn,🪟 微软服务
- RULE-SET,apple-cn,🍎 苹果服务
- RULE-SET,google-cn,🇬 谷歌服务
- RULE-SET,games-cn,🎮 游戏服务
- RULE-SET,games,🕹️ 游戏平台
- RULE-SET,media,🌍 国外媒体
- RULE-SET,ai,🤖 AI 平台
- RULE-SET,networktest,📈 网络测试
- RULE-SET,proxy,🌎 国外域名
- RULE-SET,cn,🇨🇳 国内域名
- RULE-SET,privateip,🔒 私有网络,no-resolve
- RULE-SET,cnip,🀄️ 国内 IP
- RULE-SET,telegramip,📲 电报消息,no-resolve
- RULE-SET,mediaip,🌍 国外媒体
- MATCH,🐟 漏网之鱼
```
将模板内容复制到自己 Gist 新建的 .yaml 文件中
### 2. 黑名单模式(只有命中规则的网络流量才使用代理,适用于服务器线路网络质量不稳定或不够快,或服务器流量紧缺的用户。通常也是软路由用户、家庭网关用户的常用模式)
```yaml
# 代理集合(获取机场订阅链接内的所有节点)
proxy-providers:
🛫 机场订阅 1:
type: http
# 机场订阅链接,使用 Clash 链接
url: "https://example.com/xxx/xxx&flag=clash"
path: ./proxies/airport1.yaml
interval: 86400
# 初步筛选需要的节点,可有效减轻路由器压力,支持正则表达式,不筛选可删除此配置项
filter: "(?i)(🇭🇰|港|hk|hongkong|hong kong|🇹🇼|台|tw|taiwan|tai wan|🇯🇵|日|jp|japan|🇸🇬|新|sg|singapore|🇺🇸|美|us|unitedstates|united states)"
# 初步排除不需要的节点,支持正则表达式,若不排除可删除此配置项
exclude-filter: "高倍|直连|×10"
health-check:
enable: true
url: https://www.gstatic.com/generate_204
interval: 600
override:
# 为节点名称添加固定前缀,如节点名称原为“香港节点”会变成“🛫 机场订阅 1-香港节点”;推荐有多个机场时使用
additional-prefix: "🛫 机场订阅 1-"
# 为节点名称添加固定后缀,如节点名称原为“香港节点”会变成“香港节点-🛫 机场订阅 1”;推荐有多个机场时使用
additional-suffix: "-🛫 机场订阅 1"
🛫 机场订阅 2:
type: http
url: "https://example.com/xxx/xxx&flag=clash"
path: ./proxies/airport2.yaml
interval: 43200
filter: "(?i)(🇭🇰|港|hk|hongkong|hong kong|🇹🇼|台|tw|taiwan|tai wan|🇯🇵|日|jp|japan|🇸🇬|新|sg|singapore|🇺🇸|美|us|unitedstates|united states)"
exclude-filter: "高倍|直连|×10"
health-check:
enable: true
url: https://www.gstatic.com/generate_204
interval: 600
override:
# 为节点名称添加固定前缀,如节点名称原为“香港节点”会变成“🛫 机场订阅 2-香港节点”;推荐有多个机场时使用
additional-prefix: "🛫 机场订阅 2-"
# 为节点名称添加固定后缀,如节点名称原为“香港节点”会变成“香港节点-🛫 机场订阅 2”;推荐有多个机场时使用
additional-suffix: "-🛫 机场订阅 2"
# 单个出站代理节点(以 vless 为例)
proxies:
- name: 🆓 免费节点
type: vless
server: example.com
port: 443
uuid: {uuid}
network: ws
tls: true
udp: false
sni: example.com
client-fingerprint: chrome
ws-opts:
path: "/?ed=2048"
headers:
host: example.com
# 策略组
proxy-groups:
# 手动选择国家或地区节点;根据“国家或地区策略组”名称对 `proxies` 值进行增删改,须一一对应
- {name: 🚀 节点选择, type: select, proxies: [♻️ 自动选择, 👉 手动选择, 🇭🇰 香港节点, 🇹🇼 台湾节点, 🇯🇵 日本节点, 🇸🇬 新加坡节点, 🇺🇸 美国节点, 🆓 免费节点]}
# 选择`🎯 全球直连`为测试本地网络(运营商网络速度和 IPv6 支持情况),可选择其它节点用于测试机场节点速度和 IPv6 支持情况
- {name: 📈 网络测试, type: select, proxies: [🎯 全球直连, 🚀 节点选择, 🇭🇰 香港节点, 🇹🇼 台湾节点, 🇯🇵 日本节点, 🇸🇬 新加坡节点, 🇺🇸 美国节点, 🆓 免费节点]}
- {name: 🕹️ 游戏平台, type: select, proxies: [🚀 节点选择, 🇭🇰 香港节点, 🇹🇼 台湾节点, 🇯🇵 日本节点, 🇸🇬 新加坡节点, 🇺🇸 美国节点]}
- {name: 🤖 AI 平台, type: select, proxies: [🚀 节点选择, 🇭🇰 香港节点, 🇹🇼 台湾节点, 🇯🇵 日本节点, 🇸🇬 新加坡节点, 🇺🇸 美国节点]}
- {name: 🌍 国外媒体, type: select, proxies: [🚀 节点选择, 🇭🇰 香港节点, 🇹🇼 台湾节点, 🇯🇵 日本节点, 🇸🇬 新加坡节点, 🇺🇸 美国节点]}
- {name: 🌎 国外域名, type: select, proxies: [🚀 节点选择, 🇭🇰 香港节点, 🇹🇼 台湾节点, 🇯🇵 日本节点, 🇸🇬 新加坡节点, 🇺🇸 美国节点, 🆓 免费节点]}
- {name: 📲 电报消息, type: select, proxies: [🚀 节点选择, 🇭🇰 香港节点, 🇹🇼 台湾节点, 🇯🇵 日本节点, 🇸🇬 新加坡节点, 🇺🇸 美国节点, 🆓 免费节点]}
# 若在面板 Dashboard 中需隐藏该策略组,可添加 `hidden: true` 配置项
- {name: 🔒 私有网络, type: select, proxies: [🎯 全球直连], hidden: true}
- {name: 🐟 漏网之鱼, type: select, proxies: [🎯 全球直连, 🚀 节点选择, 🇭🇰 香港节点, 🇹🇼 台湾节点, 🇯🇵 日本节点, 🇸🇬 新加坡节点, 🇺🇸 美国节点, 🆓 免费节点]}
- {name: 🛑 广告域名, type: select, proxies: [🔴 全球拦截, 🟢 全球绕过]}
- {name: 🔴 全球拦截, type: select, proxies: [REJECT], hidden: true}
- {name: 🟢 全球绕过, type: select, proxies: [PASS], hidden: true}
- {name: 🎯 全球直连, type: select, proxies: [DIRECT], hidden: true}
# ----------------国家或地区策略组---------------------
# 自动选择节点,即按照 url 测试结果使用延迟最低的节点;测试后容差大于 50ms 才会切换到延迟低的那个节点;筛选出“香港”节点,支持正则表达式
- {name: 🇭🇰 香港节点, type: url-test, tolerance: 50, use: [🛫 机场订阅 1, 🛫 机场订阅 2], filter: "(?i)(🇭🇰|港|hk|hongkong|hong kong)"}
# 节点自动回退,默认选择第一个节点,节点超时后则会按代理顺序选择下一个可用节点,以此类推。也被叫做“故障转移”
- {name: 🇹🇼 台湾节点, type: fallback, use: [🛫 机场订阅 1, 🛫 机场订阅 2], filter: "(?i)(🇹🇼|台|tw|taiwan|tai wan)"}
# 节点负载均衡,即将请求均匀分配到多个节点上,优点是更稳定,速度可能有提升;将相同顶级域名的请求分配给策略组内的同一个代理节点;推荐在节点复用比较多的情况下使用
- {name: 🇯🇵 日本节点, type: load-balance, strategy: consistent-hashing, use: [🛫 机场订阅 1, 🛫 机场订阅 2], filter: "(?i)(🇯🇵|日|jp|japan)"}
# 可使用 `include-all: true` 代替 `use: [🛫 机场订阅 1, 🛫 机场订阅 2, ...]`,意思为引入所有出站代理以及代理集合
- {name: 🇸🇬 新加坡节点, type: url-test, tolerance: 50, include-all: true, filter: "(?i)(🇸🇬|新|sg|singapore)"}
- {name: 🇺🇸 美国节点, type: url-test, tolerance: 100, use: [🛫 机场订阅 1, 🛫 机场订阅 2], filter: "(?i)(🇺🇸|美|us|unitedstates|united states)"}
- {name: ♻️ 自动选择, type: url-test, tolerance: 100, include-all: true}
- {name: 👉 手动选择, type: select, include-all: true}
# 规则集(yaml 文件每天自动更新)
rule-providers:
ads:
type: http
behavior: domain
format: mrs
path: ./ruleset/ads.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/ads.mrs"
interval: 86400
private:
type: http
behavior: domain
format: mrs
path: ./ruleset/private.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/private.mrs"
interval: 86400
games:
type: http
behavior: domain
format: mrs
path: ./ruleset/games.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/games.mrs"
interval: 86400
media:
type: http
behavior: domain
format: mrs
path: ./ruleset/media.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/media.mrs"
interval: 86400
ai:
type: http
behavior: domain
format: mrs
path: ./ruleset/ai.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/ai.mrs"
interval: 86400
networktest:
type: http
behavior: domain
format: mrs
path: ./ruleset/networktest.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/networktest.mrs"
interval: 86400
tld-proxy:
type: http
behavior: domain
format: mrs
path: ./ruleset/tld-proxy.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/tld-proxy.mrs"
interval: 86400
gfw:
type: http
behavior: domain
format: mrs
path: ./ruleset/gfw.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/gfw.mrs"
interval: 86400
telegramip:
type: http
behavior: ipcidr
format: mrs
path: ./ruleset/telegramip.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/telegramip.mrs"
interval: 86400
mediaip:
type: http
behavior: ipcidr
format: mrs
path: ./ruleset/mediaip.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/mediaip.mrs"
interval: 86400
# 规则
rules:
- RULE-SET,private,🔒 私有网络
- RULE-SET,ads,🛑 广告域名
- RULE-SET,games,🕹️ 游戏平台
- RULE-SET,media,🌍 国外媒体
- RULE-SET,ai,🤖 AI 平台
- RULE-SET,networktest,📈 网络测试
- RULE-SET,tld-proxy,🌎 国外域名
- RULE-SET,gfw,🌎 国外域名
- RULE-SET,telegramip,📲 电报消息,no-resolve
- RULE-SET,mediaip,🌍 国外媒体
- MATCH,🐟 漏网之鱼
```
将模板内容复制到自己 Gist 新建的 .yaml 文件中
## 三、 修改模板
1. 将代理集合 `proxy-providers` 中的 `url` 链接改成自己机场的订阅链接(必须为 Clash 订阅链接,详见《说明 4》)
2. 确定自己机场中有哪些国家或地区的节点,然后对 `proxy-groups` 中的 “**国家或地区策略组**”以及 `proxies` 里的国家或地区进行增删改
- 注:两者中的国家或地区必须一一对应,新增就全部新增,删除就全部删除,修改就全部修改(重要)
3. 在“国家或地区策略组”中的 `filter` 支持[正则表达式](https://www.lddgo.net/string/golangregex),可以精确地筛选出指定的国家或地区节点
例如:我想筛选出“香港 IPLC”节点,`filter` 可以这样写:
`filter: "香港.*IPLC|IPLC.*香港"`
- 小窍门:使用 [ChatGPT](https://chatgpt.com) 等 AI 工具查询符合自己要求的正则表达式
4.`🚀 节点选择` 策略组下的 `proxies` 里,可以将最稳定的节点放在最前面,配置完成后会自动选择最稳定的节点
5. 在“国家或地区策略组”里,`type``url-test` 就是自动选择延迟最低的节点,将 `url-test` 改成 `select` 就是手动选择节点
举个例子:我的机场包含有 2 个节点,分别是新加坡节点和日本节点,我想让 [Netflix](https://www.netflix.com/) 自动选择延迟最低的新加坡节点,[哔哩哔哩](https://www.bilibili.com)可以手动选择日本任一节点,这个需求怎么写?
注:
- ① 以下只是节选,请酌情套用
- ② 本教程搭配的规则集合文件包含有 `netflix``netflixip``bilibili`
```yaml
# 策略组
proxy-groups:
# 默认选择新加坡节点
- {name: 🎥 奈飞视频, type: select, proxies: [🇸🇬 新加坡节点]}
# 默认选择日本节点,也可切换到直连
- {name: 📺 哔哩哔哩, type: select, proxies: [🇯🇵 日本节点, 🎯 全球直连]}
# 自动选择延迟最低的新加坡节点;容差大于 50ms 才会切换到延迟低的那个节点
- {name: 🇸🇬 新加坡节点, type: url-test, tolerance: 50, include-all: true, filter: "(?i)(🇸🇬|新|sg|singapore)"}
# 手动选择日本任一节点
- {name: 🇯🇵 日本节点, type: select, include-all: true, filter: "(?i)(🇯🇵|日|jp|japan)"}
- {name: 🎯 全球直连, type: select, proxies: [DIRECT], hidden: true}
# 规则集(yaml 文件每天自动更新)
rule-providers:
netflix:
type: http
behavior: domain
format: mrs
path: ./ruleset/netflix.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/netflix.mrs"
interval: 86400
netflixip:
type: http
behavior: ipcidr
format: mrs
path: ./ruleset/netflixip.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/netflixip.mrs"
interval: 86400
bilibili:
type: http
behavior: domain
format: mrs
path: ./ruleset/bilibili.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/bilibili.mrs"
interval: 86400
# 规则
rules:
# 自定义规则优先放前面
- RULE-SET,netflix,🎥 奈飞视频
- RULE-SET,netflixip,🎥 奈飞视频
- RULE-SET,bilibili,📺 哔哩哔哩
```
> 若有其它需求,可进入 [blackmatrix7/ios_rule_script/rule/Clash](https://github.com/blackmatrix7/ios_rule_script/tree/master/rule/Clash) 搜索关键字,通过能够搜索到的关键字来编写规则(推荐使用“xxx_Classical.yaml”文件,`rule-provider` 内须配置 `behavior: classical`
{: .prompt-tip }
## 四、 生成 .yaml 文件链接
1. 编辑完成后,点击右下角的“Create secret gist”按钮,然后点击右上角的“Raw”按钮
<img src="/assets/img/link/click-raw-yaml.png" alt="生成 .yaml 文件链接 1" width="60%" />
2. 取出地址栏中的网址,删除后面的一串随机码,**完成后该 .yaml 文件直链才是最终生成的订阅链接**,该订阅链接地址不会改变,在不更改文件名的情况下即使编辑该 .yaml 文件并提交了 n 次也不会改变。举个例子,这是原地址:
`https://gist.githubusercontent.com/DustinWin/3d1a5039fc6f88a1da44f8e0b1c8e181/raw/6e9d5fbbaf3b1f721eb9245e7944b2ca39512705/mihomolink.yaml`
删除后面的一串随机码(当前编辑该文件生成的随机码“6e9d5fbbaf3b1f721eb9245e7944b2ca39512705”)
<img src="/assets/img/link/2705-yaml.png" alt="生成 .yaml 文件链接 2" width="60%" />
删除后变成:
`https://gist.githubusercontent.com/DustinWin/3d1a5039fc6f88a1da44f8e0b1c8e181/raw/mihomolink.yaml`
- 注:若无法直连访问,可在链接上添加 `https://ghfast.top/` 前缀,即:将链接改为 `https://ghfast.top/https://gist.githubusercontent.com/DustinWin/3d1a5039fc6f88a1da44f8e0b1c8e181/raw/mihomolink.yaml`
## 五、 导入订阅链接(以 ShellCrash 导入订阅链接为例)
1. 进入 ShellCrash 配置脚本 → a) 添加提供者 → 1) 设置名称或代号,如输入 `mihomo`;后进入 2) 设置链接或路径,粘贴最终生成的订阅链接,选择“a) 保存此提供者”
2. 进入 6) 配置文件管理 → 6) 配置文件管理 → c) 在线生成配置文件 → 6) 自定义浏览器 UA,选择“2) 不使用 UA”
3. 进入 6) 配置文件管理 → 1) mihomo,选择“e) 在线获取此配置文件”即可
4. 具体设置请参考《[ShellCrash 搭载 mihomo 内核的配置-ruleset 方案](https://proxy-tutorials.dustinwin.us.kg/posts/toolsettings-shellcrash-mihomo-ruleset)》
@@ -0,0 +1,481 @@
---
title: 全网最详细的解锁 SSH ShellCrash 搭载 mihomo 内核搭配 AdGuard Home 安装和配置教程
description: 此教程使用 ShellCrash 搭载 mihomo 内核并搭配 AdGuard Home 作下游,配有详细图文
date: 2024-08-21 18:29:59 +0800
categories: [置顶]
tags: [Clash, mihomo, ShellCrash, AdGuard Home, 解锁, SSH]
pin: true
---
> 说明
{: .prompt-tip }
1. 本教程基于 REDMI AX6000 [官方固件](https://www1.miwifi.com/miwifi_download.html) v1.0.70 版,[ShellCrash](https://github.com/juewuy/ShellCrash) v1.9.5 版,[AdGuard Home](https://github.com/AdguardTeam/AdGuardHome) v0.108.0 版编写
2. 恢复 SSH,安装 ShellCrash 和 AdGuard Home 的方法也适用于其它已解锁 SSH 的路由器
3. 安装 [mihomo 内核](https://github.com/MetaCubeX/mihomo)和 AdGuard Home 时须注意路由器 CPU 架构,查看 CPU 架构可连接 SSH 后执行命令 `uname -ms`,若执行结果是“linux aarch64”,就下载 arm64 版安装包;若是其它架构请下载相匹配的安装包
4. ShellCrash 和 AdGuard Home 中所有没有提到的配置保持默认即可
5. 使用本教程时,不建议启用 ShellCrash 配置脚本 → 2) 功能设置 → 3) 透明路由流量过滤 → 2) 过滤局域网设备,因不经过内核的设备在访问 `漏网之鱼` 域名时会遇到无法访问的情况
6. ShellCrash 和 AdGuard Home 快速安装方法请看《[ShellCrash 和 AdGuard Home 快速安装教程](https://proxy-tutorials.dustinwin.us.kg/posts/pin-toolsinstall)》
7. ShellCrash 单独使用时设置 DNS 分流请看《[搭载 mihomo 内核进行 DNS 分流教程-geodata 方案](https://proxy-tutorials.dustinwin.us.kg/posts/dnsbypass-mihomo-geodata)》或《[搭载 mihomo 内核进行 DNS 分流教程-ruleset 方案](https://proxy-tutorials.dustinwin.us.kg/posts/dnsbypass-mihomo-ruleset)》
## 一、 资源下载
打包下载:<https://dustinwinvip.lanzoum.com/b01qd6p3a>
密码:`zyxz`
注:
- ① 没有对文件进行任何处理,请自行操作使用
- ② 不保证实时更新,想用新版请安装后自行升级
- ③ 版本信息请查看打包文件内的 Readme.txt 文本
### 1. ShellCrash
官方下载:<https://raw.githubusercontent.com/juewuy/ShellCrash/master/ShellCrash.tar.gz>
### 2. mihomo 内核
官方下载:<https://github.com/MetaCubeX/mihomo/releases>
下载 mihomo-linux-arm64-[version].gz 文件
### 3. PuTTY
官方下载:<https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html>
下载 putty-64bit-[version]-installer.msi 文件
### 4. AdGuard Home
官方下载:<https://github.com/AdguardTeam/AdGuardHome/releases>
下载 AdGuardHome_linux_arm64.tar.gz 文件
### 5. UPX
官方下载:<https://github.com/upx/upx/releases>
下载 upx-[version]-win64.zip 文件
### 6. WinSCP
官方下载:<https://winscp.net/eng/downloads.php>
下载 WinSCP-[version]-Setup.exe 文件
## 二、 添加 SSH 支持
### 1. 给 Windows 操作系统添加 SSH 支持(任选一)
- ① 启用 Telnet 客户端
- ➊ 进入设置 → 系统 → 可选功能 → 更多 Windows 功能,勾选“Telnet Client”并点击“确定”
<img src="/assets/img/pin/add-windows-telnet-1.png" alt="启用 Telnet 客户端 1" width="60%" />
- ➋ 点击“让 Windows 更新为你下载文件”
<img src="/assets/img/pin/add-windows-telnet-2.png" alt="启用 Telnet 客户端 2" width="60%" />
- ② 添加 OpenSSH 客户端和 OpenSSH 服务器
- ➊ 进入设置 → 系统 → 可选功能 → 查看功能,搜索“ssh”,在搜索结果中勾选“OpenSSH 客户端”和“OpenSSH 服务器”并点击“下一步”
<img src="/assets/img/pin/add-windows-openssh-1.png" alt="启用 OpenSSH 服务器 1" width="60%" />
- ➋ 点击“添加”
<img src="/assets/img/pin/add-windows-openssh-2.png" alt="启用 OpenSSH 服务器 2" width="60%" />
> 在成功完成《[三、 2](https://proxy-tutorials.dustinwin.us.kg/posts/pin-shellcrashadguardhome-mihomo/#2-%E6%B0%B8%E4%B9%85%E5%BC%80%E5%90%AF-telnet)》后才能进行此操作
{: .prompt-warning }
- ③ 连接 Telnet
- ➊ 以管理员身份运行 PowerShell 或 CMD,执行命令 `telnet 192.168.31.1`
- 注:首次登录不需要用户名和密码,解锁或恢复 SSH 后用户名为 `root`,密码为《[三、 3](https://proxy-tutorials.dustinwin.us.kg/posts/pin-shellcrashadguardhome-mihomo/#3-%E6%B0%B8%E4%B9%85%E5%BC%80%E5%90%AF%E5%B9%B6%E5%9B%BA%E5%8C%96-ssh)》中设置的登录密码
<img src="/assets/img/pin/connect-telnet-windows-1.png" alt="连接 Telnet 1" width="60%" />
- ➋ 输入密码 `12345678`(输入时密码不可见,下同)并回车,显示“ARE U OK”表示成功连接 Telnet
<img src="/assets/img/pin/connect-telnet-windows-2.png" alt="连接 Telnet 2" width="60%" />
> 在成功完成《[三、 3](https://proxy-tutorials.dustinwin.us.kg/posts/pin-shellcrashadguardhome-mihomo/#3-%E6%B0%B8%E4%B9%85%E5%BC%80%E5%90%AF%E5%B9%B6%E5%9B%BA%E5%8C%96-ssh)》后才能进行此操作
{: .prompt-warning }
- ④ 连接 SSH
- ➊ 以管理员身份运行 PowerShell 或 CMD,执行命令 `ssh -oHostKeyAlgorithms=+ssh-rsa [email protected]` 以允许 SSH 客户端接受“ssh-rsa”密钥,输入 `yes` 并回车
- 注:若当前电脑登录过 SSH,后路由器经过重新解锁或恢复 SSH,须进入 `C:\Users\[用户名]\.ssh`{: .filepath} 文件夹,删除“known_hosts”文件,否则登录会报错
<img src="/assets/img/pin/connect-ssh-windows-1.png" alt="连接 SSH 1" width="60%" />
- ➋ 输入密码 `12345678` 并回车
<img src="/assets/img/pin/connect-ssh-windows-2.png" alt="连接 SSH 2" width="60%" />
- ➌ 显示“ARE U OK”表示成功登录 SSH
<img src="/assets/img/pin/connect-ssh-windows-3.png" alt="连接 SSH 3" width="60%" />
### 2. 通过 SSH 工具添加 SSH 支持(任选一)
> 在成功完成《[三、 2](https://proxy-tutorials.dustinwin.us.kg/posts/pin-shellcrashadguardhome-mihomo/#2-%E6%B0%B8%E4%B9%85%E5%BC%80%E5%90%AF-telnet)》后才能进行此操作
{: .prompt-warning }
- ① 连接 Telnet
- ➊ 安装 PuTTY 并打开,按图输入和选择,点击“Open”即可成功连接 Telnet
<img src="/assets/img/pin/connect-telnet-1.png" alt="连接 Telnet 1" width="60%" />
- ➋ 显示“ARE U OK”表示成功登录 Telnet
<img src="/assets/img/pin/connect-telnet-2.png" alt="连接和添加 Telnet 2" width="60%" />
> 在成功完成《[三、 3](https://proxy-tutorials.dustinwin.us.kg/posts/pin-shellcrashadguardhome-mihomo/#3-%E6%B0%B8%E4%B9%85%E5%BC%80%E5%90%AF%E5%B9%B6%E5%9B%BA%E5%8C%96-ssh)》后才能进行此操作
{: .prompt-warning }
- ② 连接 SSH
- ➊ 打开 PuTTY,然后按图输入,点击“Open”即可成功连接 SSH
<img src="/assets/img/pin/connect-ssh-1.png" alt="连接和添加 SSH 1" width="60%" />
- ➋ “login as”输入 `root` 并回车,“password”为解锁或恢复 SSH 时设置的密码,输入后再次回车,显示“ARE U OK”表示成功连接 SSH
<img src="/assets/img/pin/connect-ssh-2.png" alt="连接和添加 SSH 2" width="60%" />
### 3. 通过 WinSCP 连接路由器文件管理
> 在成功完成《[三、 3](https://proxy-tutorials.dustinwin.us.kg/posts/pin-shellcrashadguardhome-mihomo/#3-%E6%B0%B8%E4%B9%85%E5%BC%80%E5%90%AF%E5%B9%B6%E5%9B%BA%E5%8C%96-ssh)》后才能进行此操作
{: .prompt-warning }
- ① 安装 WinSCP 并打开,“文件协议”选择“SCP”,其它按图输入,“密码”为 SSH 登录密码,点击“保存”后再点击“登录”
<img src="/assets/img/pin/login-winscp.png" alt="通过 WinSCP 连接路由器文件管理 1" width="60%" />
- ② 左侧为电脑本地文件,右侧为路由器文件
<img src="/assets/img/pin/show-winscp.png" alt="通过 WinSCP 连接路由器文件管理 2" width="60%" />
---
>配置免密码连接 SSH 和 WinSCP
{: .prompt-tip }
1. 配置免密码连接 SSH
- ① 打开 PuTTYgen,直接点击“Generate”(期间鼠标必须在此窗口内不停移动)
<img src="/assets/img/pin/puttygen-generate.png" alt="生成 key" width="60%" />
- ② 生成后复制完整的“Key”值备用,点击“Save private key”(可在“Key comment”输入 `[email protected] - REDMI AX6000`
<img src="/assets/img/pin/puttygen-save.png" alt="保存 key" width="60%" />
- ③ “保存”文件到 `C:\Users\[用户名]\.ssh\rsa_key.ppk`{: .filepath} 中
- ④ 打开 PuTTY,进入 Connection → SSH → Auth → Credentials,点击“Private key file for authentication”的“Browser”,定位到 `C:\Users\[用户名]\.ssh\rsa_key.ppk`{: .filepath} 文件并“打开”
- ⑤ 进入 Connections → Data,“Auto-login username”输入 `root`
<img src="/assets/img/pin/putty-setting-1.png" alt="设置登录用户名" width="60%" />
- ⑥ 进入 Session,按图输入后,**先点击“Default Settings”,后点击“Save”**
<img src="/assets/img/pin/putty-setting-2.png" alt="保存配置" width="60%" />
2. 配置免密码连接 WinSCP
- ① 打开 WinSCP,进入标签页 → 站点 → 站点管理器,点击“编辑”,删除密码后点击“高级”
- ② 进入 SSH → 验证,点击“密钥文件”的“...”图标,定位到 `C:\Users\[用户名]\.ssh\rsa_key.ppk`{: .filepath} 文件并“打开”,点击“确定”,再点击“保存”
3. 导入 Key 并加入开机启动
连接 SSH,执行如下命令:
- 注:将《1. ②》中复制的 Key 值替换下面命令中的 `{key}`
```shell
echo "{key}" > /data/auto_ssh/authorized_keys
chmod 600 /data/auto_ssh/authorized_keys
ln -sf /data/auto_ssh/authorized_keys /etc/dropbear/
echo -e "\nln -sf /data/auto_ssh/authorized_keys /etc/dropbear/" >> /data/auto_ssh/auto_ssh.sh
```
---
## 三、 解锁 SSH
### 1. 启用调试模式
- ① 进入路由器管理页面 <http://192.168.31.1>,登录后复制地址栏中的 stok 值
<img src="/assets/img/pin/copy-stok.png" alt="复制 stok 值" width="60%" />
- ② 将复制的 stok 值替换如下网址的 `{stok}` 并访问:
```text
http://192.168.31.1/cgi-bin/luci/;stok={stok}/api/misystem/set_sys_time?timezone=%20%27%20%3B%20zz%3D%24%28dd%20if%3D%2Fdev%2Fzero%20bs%3D1%20count%3D2%202%3E%2Fdev%2Fnull%29%20%3B%20printf%20%27%A5%5A%25c%25c%27%20%24zz%20%24zz%20%7C%20mtd%20write%20-%20crash%20%3B%20
```
网页内容显示 `{"code":0}` 表示成功启用调试模式
- ③ 继续将复制的 stok 值替换如下网址的 `{stok}` 并访问:
```text
http://192.168.31.1/cgi-bin/luci/;stok={stok}/api/misystem/set_sys_time?timezone=%20%27%20%3b%20reboot%20%3b%20
```
网页内容显示 `{"code":0}`,此时路由器会重启
### 2. 永久启用 Telnet
- ① 重启完成后进入路由器管理页面并登录,再次复制 stok 值
- ② 将复制的 stok 值替换如下网址的 `{stok}` 并访问:
```text
http://192.168.31.1/cgi-bin/luci/;stok={stok}/api/misystem/set_sys_time?timezone=%20%27%20%3B%20bdata%20set%20telnet_en%3D1%20%3B%20bdata%20set%20ssh_en%3D1%20%3B%20bdata%20set%20uart_en%3D1%20%3B%20bdata%20commit%20%3B%20
```
网页内容显示 `{"code":0}` 表示成功设置 Bdata 永久启用 Telnet
- ③ 继续将复制的 stok 值替换如下网址的 `{stok}` 并访问:
```text
http://192.168.31.1/cgi-bin/luci/;stok={stok}/api/misystem/set_sys_time?timezone=%20%27%20%3b%20reboot%20%3b%20
```
网页内容显示 `{"code":0}`,此时路由器会再次重启
**启用 Telnet 成功!**
### 3. 永久启用并固化 SSH
- ① 连接 Telnet,执行如下命令:
- 注:第一行命令是将 Telnet 和 SSH 登录密码设置为 `12345678`,可自定义
```shell
echo -e '12345678\n12345678' | passwd root
nvram set telnet_en=1
nvram set ssh_en=1
nvram set uart_en=1
nvram set boot_wait=on
nvram commit
/etc/init.d/dropbear enable & /etc/init.d/dropbear start
mkdir -p /data/auto_ssh
curl -sS -o /data/auto_ssh/auto_ssh.sh -L https://cdn.jsdelivr.net/gh/lemoeo/AX6S@main/auto_ssh.sh
chmod +x /data/auto_ssh/auto_ssh.sh
/data/auto_ssh/auto_ssh.sh install
uci set system.@system[0].timezone='CST-8'
uci set system.@system[0].webtimezone='CST-8'
uci set system.@system[0].timezoneindex='2.84'
uci commit
mtd erase crash
reboot
```
<img src="/assets/img/pin/unlock-ssh.png" alt="永久启用并固化 SSH" width="60%" />
- ② 最后一行 `reboot` 命令需要手动回车(下同),回车后路由器会重启
**解锁 SSH 成功!**
## 四、 恢复 SSH
> 若已解锁并固化过 SSH 的路由器在升级固件或恢复出厂设置后导致 SSH 丢失,可快速再次解锁 SSH
{: .prompt-tip }
### 1. 计算 Telnet 登录密码
打开网站 <https://miwifi.dev/ssh>,在 SN 处输入路由器背面的 SN 号,点击“Calc”后再点击“Copy”即可复制密码
- 注:复制的密码即 Telnet 和 SSH 登录密码
<img src="/assets/img/pin/caculate-ssh-password.png" alt="计算 Telnet 登录密码" width="60%" />
### 2. 永久启用并固化 SSH
连接 Telnet,执行如下命令:
- 注:最后一行命令是将 Telnet 或 SSH 登录密码设置为 `12345678`,可自定义
```shell
mkdir -p /data/auto_ssh
curl -sS -o /data/auto_ssh/auto_ssh.sh -L https://cdn.jsdelivr.net/gh/lemoeo/AX6S@main/auto_ssh.sh
chmod +x /data/auto_ssh/auto_ssh.sh
/data/auto_ssh/auto_ssh.sh install
echo -e '12345678\n12345678' | passwd root
```
### 3. 更改 Telnet 和 SSH 登录密码(可选)
执行命令 `passwd root`,输入密码如:`12341234`,回车后输入同样的密码,再次回车即可
**恢复 SSH 成功!**
## 五、 ShellCrash 安装和配置
### 1. ShellCrash 安装
- ① 打开 WinSCP,将下载的 ShellCrash.tar.gz 文件移动到路由器的 `/tmp`{: .filepath} 目录中
<img src="/assets/img/pin/move-shellcrash.png" alt="ShellCrash 安装 1" width="60%" />
- ② 连接 SSH 后执行如下命令:
```shell
mkdir -p /tmp/SC_tmp && tar -zxf '/tmp/ShellCrash.tar.gz' -C /tmp/SC_tmp/ && source /tmp/SC_tmp/init.sh
```
- ③ 选择 1 安装到 /data 目录,剩余空间:*.*M
- ④ 根据需要自定义别名(此处选择“2) 【 sc 】”)
- ⑤ 将下载的 mihomo-linux-arm64-[version].gz 文件解压,得到 mihomo-linux-arm64 文件
- ⑥ 将 mihomo-linux-arm64 文件移动到路由器的 `/tmp`{: .filepath} 目录中
<img src="/assets/img/pin/move-mihomo.png" alt="ShellCrash 安装 2" width="60%" />
**安装 ShellCrash 成功!**
### 2. ShellCrash 配置
- ① 连接 SSH 后执行命令 `sc` 即可打开 ShellCrash 配置脚本
- ② 新手引导
- ➊ 选择“1) 路由设备配置局域网透明代理”
- ➋ 根据需要是否启用小内存模式(此处选择“0”)
- ➌ 启用推荐的自动任务配置
- ➍ 根据需要是否开始导入配置文件(此处选择“0”)
- ➎ 此时脚本会自动“发现可用的内核文件”,选择“1) 立即加载”,后选择“1) Mihomo(Meta)”
<img src="/assets/img/pin/import-mihomo.png" alt="ShellCrash 配置 1" width="60%" />
- ➏ 内核加载完成后根据需要是否保留相关数据库文件(此处选择“0) 不保留”)
- ③ 功能设置
- ➊ 进入 ShellCrash 配置脚本 → 2) 功能设置 → 1) 路由模式设置(推荐“混合模式”,其次“Tproxy 模式”,宽带在 300M 内推荐“Tun 模式”)
- 注:使用“Tun 模式”前须进入主菜单 → 8) 工具与优化,启用“8) 小米设备 Tun 模块修复”
- ➋ 进入 2) 功能设置 → 2) DNS 设置(推荐“MIX 模式”)
- ➌ 进入 2) DNS 设置 → 7) DNS 劫持端口,设置为“5353”(须完成《[六、 1](https://proxy-tutorials.dustinwin.us.kg/posts/pin-shellcrashadguardhome-mihomo/#1-adguard-home-%E5%AE%89%E8%A3%85)》后才可设置)
- ➍ 进入 2) DNS 设置 → 9) 修改 DNS 服务器,选择“4) 一键配置加密 DNS”
- 注:推荐设置 DNS 分流(单独使用 ShellCrash 以及 ShellCrash 搭配 AdGuard Home 都适用),请看《[搭载 mihomo 内核进行 DNS 分流教程-geodata 方案](https://proxy-tutorials.dustinwin.us.kg/posts/dnsbypass-mihomo-geodata)》或《[搭载 mihomo 内核进行 DNS 分流教程-ruleset 方案](https://proxy-tutorials.dustinwin.us.kg/posts/dnsbypass-mihomo-ruleset)》
- ➎ 进入 2) 功能设置 → 5) 启用域名嗅探,选择“1) 是”
- ④ 进入主菜单 → 4 启动设置,启用“1) 开机自启动”(若重启路由器后服务没有自动运行,可进入 3) 设置自启延时,设置为“30”秒,然后在《[六、 1. ⑥](https://proxy-tutorials.dustinwin.us.kg//posts/pin-shellcrashadguardhome-mihomo/#1-adguard-home-%E5%AE%89%E8%A3%85)》,将 `sleep 10s` 改为 `sleep 40s`
- ⑤ 进入主菜单 → 5) 自动任务 → 1) 添加自动任务,输入对应的数字并回车后可设置执行条件
- ⑥ 进入主菜单 → 8) 工具与优化,选择“6) 小米设备软固化 SSH”(无需输入需要还原的 SSH 密码)
- ⑦ 进入主菜单 → 9) 更新与支持 → 4) 安装/更新本地 Dashboard 面板,推荐安装“1) 安装 zashboard 面板”
注:
- ➊ 启动服务后,面板 Dashboard 访问链接为:<http://192.168.31.1:9999/ui/>
- ➋ 初次打开需要添加“主机”和“端口”,分别填入 `192.168.31.1` 和 `9999` 并点击“添加”即可访问 Dashboard 面板
<img src="/assets/img/pin/install-dashboard.png" alt="ShellCrash 配置 6" width="60%" />
- ⑧ 导入配置文件
- ➊ 进入主菜单 → 6) 配置文件管理 → a) 添加提供者 → 1) 设置名称或代号,如输入“mihomo”;后进入 2) 设置链接或路径,粘贴你的订阅链接,选择“a) 保存此提供者”
- ➋ 进入 6) 配置文件管理 → c) 在线生成配置文件 → 6) 自定义浏览器 UA,根据需要设置 UA(此处选择“2) 不使用 UA”)
- ➌ 进入 6) 配置文件管理 → 1) mihomo,根据需要选择“b) 本地生成仅包含此提供者的配置文件”或“c) 在线生成仅包含此提供者的配置文件”;选择“e) 在线获取此配置文件”需要一定的 mihomo 知识储备,请查看《[生成带有自定义策略组和规则的 mihomo 配置文件直链-geodata 方案](https://proxy-tutorials.dustinwin.us.kg/posts/link-mihomo-geodata)》或《[生成带有自定义策略组和规则的 mihomo 配置文件直链-ruleset 方案](https://proxy-tutorials.dustinwin.us.kg/posts/link-mihomo-ruleset)》
导入配置文件完成后,选择 1 启动/重启服务
**配置 ShellCrash 成功!**
**ShellCrash 常用命令:**
1. 打开配置:`sc`
2. 启动服务:`$CRASHDIR/start.sh start`
3. 停止服务:`$CRASHDIR/start.sh stop`
4. 重启服务:`$CRASHDIR/start.sh restart`
5. 更新订阅:`$CRASHDIR/task/task.sh update_config`
6. 查看帮助和说明:`sc -h`
### 3. ShellCrash 升级
进入主菜单 → 9) 更新与支持,查看“管理脚本”、“内核文件”和“本地数据库文件”有无新版本,有则选择对应的数字进行升级即可
<img src="/assets/img/pin/update-shellcrash-mihomo.png" alt="ShellCrash 升级" width="60%" />
### 4. ShellCrash 卸载
- ① 通过脚本命令进行卸载(任选一)
连接 SSH 后执行命令 `$CRASHDIR/start.sh stop && sc -u`
- ② 通过 ShellCrash 配置进行卸载(任选一)
进入主菜单 → 9) 更新与支持,选择“8) 卸载 ShellCrash”
## 六 、 AdGuard Home 安装和配置
### 1. AdGuard Home 安装
- ① 将下载的 upx-[version]-win64.zip 文件解压到桌面,目录结构为 `C:\Users\[用户名]\Desktop\upx`{: .filepath}
- ② 将下载的 AdGuardHome_linux_arm64.tar.gz 文件复制到桌面,以管理员身份运行 PowerShell,依次执行如下命令:
```shell
cd C:\Users\[用户名]\Desktop
tar -zxvf AdGuardHome_linux_arm64.tar.gz
```
.tar.gz 压缩文件成功解压到桌面的 `AdGuardHome`{: .filepath} 文件夹内,目录结构为 `C:\Users\[用户名]\Desktop\AdGuardHome`{: .filepath}
- ③ 进入 `AdGuardHome`{: .filepath} 文件夹,将里面的“AdGuardHome”文件移动到 `C:\Users\[用户名]\Desktop\upx`{: .filepath} 文件夹中
依次执行如下命令:
```shell
cd C:\Users\[用户名]\Desktop\upx
.\upx AdGuardHome
```
- ④ 将压缩后的“AdGuardHome”文件移动到路由器的 `/data/AdGuardHome`{: .filepath} 目录(没有此目录就新建)中
<img src="/assets/img/pin/move-adguardhome.png" alt="AdGuard Home 安装 1" width="60%" />
- ⑤ 进入路由器文件管理的 `/data/auto_ssh`{: .filepath} 目录,右击“auto_ssh.sh”文件并点击“编辑”
- 注:若没有此目录和文件,可新建,且须连接 SSH 后执行命令 `chmod +x /data/auto_ssh/auto_ssh.sh`
<img src="/assets/img/pin/edit-task.png" alt="AdGuard Home 安装 2" width="60%" />
> AdGuard Home 的“DNS 服务器端口”须设置为“5353”
{: .prompt-warning }
- ⑥ 在最下方添加如下内容并保存:
- 注: 若 ShellCrash 设置了自启延时如“30”秒,须将 `sleep 10s` 修改为 `sleep 40s`(即 +10s
```shell
sleep 10s
/data/AdGuardHome/AdGuardHome -s install
/data/AdGuardHome/AdGuardHome -s start
iptables -t nat -A PREROUTING -p tcp --dport 53 -j REDIRECT --to-ports 5353
iptables -t nat -A PREROUTING -p udp --dport 53 -j REDIRECT --to-ports 5353
ip6tables -t nat -A PREROUTING -p tcp --dport 53 -j REDIRECT --to-ports 5353
ip6tables -t nat -A PREROUTING -p udp --dport 53 -j REDIRECT --to-ports 5353
```
- ⑦ 连接 SSH 后直接粘贴如下所有命令:
```shell
chmod +x /data/AdGuardHome/AdGuardHome
/data/AdGuardHome/AdGuardHome -s install
/data/AdGuardHome/AdGuardHome -s start
iptables -t nat -A PREROUTING -p tcp --dport 53 -j REDIRECT --to-ports 5353
iptables -t nat -A PREROUTING -p udp --dport 53 -j REDIRECT --to-ports 5353
ip6tables -t nat -A PREROUTING -p tcp --dport 53 -j REDIRECT --to-ports 5353
ip6tables -t nat -A PREROUTING -p udp --dport 53 -j REDIRECT --to-ports 5353
```
**安装 AdGuard Home 成功!**
### 2. AdGuard Home 配置
- ① 引导设置
- ➊ 打开网页 <http://192.168.31.1:3000> 后点击“开始配置”
- ➋ **“网页管理界面端口”输入 `3000`,“DNS 服务器端口”输入“5353”**,点击“下一步”
- ➌ “身份认证”设置用户名和密码
- ➍ 点击“打开仪表盘”后输入刚才设置的用户名和密码“登入”,就可以进入 AdGuard Home 管理页面
- ② 进入设置 → 常规设置,取消勾选“启用日志”并点击“保存”(日志非常占用空间)
- ③ DNS 设置
- ➊ 进入设置 → DNS 设置,“上游 DNS 服务器”设置为 `localhost:1053`,并选择“并行请求”
- 注:此时页面右下角可能会弹出报错信息,但不用理会
<img src="/assets/img/pin/adguardhome-up-dns.png" alt="AdGuard Home 配置 1" width="60%" />
- ➋ “后备 DNS 服务器”设置为:
```text
quic://dns.alidns.com:853
https://doh.pub/dns-query
```
- ➌ “Bootstrap DNS 服务器”设置为:
```text
223.5.5.5
119.29.29.29
```
- ➍ 直接点击“应用”即可
<img src="/assets/img/pin/adguardhome-dns.png" alt="AdGuard Home 配置 2" width="60%" />
- ➎ “速度限制”输入“0”,然后点击下方的“保存”
<img src="/assets/img/pin/adguardhome-dns-service.png" alt="AdGuard Home 配置 3" width="60%" />
- ➏ 勾选“乐观缓存”,并点击“保存”
<img src="/assets/img/pin/adguardhome-cache.png" alt="AdGuard Home 配置 4" width="60%" />
- ④ 进入过滤器 → DNS 黑名单 → 添加黑名单 → 从列表中选择,推荐勾选“区域”里的“CHN: anti-AD”,然后点击“保存”
- 注:若等待 10 分钟仍下载失败,可手动将下载地址 URL 更改为 `https://anti-ad.net/easylist.txt`
<img src="/assets/img/pin/adguardhome-blacklist.png" alt="AdGuard Home 配置 5" width="60%" />
添加成功
<img src="/assets/img/pin/adguardhome-blacklist-success.png" alt="AdGuard Home 配置 6" width="60%" />
**配置 AdGuard Home 成功!**
**AdGuard Home 常用命令:**
1. 启动服务:`/data/AdGuardHome/AdGuardHome -s start`
2. 停止服务:`/data/AdGuardHome/AdGuardHome -s stop`
3. 重启服务:`/data/AdGuardHome/AdGuardHome -s restart`
4. 显示当前服务状态:`/data/AdGuardHome/AdGuardHome -s status`
### 3. AdGuard Home 升级
为了节约路由器内存,请按照如下步骤进行操作:
- ① 执行《[六、 1. ① ② ③ ④(替换)](https://proxy-tutorials.dustinwin.us.kg//posts/pin-shellcrashadguardhome-mihomo/#1-adguard-home-%E5%AE%89%E8%A3%85)》的操作步骤
- ② 连接 SSH 后执行命令 `/data/AdGuardHome/AdGuardHome -s restart`
### 4. AdGuard Home 卸载
- ① 删除开机启动项
执行《[六、 1. ⑥](https://proxy-tutorials.dustinwin.us.kg//posts/pin-shellcrashadguardhome-mihomo/#1-adguard-home-%E5%AE%89%E8%A3%85)》的操作步骤,删除添加的内容:
```shell
sleep 10s
/data/AdGuardHome/AdGuardHome -s install
/data/AdGuardHome/AdGuardHome -s start
iptables -t nat -A PREROUTING -p tcp --dport 53 -j REDIRECT --to-ports 5353
iptables -t nat -A PREROUTING -p udp --dport 53 -j REDIRECT --to-ports 5353
ip6tables -t nat -A PREROUTING -p tcp --dport 53 -j REDIRECT --to-ports 5353
ip6tables -t nat -A PREROUTING -p udp --dport 53 -j REDIRECT --to-ports 5353
```
并保存
- ② 卸载 AdGuard Home
连接 SSH 后直接粘贴如下所有命令:
```shell
/data/AdGuardHome/AdGuardHome -s stop && /data/AdGuardHome/AdGuardHome -s uninstall && rm -rf /data/AdGuardHome
iptables -t nat -A PREROUTING -p tcp --dport 53 -j REDIRECT --to-ports 53
iptables -t nat -A PREROUTING -p udp --dport 53 -j REDIRECT --to-ports 53
ip6tables -t nat -A PREROUTING -p tcp --dport 53 -j REDIRECT --to-ports 53
ip6tables -t nat -A PREROUTING -p udp --dport 53 -j REDIRECT --to-ports 53
```
- ③ 重启路由器
## 七、 效果图
### 1. IPv6 效果
<img src="/assets/img/pin/show-ipv6-1.png" alt="IPv6 效果 1" /><img src="/assets/img/pin/show-ipv6-2.png" alt="IPv6 效果 2" />
### 2. BT 下载效果
UDP 连接正常,使用的是移动 1000M 带宽
<img src="/assets/img/pin/show-bt.png" alt="BT 下载效果" />
### 3. ShellCrash 效果
使用的是移动 1000M 带宽
<img src="/assets/img/pin/show-speedtest.png" alt="ShellCrash 效果" />
### 4. AdGuard Home 效果
<img src="/assets/img/pin/show-adguardhome.png" alt="AdGuard Home 效果" />
@@ -0,0 +1,476 @@
---
title: 全网最详细的解锁 SSH ShellCrash 搭载 sing-boxr 内核搭配 AdGuard Home 安装和配置教程
description: 此教程使用 ShellCrash 搭载 sing-boxr 内核并搭配 AdGuard Home 作下游,配有详细图文
date: 2024-08-21 22:27:53 +0800
categories: [置顶]
tags: [sing-box, sing-boxr, ShellCrash, AdGuard Home, 解锁, SSH]
pin: true
---
> 说明
{: .prompt-tip }
1. 本教程基于 REDMI AX6000 [官方固件](https://www1.miwifi.com/miwifi_download.html) v1.0.70 版,[ShellCrash](https://github.com/juewuy/ShellCrash) v1.9.5 版,[AdGuard Home](https://github.com/AdguardTeam/AdGuardHome) v0.108.0 版编写
2. 恢复 SSH,安装 ShellCrash 和 AdGuard Home 的方法也适用于其它已解锁 SSH 的路由器
3. 安装 [sing-box reF1nd 版内核](https://github.com/reF1nd/sing-box) 内核和 AdGuard Home 时须注意路由器 CPU 架构,查看 CPU 架构可连接 SSH 后执行命令 `uname -ms`,若执行结果是“linux aarch64”,就下载 arm64 版安装包;若是其它架构请下载相匹配的安装包
4. ShellCrash 和 AdGuard Home 中所有没有提到的配置保持默认即可
5. 使用本教程时,不建议启用 ShellCrash 配置脚本 → 2) 功能设置 → 3) 透明路由流量过滤 → 2) 过滤局域网设备,因不经过内核的设备在访问 `漏网之鱼` 域名时会遇到无法访问的情况
6. ShellCrash 和 AdGuard Home 快速安装方法请看《[ShellCrash 和 AdGuard Home 快速安装教程](https://proxy-tutorials.dustinwin.us.kg/posts/pin-toolsinstall)》
## 一、 资源下载
打包下载:<https://dustinwinvip.lanzoum.com/b01qd6p3a>
密码:`zyxz`
注:
- ① 没有对文件进行任何处理,请自行操作使用
- ② 不保证实时更新,想用新版请安装后自行升级
- ③ 版本信息请查看打包文件内的 Readme.txt 文本
### 1. ShellCrash
官方下载:<https://raw.githubusercontent.com/juewuy/ShellCrash/master/ShellCrash.tar.gz>
### 2. sing-box reF1nd 版内核
第三方下载:<https://github.com/DustinWin/proxy-tools/releases/tag/sing-box>
下载 sing-box-ref1nd-stable-linux-armv8.upx 文件
### 3. PuTTY
官方下载:<https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html>
下载 putty-64bit-[version]-installer.msi 文件
### 4. AdGuard Home
官方下载:<https://github.com/AdguardTeam/AdGuardHome/releases>
下载 AdGuardHome_linux_arm64.tar.gz 文件
### 5. UPX
官方下载:<https://github.com/upx/upx/releases>
下载 upx-[version]-win64.zip 文件
### 6. WinSCP
官方下载:<https://winscp.net/eng/downloads.php>
下载 WinSCP-[version]-Setup.exe 文件
## 二、 添加 SSH 支持
### 1. 给 Windows 操作系统添加 SSH 支持(任选一)
- ① 启用 Telnet 客户端
- ➊ 进入设置 → 系统 → 可选功能 → 更多 Windows 功能,勾选“Telnet Client”并点击“确定”
<img src="/assets/img/pin/add-windows-telnet-1.png" alt="启用 Telnet 客户端 1" width="60%" />
- ➋ 点击“让 Windows 更新为你下载文件”
<img src="/assets/img/pin/add-windows-telnet-2.png" alt="启用 Telnet 客户端 2" width="60%" />
- ② 添加 OpenSSH 客户端和 OpenSSH 服务器
- ➊ 进入设置 → 系统 → 可选功能 → 查看功能,搜索“ssh”,在搜索结果中勾选“OpenSSH 客户端”和“OpenSSH 服务器”并点击“下一步”
<img src="/assets/img/pin/add-windows-openssh-1.png" alt="启用 OpenSSH 服务器 1" width="60%" />
- ➋ 点击“添加”
<img src="/assets/img/pin/add-windows-openssh-2.png" alt="启用 OpenSSH 服务器 2" width="60%" />
> 在成功完成《[三、 2](https://proxy-tutorials.dustinwin.us.kg/posts/pin-shellcrashadguardhome-singboxr/#2-%E6%B0%B8%E4%B9%85%E5%BC%80%E5%90%AF-telnet)》后才能进行此操作
{: .prompt-warning }
- ③ 连接 Telnet
- ➊ 以管理员身份运行 PowerShell 或 CMD,执行命令 `telnet 192.168.31.1`
- 注:首次登录不需要用户名和密码,解锁或恢复 SSH 后用户名为 `root`,密码为《[三、 3](https://proxy-tutorials.dustinwin.us.kg/posts/pin-shellcrashadguardhome-singboxr/#3-%E6%B0%B8%E4%B9%85%E5%BC%80%E5%90%AF%E5%B9%B6%E5%9B%BA%E5%8C%96-ssh)》中设置的登录密码
<img src="/assets/img/pin/connect-telnet-windows-1.png" alt="连接 Telnet 1" width="60%" />
- ➋ 输入密码 `12345678`(输入时密码不可见,下同)并回车,显示“ARE U OK”表示成功连接 Telnet
<img src="/assets/img/pin/connect-telnet-windows-2.png" alt="连接 Telnet 2" width="60%" />
> 在成功完成《[三、 3](https://proxy-tutorials.dustinwin.us.kg/posts/pin-shellcrashadguardhome-singboxr/#3-%E6%B0%B8%E4%B9%85%E5%BC%80%E5%90%AF%E5%B9%B6%E5%9B%BA%E5%8C%96-ssh)》后才能进行此操作
{: .prompt-warning }
- ④ 连接 SSH
- ➊ 以管理员身份运行 PowerShell 或 CMD,执行命令 `ssh -oHostKeyAlgorithms=+ssh-rsa [email protected]` 以允许 SSH 客户端接受“ssh-rsa”密钥,输入 `yes` 并回车
- 注:若当前电脑登录过 SSH,后路由器经过重新解锁或恢复 SSH,须进入 `C:\Users\[用户名]\.ssh`{: .filepath} 文件夹,删除“known_hosts”文件,否则登录会报错
<img src="/assets/img/pin/connect-ssh-windows-1.png" alt="连接 SSH 1" width="60%" />
- ➋ 输入密码 `12345678` 并回车
<img src="/assets/img/pin/connect-ssh-windows-2.png" alt="连接 SSH 2" width="60%" />
- ➌ 显示“ARE U OK”表示成功登录 SSH
<img src="/assets/img/pin/connect-ssh-windows-3.png" alt="连接 SSH 3" width="60%" />
### 2. 通过 SSH 工具添加 SSH 支持(任选一)
> 在成功完成《[三、 2](https://proxy-tutorials.dustinwin.us.kg/posts/pin-shellcrashadguardhome-singboxr/#2-%E6%B0%B8%E4%B9%85%E5%BC%80%E5%90%AF-telnet)》后才能进行此操作
{: .prompt-warning }
- ① 连接 Telnet
- ➊ 安装 PuTTY 并打开,按图输入和选择,点击“Open”即可成功连接 Telnet
<img src="/assets/img/pin/connect-telnet-1.png" alt="连接 Telnet 1" width="60%" />
- ➋ 显示“ARE U OK”表示成功登录 Telnet
<img src="/assets/img/pin/connect-telnet-2.png" alt="连接和添加 Telnet 2" width="60%" />
> 在成功完成《[三、 3](https://proxy-tutorials.dustinwin.us.kg/posts/pin-shellcrashadguardhome-singboxr/#3-%E6%B0%B8%E4%B9%85%E5%BC%80%E5%90%AF%E5%B9%B6%E5%9B%BA%E5%8C%96-ssh)》后才能进行此操作
{: .prompt-warning }
- ② 连接 SSH
- ➊ 打开 PuTTY,然后按图输入,点击“Open”即可成功连接 SSH
<img src="/assets/img/pin/connect-ssh-1.png" alt="连接和添加 SSH 1" width="60%" />
- ➋ “login as”输入“root”并回车,“password”为解锁或恢复 SSH 时设置的密码,输入后再次回车,显示“ARE U OK”表示成功连接 SSH
<img src="/assets/img/pin/connect-ssh-2.png" alt="连接和添加 SSH 2" width="60%" />
### 3. 通过 WinSCP 连接路由器文件管理
> 在成功完成《[三、 3](https://proxy-tutorials.dustinwin.us.kg/posts/pin-shellcrashadguardhome-singboxr/#3-%E6%B0%B8%E4%B9%85%E5%BC%80%E5%90%AF%E5%B9%B6%E5%9B%BA%E5%8C%96-ssh)》后才能进行此操作
{: .prompt-warning }
- ① 安装 WinSCP 并打开,“文件协议”选择“SCP”,其它按图输入,“密码”为 SSH 登录密码,点击“保存”后再点击“登录”
<img src="/assets/img/pin/login-winscp.png" alt="通过 WinSCP 连接路由器文件管理 1" width="60%" />
- ② 左侧为电脑本地文件,右侧为路由器文件
<img src="/assets/img/pin/show-winscp.png" alt="通过 WinSCP 连接路由器文件管理 2" width="60%" />
---
>配置免密码连接 SSH 和 WinSCP
{: .prompt-tip }
1. 配置免密码连接 SSH
- ① 打开 PuTTYgen,直接点击“Generate”(期间鼠标必须在此窗口内不停移动)
<img src="/assets/img/pin/puttygen-generate.png" alt="生成 key" width="60%" />
- ② 生成后复制完整的“Key”值备用,点击“Save private key”(可在“Key comment”输入 `[email protected] - REDMI AX6000`
<img src="/assets/img/pin/puttygen-save.png" alt="保存 key" width="60%" />
- ③ “保存”文件到 `C:\Users\[用户名]\.ssh\rsa_key.ppk`{: .filepath} 中
- ④ 打开 PuTTY,进入 Connection → SSH → Auth → Credentials,点击“Private key file for authentication”的“Browser”,定位到 `C:\Users\[用户名]\.ssh\rsa_key.ppk`{: .filepath} 文件并“打开”
- ⑤ 进入 Connections → Data,“Auto-login username”输入 `root`
<img src="/assets/img/pin/putty-setting-1.png" alt="设置登录用户名" width="60%" />
- ⑥ 进入 Session,按图输入后,**先点击“Default Settings”,后点击“Save”**
<img src="/assets/img/pin/putty-setting-2.png" alt="保存配置" width="60%" />
2. 配置免密码连接 WinSCP
- ① 打开 WinSCP,进入标签页 → 站点 → 站点管理器,点击“编辑”,删除密码后点击“高级”
- ② 进入 SSH → 验证,点击“密钥文件”的“...”图标,定位到 `C:\Users\[用户名]\.ssh\rsa_key.ppk`{: .filepath} 文件并“打开”,点击“确定”,再点击“保存”
3. 导入 Key 并加入开机启动
连接 SSH,执行如下命令:
- 注:将《1. ②》中复制的 Key 值替换下面命令中的 `{key}`
```shell
echo "{key}" > /data/auto_ssh/authorized_keys
chmod 600 /data/auto_ssh/authorized_keys
ln -sf /data/auto_ssh/authorized_keys /etc/dropbear/
echo -e "\nln -sf /data/auto_ssh/authorized_keys /etc/dropbear/" >> /data/auto_ssh/auto_ssh.sh
```
---
## 三、 解锁 SSH
### 1. 启用调试模式
- ① 进入路由器管理页面 <http://192.168.31.1>,登录后复制地址栏中的 stok 值
<img src="/assets/img/pin/copy-stok.png" alt="复制 stok 值" width="60%" />
- ② 将复制的 stok 值替换如下网址的 `{stok}` 并访问:
```text
http://192.168.31.1/cgi-bin/luci/;stok={stok}/api/misystem/set_sys_time?timezone=%20%27%20%3B%20zz%3D%24%28dd%20if%3D%2Fdev%2Fzero%20bs%3D1%20count%3D2%202%3E%2Fdev%2Fnull%29%20%3B%20printf%20%27%A5%5A%25c%25c%27%20%24zz%20%24zz%20%7C%20mtd%20write%20-%20crash%20%3B%20
```
网页内容显示 `{"code":0}` 表示成功启用调试模式
- ③ 继续将复制的 stok 值替换如下网址的 `{stok}` 并访问:
```text
http://192.168.31.1/cgi-bin/luci/;stok={stok}/api/misystem/set_sys_time?timezone=%20%27%20%3b%20reboot%20%3b%20
```
网页内容显示 `{"code":0}`,此时路由器会重启
### 2. 永久启用 Telnet
- ① 重启完成后进入路由器管理页面并登录,再次复制 stok 值
- ② 将复制的 stok 值替换如下网址的 `{stok}` 并访问:
```text
http://192.168.31.1/cgi-bin/luci/;stok={stok}/api/misystem/set_sys_time?timezone=%20%27%20%3B%20bdata%20set%20telnet_en%3D1%20%3B%20bdata%20set%20ssh_en%3D1%20%3B%20bdata%20set%20uart_en%3D1%20%3B%20bdata%20commit%20%3B%20
```
网页内容显示 `{"code":0}` 表示成功设置 Bdata 永久启用 Telnet
- ③ 继续将复制的 stok 值替换如下网址的 `{stok}` 并访问:
```text
http://192.168.31.1/cgi-bin/luci/;stok={stok}/api/misystem/set_sys_time?timezone=%20%27%20%3b%20reboot%20%3b%20
```
网页内容显示 `{"code":0}`,此时路由器会再次重启
**启用 Telnet 成功!**
### 3. 永久启用并固化 SSH
- ① 连接 Telnet,执行如下命令:
- 注:第一行命令是将 Telnet 和 SSH 登录密码设置为 `12345678`,可自定义
```shell
echo -e '12345678\n12345678' | passwd root
nvram set telnet_en=1
nvram set ssh_en=1
nvram set uart_en=1
nvram set boot_wait=on
nvram commit
/etc/init.d/dropbear enable & /etc/init.d/dropbear start
mkdir -p /data/auto_ssh
curl -sS -o /data/auto_ssh/auto_ssh.sh -L https://cdn.jsdelivr.net/gh/lemoeo/AX6S@main/auto_ssh.sh
chmod +x /data/auto_ssh/auto_ssh.sh
/data/auto_ssh/auto_ssh.sh install
uci set system.@system[0].timezone='CST-8'
uci set system.@system[0].webtimezone='CST-8'
uci set system.@system[0].timezoneindex='2.84'
uci commit
mtd erase crash
reboot
```
<img src="/assets/img/pin/unlock-ssh.png" alt="永久启用并固化 SSH" width="60%" />
- ② 最后一行 `reboot` 命令需要手动回车(下同),回车后路由器会重启
**解锁 SSH 成功!**
## 四、 恢复 SSH
> 若已解锁并固化过 SSH 的路由器在升级固件或恢复出厂设置后导致 SSH 丢失,可快速再次解锁 SSH
{: .prompt-tip }
### 1. 计算 Telnet 登录密码
打开网站 <https://miwifi.dev/ssh>,在 SN 处输入路由器背面的 SN 号,点击“Calc”后再点击“Copy”即可复制密码
- 注:复制的密码即 Telnet 和 SSH 登录密码
<img src="/assets/img/pin/caculate-ssh-password.png" alt="计算 Telnet 登录密码" width="60%" />
### 2. 永久启用并固化 SSH
连接 Telnet,执行如下命令:
- 注:最后一行命令是将 Telnet 或 SSH 登录密码设置为 `12345678`,可自定义
```shell
mkdir -p /data/auto_ssh
curl -sS -o /data/auto_ssh/auto_ssh.sh -L https://cdn.jsdelivr.net/gh/lemoeo/AX6S@main/auto_ssh.sh
chmod +x /data/auto_ssh/auto_ssh.sh
/data/auto_ssh/auto_ssh.sh install
echo -e '12345678\n12345678' | passwd root
```
### 3. 更改 Telnet 和 SSH 登录密码(可选)
执行命令 `passwd root`,输入密码如:`12341234`,回车后输入同样的密码,再次回车即可
**恢复 SSH 成功!**
## 五、 ShellCrash 安装和配置
### 1. ShellCrash 安装
- ① 打开 WinSCP,将下载的 ShellCrash.tar.gz 文件移动到路由器的 `/tmp`{: .filepath} 目录中
<img src="/assets/img/pin/move-shellcrash.png" alt="ShellCrash 安装 1" width="60%" />
- ② 连接 SSH 后执行如下命令:
```shell
mkdir -p /tmp/SC_tmp && tar -zxf '/tmp/ShellCrash.tar.gz' -C /tmp/SC_tmp/ && source /tmp/SC_tmp/init.sh
```
- ③ 选择 1 安装到 /data 目录,剩余空间:*.*M
- ④ 根据需要自定义别名(此处选择“2) 【 sc 】”)
- ⑤ 将下载的 sing-box-ref1nd-dev-linux-armv8.upx 文件到路由器的 `/tmp`{: .filepath} 目录中
<img src="/assets/img/pin/move-sing-boxr.png" alt="ShellCrash 安装 2" width="60%" />
**安装 ShellCrash 成功!**
### 2. ShellCrash 配置
- ① 连接 SSH 后执行命令 `sc` 即可打开 ShellCrash 配置脚本
- ② 新手引导
- ➊ 选择“1) 路由设备配置局域网透明代理”
- ➋ 根据需要是否启用小内存模式(此处选择“0”)
- ➌ 启用推荐的自动任务配置
- ➍ 根据需要是否开始导入配置文件(此处选择“0”)
- ➎ 此时脚本会自动“发现可用的内核文件”,选择“1) 立即加载”,后选择“2) Singbox-reF1nd”
<img src="/assets/img/pin/import-sing-boxr.png" alt="ShellCrash 配置 1" width="60%" />
- ➏ 内核加载完成后根据需要是否保留相关数据库文件(此处选择“0) 不保留”)
- ③ 功能设置
- ➊ 进入 ShellCrash 配置脚本 → 2) 功能设置 → 1) 路由模式设置(推荐“混合模式”,其次“Tproxy 模式”,宽带在 300M 内推荐“Tun 模式”)
- 注:使用“Tun 模式”前须进入主菜单 → 8) 工具与优化,启用“8) 小米设备 Tun 模块修复”
- ➋ 进入 2) 功能设置 → 2) DNS 设置(推荐“MIX 模式”)
- ➌ 进入 2) DNS 设置 → 7) DNS 劫持端口,设置为“5353”(须完成《[六、 1](https://proxy-tutorials.dustinwin.us.kg/posts/pin-shellcrashadguardhome-singboxr/#1-adguard-home-%E5%AE%89%E8%A3%85)》后才可设置)
- ➍ 进入 2) DNS 设置 → 9) 修改 DNS 服务器,选择“4) 一键配置加密 DNS”
- 注:推荐设置 DNS 分流(单独使用 ShellCrash 以及 ShellCrash 搭配 AdGuard Home 都适用),请看《[搭载 sing-boxr 内核进行 DNS 分流教程-ruleset 方案](https://proxy-tutorials.dustinwin.us.kg/posts/dnsbypass-singboxr-ruleset)》
- ④ 进入主菜单 → 4 启动设置,启用“1) 开机自启动”(若重启路由器后服务没有自动运行,可进入 3) 设置自启延时,设置为“30”秒,然后在《[六、 1. ⑥](https://proxy-tutorials.dustinwin.us.kg//posts/pin-shellcrashadguardhome-mihomo/#1-adguard-home-%E5%AE%89%E8%A3%85)》,将 `sleep 10s` 改为 `sleep 40s`
- ⑤ 进入主菜单 → 5) 自动任务 → 1) 添加自动任务,输入对应的数字并回车后可设置执行条件
- ⑥ 进入主菜单 → 8) 工具与优化,选择“6) 小米设备软固化 SSH”(无需输入需要还原的 SSH 密码)
- ⑦ 进入主菜单 → 9) 更新与支持 → 4) 安装/更新本地 Dashboard 面板,推荐安装“1) 安装 zashboard 面板”
注:
- ➊ 启动服务后,面板 Dashboard 访问链接为:<http://192.168.31.1:9999/ui/>
- ➋ 初次打开需要添加“主机”和“端口”,分别填入 `192.168.31.1` 和 `9999` 并点击“添加”即可访问 Dashboard 面板
<img src="/assets/img/pin/install-dashboard.png" alt="ShellCrash 配置 6" width="60%" />
- ⑧ 导入配置文件
- ➊ 进入主菜单 → 6) 配置文件管理 → a) 添加提供者 → 1) 设置名称或代号,如输入“sing-boxr”;后进入 2) 设置链接或路径,粘贴你的订阅链接,选择“a) 保存此提供者”
- ➋ 进入 6) 配置文件管理 → c) 在线生成配置文件 → 6) 自定义浏览器 UA,根据需要设置 UA(此处选择“2) 不使用 UA”)
- ➌ 进入 6) 配置文件管理 → 1) sing-boxr,根据需要选择“b) 本地生成仅包含此提供者的配置文件”或“c) 在线生成仅包含此提供者的配置文件”;选择“e) 在线获取此配置文件”需要一定的 sing-boxr 知识储备,请查看《[生成带有自定义出站和规则的 sing-boxr 配置文件直链-ruleset 方案](https://proxy-tutorials.dustinwin.us.kg/posts/link-singboxr-ruleset/)》
导入配置文件完成后,选择 1 启动/重启服务
**配置 ShellCrash 成功!**
**ShellCrash 常用命令:**
1. 打开配置:`sc`
2. 启动服务:`$CRASHDIR/start.sh start`
3. 停止服务:`$CRASHDIR/start.sh stop`
4. 重启服务:`$CRASHDIR/start.sh restart`
5. 更新订阅:`$CRASHDIR/task/task.sh update_config`
6. 查看帮助和说明:`sc -h`
### 3. ShellCrash 升级
进入主菜单 → 9) 更新与支持,查看“管理脚本”、“内核文件”和“本地数据库文件”有无新版本,有则选择对应的数字进行升级即可
<img src="/assets/img/pin/update-shellcrash-singboxr.png" alt="ShellCrash 升级" width="60%" />
### 4. ShellCrash 卸载
- ① 通过脚本命令进行卸载(任选一)
连接 SSH 后执行命令 `$CRASHDIR/start.sh stop && sc -u`
- ② 通过 ShellCrash 配置进行卸载(任选一)
进入主菜单 → 9) 更新与支持,选择“8) 卸载 ShellCrash”
## 六 、 AdGuard Home 安装和配置
### 1. AdGuard Home 安装
- ① 将下载的 upx-[version]-win64.zip 文件解压到桌面,目录结构为 `C:\Users\[用户名]\Desktop\upx`{: .filepath}
- ② 将下载的 AdGuardHome_linux_arm64.tar.gz 文件复制到桌面,以管理员身份运行 PowerShell,依次执行如下命令:
```shell
cd C:\Users\[用户名]\Desktop
tar -zxvf AdGuardHome_linux_arm64.tar.gz
```
.tar.gz 压缩文件成功解压到桌面的 `AdGuardHome`{: .filepath} 文件夹内,目录结构为 `C:\Users\[用户名]\Desktop\AdGuardHome`{: .filepath}
- ③ 进入 `AdGuardHome`{: .filepath} 文件夹,将里面的“AdGuardHome”文件移动到 `C:\Users\[用户名]\Desktop\upx`{: .filepath} 文件夹中
依次执行如下命令:
```shell
cd C:\Users\[用户名]\Desktop\upx
.\upx AdGuardHome
```
- ④ 将压缩后的“AdGuardHome”文件移动到路由器的 `/data/AdGuardHome`{: .filepath} 目录(没有此目录就新建)中
<img src="/assets/img/pin/move-adguardhome.png" alt="AdGuard Home 安装 1" width="60%" />
- ⑤ 进入路由器文件管理的 `/data/auto_ssh`{: .filepath} 目录,右击“auto_ssh.sh”文件并点击“编辑”
- 注:若没有此目录和文件,可新建,且须连接 SSH 后执行命令 `chmod +x /data/auto_ssh/auto_ssh.sh`
<img src="/assets/img/pin/edit-task.png" alt="AdGuard Home 安装 2" width="60%" />
> AdGuard Home 的“DNS 服务器端口”须设置为“5353”
{: .prompt-warning }
- ⑥ 在最下方添加如下内容并保存:
- 注: 若 ShellCrash 设置了自启延时如“30”秒,须将 `sleep 10s` 修改为 `sleep 40s`(即 +10s
```shell
sleep 10s
/data/AdGuardHome/AdGuardHome -s install
/data/AdGuardHome/AdGuardHome -s start
iptables -t nat -A PREROUTING -p tcp --dport 53 -j REDIRECT --to-ports 5353
iptables -t nat -A PREROUTING -p udp --dport 53 -j REDIRECT --to-ports 5353
ip6tables -t nat -A PREROUTING -p tcp --dport 53 -j REDIRECT --to-ports 5353
ip6tables -t nat -A PREROUTING -p udp --dport 53 -j REDIRECT --to-ports 5353
```
- ⑦ 连接 SSH 后直接粘贴如下所有命令:
```shell
chmod +x /data/AdGuardHome/AdGuardHome
/data/AdGuardHome/AdGuardHome -s install
/data/AdGuardHome/AdGuardHome -s start
iptables -t nat -A PREROUTING -p tcp --dport 53 -j REDIRECT --to-ports 5353
iptables -t nat -A PREROUTING -p udp --dport 53 -j REDIRECT --to-ports 5353
ip6tables -t nat -A PREROUTING -p tcp --dport 53 -j REDIRECT --to-ports 5353
ip6tables -t nat -A PREROUTING -p udp --dport 53 -j REDIRECT --to-ports 5353
```
**安装 AdGuard Home 成功!**
### 2. AdGuard Home 配置
- ① 引导设置
- ➊ 打开网页 <http://192.168.31.1:3000> 后点击“开始配置”
- ➋ **“网页管理界面端口”输入 `3000`,“DNS 服务器端口”输入“5353”**,点击“下一步”
- ➌ “身份认证”设置用户名和密码
- ➍ 点击“打开仪表盘”后输入刚才设置的用户名和密码“登入”,就可以进入 AdGuard Home 管理页面
- ② 进入设置 → 常规设置,取消勾选“启用日志”并点击“保存”(日志非常占用空间)
- ③ DNS 设置
- ➊ 进入设置 → DNS 设置,“上游 DNS 服务器”设置为 `localhost:1053`,并选择“并行请求”
- 注:此时页面右下角可能会弹出报错信息,但不用理会
<img src="/assets/img/pin/adguardhome-up-dns.png" alt="AdGuard Home 配置 1" width="60%" />
- ➋ “后备 DNS 服务器”设置为:
```text
quic://dns.alidns.com:853
https://doh.pub/dns-query
```
- ➌ “Bootstrap DNS 服务器”设置为:
```text
223.5.5.5
119.29.29.29
```
- ➍ 直接点击“应用”即可
<img src="/assets/img/pin/adguardhome-dns.png" alt="AdGuard Home 配置 2" width="60%" />
- ➎ “速度限制”输入“0”,然后点击下方的“保存”
<img src="/assets/img/pin/adguardhome-dns-service.png" alt="AdGuard Home 配置 3" width="60%" />
- ➏ 勾选“乐观缓存”,并点击“保存”
<img src="/assets/img/pin/adguardhome-cache.png" alt="AdGuard Home 配置 4" width="60%" />
- ④ 进入过滤器 → DNS 黑名单 → 添加黑名单 → 从列表中选择,推荐勾选“区域”里的“CHN: anti-AD”,然后点击“保存”
- 注:若等待 10 分钟仍下载失败,可手动将下载地址 URL 更改为 `https://anti-ad.net/easylist.txt`
<img src="/assets/img/pin/adguardhome-blacklist.png" alt="AdGuard Home 配置 5" width="60%" />
添加成功
<img src="/assets/img/pin/adguardhome-blacklist-success.png" alt="AdGuard Home 配置 6" width="60%" />
**配置 AdGuard Home 成功!**
**AdGuard Home 常用命令:**
1. 启动服务:`/data/AdGuardHome/AdGuardHome -s start`
2. 停止服务:`/data/AdGuardHome/AdGuardHome -s stop`
3. 重启服务:`/data/AdGuardHome/AdGuardHome -s restart`
4. 显示当前服务状态:`/data/AdGuardHome/AdGuardHome -s status`
### 3. AdGuard Home 升级
为了节约路由器内存,请按照如下步骤进行操作:
- ① 执行《[六、 1. ① ② ③ ④(替换)](https://proxy-tutorials.dustinwin.us.kg//posts/pin-shellcrashadguardhome-singboxr/#1-adguard-home-%E5%AE%89%E8%A3%85)》的操作步骤
- ② 连接 SSH 后执行命令 `/data/AdGuardHome/AdGuardHome -s restart`
### 4. AdGuard Home 卸载
- ① 删除开机启动项
执行《[六、 1. ⑥](https://proxy-tutorials.dustinwin.us.kg//posts/pin-shellcrashadguardhome-singboxr/#1-adguard-home-%E5%AE%89%E8%A3%85)》的操作步骤,删除添加的内容:
```shell
sleep 10s
/data/AdGuardHome/AdGuardHome -s install
/data/AdGuardHome/AdGuardHome -s start
iptables -t nat -A PREROUTING -p tcp --dport 53 -j REDIRECT --to-ports 5353
iptables -t nat -A PREROUTING -p udp --dport 53 -j REDIRECT --to-ports 5353
ip6tables -t nat -A PREROUTING -p tcp --dport 53 -j REDIRECT --to-ports 5353
ip6tables -t nat -A PREROUTING -p udp --dport 53 -j REDIRECT --to-ports 5353
```
并保存
- ② 卸载 AdGuard Home
连接 SSH 后直接粘贴如下所有命令:
```shell
/data/AdGuardHome/AdGuardHome -s stop && /data/AdGuardHome/AdGuardHome -s uninstall && rm -rf /data/AdGuardHome
iptables -t nat -A PREROUTING -p tcp --dport 53 -j REDIRECT --to-ports 53
iptables -t nat -A PREROUTING -p udp --dport 53 -j REDIRECT --to-ports 53
ip6tables -t nat -A PREROUTING -p tcp --dport 53 -j REDIRECT --to-ports 53
ip6tables -t nat -A PREROUTING -p udp --dport 53 -j REDIRECT --to-ports 53
```
- ③ 重启路由器
## 七、 效果图
### 1. IPv6 效果
<img src="/assets/img/pin/show-ipv6-1.png" alt="IPv6 效果 1" /><img src="/assets/img/pin/show-ipv6-2.png" alt="IPv6 效果 2" />
### 2. BT 下载效果
UDP 连接正常,使用的是移动 1000M 带宽
<img src="/assets/img/pin/show-bt.png" alt="BT 下载效果" />
### 3. ShellCrash 效果
使用的是移动 1000M 带宽
<img src="/assets/img/pin/show-speedtest.png" alt="ShellCrash 效果" />
### 4. AdGuard Home 效果
<img src="/assets/img/pin/show-adguardhome.png" alt="AdGuard Home 效果" />
+156
View File
@@ -0,0 +1,156 @@
---
title: ShellCrash 和 AdGuard Home 快速安装教程
description: 此教程包括 ShellCrash、AdGuard Home、mihomo 内核、sing-box 内核和 Dashboard 面板的安装方法
date: 2024-08-21 17:13:12 +0800
categories: [置顶]
tags: [ShellCrash, AdGuard Home, mihomo, sing-box, sing-boxr, 安装, Dashboard]
pin: true
---
> 说明
{: .prompt-tip }
1. 本教程中 **[AdGuard Home](https://github.com/AdguardTeam/AdGuardHome) 安装目录为 `/data/AdGuardHome`{: .filepath}**
2. 本教程中的下载链接以 CPU 架构 ARM64 为例,请注意修改链接后缀
3. 查看 CPU 架构可连接 SSH 后执行命令 `uname -ms`,若执行结果是“linux aarch64”,就是搭载的 ARM64 架构
4. 以下所有命令均可全部复制后直接粘贴执行(若出现无法下载的情况,可更换[下载源](https://proxy-tutorials.dustinwin.us.kg/about/#%E5%AF%B9%E4%B8%8B%E8%BD%BD%E6%BA%90%E7%9A%84%E8%AF%B4%E6%98%8E)
## 一、 安装 [ShellCrash](https://github.com/juewuy/ShellCrash)
### 1. 本地安装
连接 SSH 后执行如下命令:
```shell
curl -sS -o /tmp/ShellCrash.tar.gz -L https://cdn.jsdelivr.net/gh/juewuy/ShellCrash@master/ShellCrash.tar.gz
mkdir -p /tmp/SC_tmp/ && tar -zxf '/tmp/ShellCrash.tar.gz' -C /tmp/SC_tmp/ && source /tmp/SC_tmp/init.sh
```
### 2. 在线安装
连接 SSH 后执行如下命令:
```shell
export url='https://cdn.jsdelivr.net/gh/juewuy/ShellCrash@master' && sh -c "$(curl -kfsSl $url/install.sh)" && . /etc/profile &> /dev/null
```
## 二、 导入 [mihomo 内核](https://github.com/MetaCubeX/mihomo) 或 [sing-box 内核](https://github.com/SagerNet/sing-box)
### 1. 首次导入
连接 SSH 后执行如下命令:
```shell
# mihomo 内核 Meta 版
curl -sS -o /tmp/CrashCore.upx -L https://ghfast.top/https://github.com/DustinWin/proxy-tools/releases/download/mihomo/mihomo-meta-linux-arm64.upx && sc
# mihomo 内核 Alpha 版
curl -sS -o /tmp/CrashCore.upx -L https://ghfast.top/https://github.com/DustinWin/proxy-tools/releases/download/mihomo/mihomo-alpha-linux-arm64.upx && sc
# sing-box 内核 reF1nd-Stable 版
curl -sS -o /tmp/CrashCore.upx -L https://ghfast.top/https://github.com/DustinWin/proxy-tools/releases/download/sing-box/sing-box-ref1nd-stable-linux-arm64.upx && sc
# sing-box 内核 reF1nd-Testing 版
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 && sc
# sing-box 内核 Stable 版
curl -sS -o /tmp/CrashCore.upx -L https://ghfast.top/https://github.com/DustinWin/proxy-tools/releases/download/sing-box/sing-box-stable-linux-arm64.upx && sc
# sing-box 内核 Testing 版
curl -sS -o /tmp/CrashCore.upx -L https://ghfast.top/https://github.com/DustinWin/proxy-tools/releases/download/sing-box/sing-box-testing-linux-arm64.upx && sc
```
此时脚本会自动“发现可用的内核文件”,选择 1 加载,后选择对应的内核类型
### 2. 升级导入(ShellCrash → 9 更新/卸载 → 2 切换内核文件,内核版本不会刷新)
连接 SSH 后执行如下命令:
```shell
# mihomo 内核 Meta 版
curl -sS -o $CRASHDIR/CrashCore.upx -L https://ghfast.top/https://github.com/DustinWin/proxy-tools/releases/download/mihomo/mihomo-meta-linux-arm64.upx && $CRASHDIR/start.sh restart
# mihomo 内核 Alpha 版
curl -sS -o $CRASHDIR/CrashCore.upx -L https://ghfast.top/https://github.com/DustinWin/proxy-tools/releases/download/mihomo/mihomo-alpha-linux-arm64.upx && $CRASHDIR/start.sh restart
# sing-box 内核 reF1nd-Stable 版
curl -sS -o $CRASHDIR/CrashCore.upx -L https://ghfast.top/https://github.com/DustinWin/proxy-tools/releases/download/sing-box/sing-box-ref1nd-stable-linux-arm64.upx && $CRASHDIR/start.sh restart
# sing-box 内核 reF1nd-Testing 版
curl -sS -o $CRASHDIR/CrashCore.upx -L https://ghfast.top/https://github.com/DustinWin/proxy-tools/releases/download/sing-box/sing-box-ref1nd-testing-linux-arm64.upx && $CRASHDIR/start.sh restart
# sing-box 内核 Stable 版
curl -sS -o $CRASHDIR/CrashCore.upx -L https://ghfast.top/https://github.com/DustinWin/proxy-tools/releases/download/sing-box/sing-box-stable-linux-arm64.upx && $CRASHDIR/start.sh restart
# sing-box 内核 Testing 版
curl -sS -o $CRASHDIR/CrashCore.upx -L https://ghfast.top/https://github.com/DustinWin/proxy-tools/releases/download/sing-box/sing-box-testing-linux-arm64.upx && $CRASHDIR/start.sh restart
```
## 三、 安装 Dashboard 面板
**Dashboard 面板对应文件名和网址关系如下表:**
| 面板名称 | 文件名 | 网址 |
| ------------------ | --------------------------- | ----------------------------------------- |
| Yacd-meta | `Yacd-meta.tar.gz` | <https://yacd.metacubex.one> |
| metacubexd | `metacubexd.tar.gz` | <https://metacubex.github.io/metacubexd/> |
| zashboard | `zashboard.tar.gz` | <https://board.zash.run.place> |
| sing-box dashboard | `sing-box-dashboard.tar.gz` | <https://sing-box-dashboard.sagernet.org> |
连接 SSH 后执行如下命令:
```shell
# Yacd-meta
curl -sS -L https://ghfast.top/https://github.com/DustinWin/proxy-tools/releases/download/Dashboard/Yacd-meta.tar.gz | tar -zx -C $CRASHDIR/ui/ && $CRASHDIR/start.sh restart
# metacubexd
curl -sS -L https://ghfast.top/https://github.com/DustinWin/proxy-tools/releases/download/Dashboard/metacubexd.tar.gz | tar -zx -C $CRASHDIR/ui/ && $CRASHDIR/start.sh restart
# zashboard
curl -sS -L https://ghfast.top/https://github.com/DustinWin/proxy-tools/releases/download/Dashboard/zashboard.tar.gz | tar -zx -C $CRASHDIR/ui/ && $CRASHDIR/start.sh restart
# sing-box dashboard
curl -sS -L https://ghfast.top/https://github.com/DustinWin/proxy-tools/releases/download/Dashboard/sing-box-dashboard.tar.gz | tar -zx -C $CRASHDIR/ui/ && $CRASHDIR/start.sh restart
```
- 注:若使用基于 [Chromium 项目](https://www.chromium.org/Home/)开发的浏览器无法访问 Dashboard 在线面板时,以 [Chrome 浏览器](https://www.google.com/chrome/)为例,需要设置该网址域名“允许显示不安全内容”。方法如下:
进入设置 → 隐私和安全 → 网站设置 → 更多内容设置 → 不安全内容(或者直接在地址栏打开 chrome://settings/content/insecureContent 进行设置),在“允许显示不安全内容”内添加网址域名如:`board.zash.run.place`
## 四、 安装 AdGuard Home
### 1. 安装 AdGuard Home
连接 SSH 后执行如下命令:
```shell
mkdir -p /data/AdGuardHome/
# AdGuard Home Release 版
curl -sS -o /data/AdGuardHome/AdGuardHome -L https://ghfast.top/https://github.com/DustinWin/proxy-tools/releases/download/AdGuardHome/AdGuardHome_release_linux_arm64
# AdGuard Home Beta 版
curl -sS -o /data/AdGuardHome/AdGuardHome -L https://ghfast.top/https://github.com/DustinWin/proxy-tools/releases/download/AdGuardHome/AdGuardHome_beta_linux_arm64
chmod +x /data/AdGuardHome/AdGuardHome
/data/AdGuardHome/AdGuardHome -s install
/data/AdGuardHome/AdGuardHome -s start
# 将所有发往 53 端口的流量重定向到本地的 5353 端口
iptables -t nat -A PREROUTING -p tcp --dport 53 -j REDIRECT --to-ports 5353
iptables -t nat -A PREROUTING -p udp --dport 53 -j REDIRECT --to-ports 5353
ip6tables -t nat -A PREROUTING -p tcp --dport 53 -j REDIRECT --to-ports 5353
ip6tables -t nat -A PREROUTING -p udp --dport 53 -j REDIRECT --to-ports 5353
# 添加开机启动
cat <<EOF >> /data/auto_ssh/auto_ssh.sh
sleep 10s
/data/AdGuardHome/AdGuardHome -s install
/data/AdGuardHome/AdGuardHome -s start
iptables -t nat -A PREROUTING -p tcp --dport 53 -j REDIRECT --to-ports 5353
iptables -t nat -A PREROUTING -p udp --dport 53 -j REDIRECT --to-ports 5353
ip6tables -t nat -A PREROUTING -p tcp --dport 53 -j REDIRECT --to-ports 5353
ip6tables -t nat -A PREROUTING -p udp --dport 53 -j REDIRECT --to-ports 5353
EOF
```
### 2. 升级 AdGuard Home
- 注:留意链接后缀是否与 CPU 架构匹配
连接 SSH 后执行如下命令:
```shell
# AdGuard Home Release 版
curl -sS -o /data/AdGuardHome/AdGuardHome -L https://ghfast.top/https://github.com/DustinWin/proxy-tools/releases/download/AdGuardHome/AdGuardHome_release_linux_arm64
# AdGuard Home Beta 版
curl -sS -o /data/AdGuardHome/AdGuardHome -L https://ghfast.top/https://github.com/DustinWin/proxy-tools/releases/download/AdGuardHome/AdGuardHome_beta_linux_arm64
/data/AdGuardHome/AdGuardHome -s restart
```
## 五、 扩展(以 ShellCrash 配置定时任务为例)
可在 ShellCrash 里添加定时更新 mihomo 内核、sing-box 内核、[zashboard](https://github.com/Zephyruso/zashboard) 和 AdGuard Home 的任务
1. 连接 SSH 后执行 `vi $CRASHDIR/configs/task/task.user`,按一下 Ins 键(Insert 键),粘贴如下内容:
注:
- ① 留意链接后缀是否与 CPU 架构匹配
- ② 须重启 ShellCrash 和 AdGuard Home 服务后生效
```shell
201#curl -sS -o $CRASHDIR/CrashCore.upx -L https://ghfast.top/https://github.com/DustinWin/proxy-tools/releases/download/mihomo/mihomo-meta-linux-arm64.upx >/dev/null 2>&1#更新mihomo内核
202#curl -sS -o $CRASHDIR/CrashCore.upx -L https://ghfast.top/https://github.com/DustinWin/proxy-tools/releases/download/sing-box/sing-box-ref1nd-stable-linux-arm64.upx >/dev/null 2>&1#更新sing-boxr内核
203#curl -sS -o $CRASHDIR/CrashCore.upx -L https://ghfast.top/https://github.com/DustinWin/proxy-tools/releases/download/sing-box/sing-box-stable-linux-arm64.upx >/dev/null 2>&1#更新sing-box内核
204#curl -sS -L https://ghfast.top/https://github.com/DustinWin/proxy-tools/releases/download/Dashboard/zashboard.tar.gz | tar -zx -C $CRASHDIR/ui/ >/dev/null 2>&1#更新zashboard
205#curl -sS -o /data/AdGuardHome/AdGuardHome -L https://ghfast.top/https://github.com/DustinWin/proxy-tools/releases/download/AdGuardHome/AdGuardHome_beta_linux_arm64 >/dev/null 2>&1#更新AdGuardHome
```
1. 按一下 Esc 键(退出键),输入英文冒号 `:`,继续输入 `wq` 并回车
2. 执行 `sc`,进入 ShellCrash → 5 配置自动任务 → 1 添加自动任务,可以看到末尾就有添加的定时任务,输入对应的数字并回车后可设置执行条件
+156
View File
@@ -0,0 +1,156 @@
---
title: ShellCrash 和 AdGuard Home 快速安装教程
description: 此教程包括 ShellCrash、AdGuard Home、mihomo 内核、sing-box 内核和 Dashboard 面板的安装方法
date: 2024-08-21 17:13:12 +0800
categories: [置顶]
tags: [ShellCrash, AdGuard Home, mihomo, sing-box, sing-boxr, 安装, Dashboard]
pin: true
---
> 说明
{: .prompt-tip }
1. 本教程中 **[AdGuard Home](https://github.com/AdguardTeam/AdGuardHome) 安装目录为 `/data/AdGuardHome`{: .filepath}**
2. 本教程中的下载链接以 CPU 架构 ARM64 为例,请注意修改链接后缀
3. 查看 CPU 架构可连接 SSH 后执行命令 `uname -ms`,若执行结果是“linux aarch64”,就是搭载的 ARM64 架构
4. 以下所有命令均可全部复制后直接粘贴执行(若出现无法下载的情况,可更换[下载源](https://proxy-tutorials.dustinwin.us.kg/about/#%E5%AF%B9%E4%B8%8B%E8%BD%BD%E6%BA%90%E7%9A%84%E8%AF%B4%E6%98%8E)
## 一、 安装 [ShellCrash](https://github.com/juewuy/ShellCrash)
### 1. 本地安装
连接 SSH 后执行如下命令:
```shell
curl -sS -o /tmp/ShellCrash.tar.gz -L https://cdn.jsdelivr.net/gh/juewuy/ShellCrash@master/ShellCrash.tar.gz
mkdir -p /tmp/SC_tmp/ && tar -zxf '/tmp/ShellCrash.tar.gz' -C /tmp/SC_tmp/ && source /tmp/SC_tmp/init.sh
```
### 2. 在线安装
连接 SSH 后执行如下命令:
```shell
export url='https://cdn.jsdelivr.net/gh/juewuy/ShellCrash@master' && sh -c "$(curl -kfsSl $url/install.sh)" && . /etc/profile &> /dev/null
```
## 二、 导入 [mihomo 内核](https://github.com/MetaCubeX/mihomo) 或 [sing-box 内核](https://github.com/SagerNet/sing-box)
### 1. 首次导入
连接 SSH 后执行如下命令:
```shell
# mihomo 内核 Meta 版
curl -sS -o /tmp/CrashCore.upx -L https://ghfast.top/https://github.com/DustinWin/proxy-tools/releases/download/mihomo/mihomo-meta-linux-arm64.upx && sc
# mihomo 内核 Alpha 版
curl -sS -o /tmp/CrashCore.upx -L https://ghfast.top/https://github.com/DustinWin/proxy-tools/releases/download/mihomo/mihomo-alpha-linux-arm64.upx && sc
# sing-box 内核 reF1nd-Stable 版
curl -sS -o /tmp/CrashCore.upx -L https://ghfast.top/https://github.com/DustinWin/proxy-tools/releases/download/sing-box/sing-box-ref1nd-stable-linux-arm64.upx && sc
# sing-box 内核 reF1nd-Testing 版
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 && sc
# sing-box 内核 Stable 版
curl -sS -o /tmp/CrashCore.upx -L https://ghfast.top/https://github.com/DustinWin/proxy-tools/releases/download/sing-box/sing-box-stable-linux-arm64.upx && sc
# sing-box 内核 Testing 版
curl -sS -o /tmp/CrashCore.upx -L https://ghfast.top/https://github.com/DustinWin/proxy-tools/releases/download/sing-box/sing-box-testing-linux-arm64.upx && sc
```
此时脚本会自动“发现可用的内核文件”,选择 1 加载,后选择对应的内核类型
### 2. 升级导入(ShellCrash → 9 更新/卸载 → 2 切换内核文件,内核版本不会刷新)
连接 SSH 后执行如下命令:
```shell
# mihomo 内核 Meta 版
curl -sS -o $CRASHDIR/CrashCore.upx -L https://ghfast.top/https://github.com/DustinWin/proxy-tools/releases/download/mihomo/mihomo-meta-linux-arm64.upx && $CRASHDIR/start.sh restart
# mihomo 内核 Alpha 版
curl -sS -o $CRASHDIR/CrashCore.upx -L https://ghfast.top/https://github.com/DustinWin/proxy-tools/releases/download/mihomo/mihomo-alpha-linux-arm64.upx && $CRASHDIR/start.sh restart
# sing-box 内核 reF1nd-Stable 版
curl -sS -o $CRASHDIR/CrashCore.upx -L https://ghfast.top/https://github.com/DustinWin/proxy-tools/releases/download/sing-box/sing-box-ref1nd-stable-linux-arm64.upx && $CRASHDIR/start.sh restart
# sing-box 内核 reF1nd-Testing 版
curl -sS -o $CRASHDIR/CrashCore.upx -L https://ghfast.top/https://github.com/DustinWin/proxy-tools/releases/download/sing-box/sing-box-ref1nd-testing-linux-arm64.upx && $CRASHDIR/start.sh restart
# sing-box 内核 Stable 版
curl -sS -o $CRASHDIR/CrashCore.upx -L https://ghfast.top/https://github.com/DustinWin/proxy-tools/releases/download/sing-box/sing-box-stable-linux-arm64.upx && $CRASHDIR/start.sh restart
# sing-box 内核 Testing 版
curl -sS -o $CRASHDIR/CrashCore.upx -L https://ghfast.top/https://github.com/DustinWin/proxy-tools/releases/download/sing-box/sing-box-testing-linux-arm64.upx && $CRASHDIR/start.sh restart
```
## 三、 安装 Dashboard 面板
**Dashboard 面板对应文件名和网址关系如下表:**
| 面板名称 | 文件名 | 网址 |
| ------------------ | --------------------------- | ----------------------------------------- |
| Yacd-meta | `Yacd-meta.tar.gz` | <https://yacd.metacubex.one> |
| metacubexd | `metacubexd.tar.gz` | <https://metacubex.github.io/metacubexd/> |
| zashboard | `zashboard.tar.gz` | <https://board.zash.run.place> |
| sing-box dashboard | `sing-box-dashboard.tar.gz` | <https://sing-box-dashboard.sagernet.org> |
连接 SSH 后执行如下命令:
```shell
# Yacd-meta
curl -sS -L https://ghfast.top/https://github.com/DustinWin/proxy-tools/releases/download/Dashboard/Yacd-meta.tar.gz | tar -zx -C $CRASHDIR/ui/ && $CRASHDIR/start.sh restart
# metacubexd
curl -sS -L https://ghfast.top/https://github.com/DustinWin/proxy-tools/releases/download/Dashboard/metacubexd.tar.gz | tar -zx -C $CRASHDIR/ui/ && $CRASHDIR/start.sh restart
# zashboard
curl -sS -L https://ghfast.top/https://github.com/DustinWin/proxy-tools/releases/download/Dashboard/zashboard.tar.gz | tar -zx -C $CRASHDIR/ui/ && $CRASHDIR/start.sh restart
# sing-box dashboard
curl -sS -L https://ghfast.top/https://github.com/DustinWin/proxy-tools/releases/download/Dashboard/sing-box-dashboard.tar.gz | tar -zx -C $CRASHDIR/ui/ && $CRASHDIR/start.sh restart
```
- 注:若使用基于 [Chromium 项目](https://www.chromium.org/Home/)开发的浏览器无法访问在线 Dashboard 面板时,以 [Chrome 浏览器](https://www.google.com/chrome/)为例,需要设置该网址域名“允许显示不安全内容”。方法如下:
进入设置 → 隐私和安全 → 网站设置 → 更多内容设置 → 不安全内容(或者直接在地址栏打开 chrome://settings/content/insecureContent 进行设置),在“允许显示不安全内容”内添加网址域名如:`board.zash.run.place`
## 四、 安装 AdGuard Home
### 1. 安装 AdGuard Home
连接 SSH 后执行如下命令:
```shell
mkdir -p /data/AdGuardHome/
# AdGuard Home Release 版
curl -sS -o /data/AdGuardHome/AdGuardHome -L https://ghfast.top/https://github.com/DustinWin/proxy-tools/releases/download/AdGuardHome/AdGuardHome_release_linux_arm64
# AdGuard Home Beta 版
curl -sS -o /data/AdGuardHome/AdGuardHome -L https://ghfast.top/https://github.com/DustinWin/proxy-tools/releases/download/AdGuardHome/AdGuardHome_beta_linux_arm64
chmod +x /data/AdGuardHome/AdGuardHome
/data/AdGuardHome/AdGuardHome -s install
/data/AdGuardHome/AdGuardHome -s start
# 将所有发往 53 端口的流量重定向到本地的 5353 端口
iptables -t nat -A PREROUTING -p tcp --dport 53 -j REDIRECT --to-ports 5353
iptables -t nat -A PREROUTING -p udp --dport 53 -j REDIRECT --to-ports 5353
ip6tables -t nat -A PREROUTING -p tcp --dport 53 -j REDIRECT --to-ports 5353
ip6tables -t nat -A PREROUTING -p udp --dport 53 -j REDIRECT --to-ports 5353
# 添加开机启动
cat <<EOF >> /data/auto_ssh/auto_ssh.sh
sleep 10s
/data/AdGuardHome/AdGuardHome -s install
/data/AdGuardHome/AdGuardHome -s start
iptables -t nat -A PREROUTING -p tcp --dport 53 -j REDIRECT --to-ports 5353
iptables -t nat -A PREROUTING -p udp --dport 53 -j REDIRECT --to-ports 5353
ip6tables -t nat -A PREROUTING -p tcp --dport 53 -j REDIRECT --to-ports 5353
ip6tables -t nat -A PREROUTING -p udp --dport 53 -j REDIRECT --to-ports 5353
EOF
```
### 2. 升级 AdGuard Home
- 注:留意链接后缀是否与 CPU 架构匹配
连接 SSH 后执行如下命令:
```shell
# AdGuard Home Release 版
curl -sS -o /data/AdGuardHome/AdGuardHome -L https://ghfast.top/https://github.com/DustinWin/proxy-tools/releases/download/AdGuardHome/AdGuardHome_release_linux_arm64
# AdGuard Home Beta 版
curl -sS -o /data/AdGuardHome/AdGuardHome -L https://ghfast.top/https://github.com/DustinWin/proxy-tools/releases/download/AdGuardHome/AdGuardHome_beta_linux_arm64
/data/AdGuardHome/AdGuardHome -s restart
```
## 五、 扩展(以 ShellCrash 配置定时任务为例)
可在 ShellCrash 里添加定时更新 mihomo 内核、sing-box 内核、[zashboard](https://github.com/Zephyruso/zashboard) 和 AdGuard Home 的任务
1. 连接 SSH 后执行 `vi $CRASHDIR/configs/task/task.user`,按一下 Ins 键(Insert 键),粘贴如下内容:
注:
- ① 留意链接后缀是否与 CPU 架构匹配
- ② 须重启 ShellCrash 和 AdGuard Home 服务后生效
```shell
201#curl -sS -o $CRASHDIR/CrashCore.upx -L https://ghfast.top/https://github.com/DustinWin/proxy-tools/releases/download/mihomo/mihomo-meta-linux-arm64.upx >/dev/null 2>&1#更新mihomo内核
202#curl -sS -o $CRASHDIR/CrashCore.upx -L https://ghfast.top/https://github.com/DustinWin/proxy-tools/releases/download/sing-box/sing-box-ref1nd-stable-linux-arm64.upx >/dev/null 2>&1#更新sing-boxr内核
203#curl -sS -o $CRASHDIR/CrashCore.upx -L https://ghfast.top/https://github.com/DustinWin/proxy-tools/releases/download/sing-box/sing-box-stable-linux-arm64.upx >/dev/null 2>&1#更新sing-box内核
204#curl -sS -L https://ghfast.top/https://github.com/DustinWin/proxy-tools/releases/download/Dashboard/zashboard.tar.gz | tar -zx -C $CRASHDIR/ui/ >/dev/null 2>&1#更新zashboard
205#curl -sS -o /data/AdGuardHome/AdGuardHome -L https://ghfast.top/https://github.com/DustinWin/proxy-tools/releases/download/AdGuardHome/AdGuardHome_beta_linux_arm64 >/dev/null 2>&1#更新AdGuardHome
```
1. 按一下 Esc 键(退出键),输入英文冒号 `:`,继续输入 `wq` 并回车
2. 执行 `sc`,进入 ShellCrash → 5 配置自动任务 → 1 添加自动任务,可以看到末尾就有添加的定时任务,输入对应的数字并回车后可设置执行条件
@@ -0,0 +1,377 @@
---
title: 分享 Clash Mi for Android 采用 ruleset 方案的一套配置
description: 此配置搭载 mihomo 内核,采用 <code>RULE-SET</code> 规则搭配 .list 和 .mrs 规则集合文件
date: 2024-08-21 18:08:13 +0800
categories: [分享配置, Android]
tags: [Clash, Clash Mi, mihomo, Android, ruleset, rule-set, 分享]
---
> 声明
{: .prompt-warning }
请根据自身情况进行修改,**适合自己的方案才是最好的方案**,如无特殊需求,可以照搬
## 一、 生成配置文件 .yaml 文件直链
具体方法请参考《[生成带有自定义策略组和规则的 mihomo 配置文件直链-ruleset 方案](https://proxy-tutorials.dustinwin.us.kg/posts/link-mihomo-ruleset)》,贴一下我使用的配置:
```yaml
proxy-providers:
🛫 机场订阅:
type: http
# 修改为你的 Clash 订阅链接
url: "https://example.com/xxx/xxx&flag=clash"
path: ./proxies/airport.yaml
interval: 86400
filter: "(?i)(🇭🇰|港|hk|hongkong|hong kong|🇹🇼|台|tw|taiwan|tai wan|🇯🇵|日|jp|japan|🇸🇬|新|sg|singapore|🇺🇸|美|us|unitedstates|united states)"
health-check:
enable: true
url: https://www.gstatic.com/generate_204
interval: 600
🆓 免费订阅:
type: http
# 修改为你的 Clash 订阅链接
url: "https://example.com/xxx/xxx&flag=clash"
path: ./proxies/free.yaml
interval: 43200
health-check:
enable: true
url: https://www.gstatic.com/generate_204
interval: 600
log-level: error
ipv6: true
allow-lan: true
mixed-port: 7890
unified-delay: true
tcp-concurrent: true
external-controller: 0.0.0.0:9090
profile: {store-selected: true, store-fake-ip: true}
sniffer:
enable: true
parse-pure-ip: true
sniff: {HTTP: {ports: [80, 8080-8880], override-destination: true}, TLS: {ports: [443, 8443]}, QUIC: {ports: [443, 8443]}}
skip-domain: ['Mijia Cloud']
tun:
enable: true
stack: mixed
dns-hijack: [any:53]
auto-route: true
auto-detect-interface: true
device: mihomo
strict-route: true
hosts:
miwifi.com: [192.168.31.1, 127.0.0.1]
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:
enable: true
prefer-h3: true
ipv6: true
enhanced-mode: fake-ip
fake-ip-range: 28.0.0.0/8
fake-ip-range6: fc00::/16
fake-ip-filter-mode: rule
fake-ip-filter:
- RULE-SET,private,real-ip
- RULE-SET,trackerslist,real-ip
- RULE-SET,microsoft-cn,real-ip
- RULE-SET,apple-cn,real-ip
- RULE-SET,google-cn,real-ip
- RULE-SET,games-cn,real-ip
- RULE-SET,games,fake-ip
- RULE-SET,ai,fake-ip
- RULE-SET,proxy,fake-ip
- RULE-SET,cn,real-ip
- MATCH,fake-ip
nameserver:
- quic://dns.alidns.com:853
- https://doh.pub/dns-query
nameserver-policy:
'rule-set:private': [system]
'rule-set:ads': [rcode://success]
# 若没有单个出站代理节点,须删除所有 `🆚 vless 节点` 相关内容
proxies:
- name: 🆚 vless 节点
type: vless
server: example.com
port: 443
uuid: {uuid}
network: ws
tls: true
udp: false
sni: example.com
client-fingerprint: chrome
ws-opts:
path: "/?ed=2048"
headers:
host: example.com
proxy-groups:
- {name: 节点选择, type: select, proxies: [香港节点, 台湾节点, 日本节点, 新加坡节点, 美国节点, 免费节点, 🆚 vless 节点], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/proxy.png"}
- {name: 网络测试, type: select, proxies: [全球直连, 节点选择, 香港节点, 台湾节点, 日本节点, 新加坡节点, 美国节点, 免费节点, 🆚 vless 节点], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/networktest.png"}
- {name: 游戏平台, type: select, proxies: [节点选择, 香港节点, 台湾节点, 日本节点, 新加坡节点, 美国节点, 🆚 vless 节点], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/games.png"}
- {name: AI 平台, type: select, proxies: [节点选择, 香港节点, 台湾节点, 日本节点, 新加坡节点, 美国节点, 🆚 vless 节点], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/ai.png"}
- {name: 游戏服务, type: select, proxies: [全球直连, 节点选择], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/games-cn.png"}
- {name: 微软服务, type: select, proxies: [全球直连, 节点选择], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/microsoft-cn.png"}
- {name: 谷歌服务, type: select, proxies: [全球直连, 节点选择], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/google-cn.png"}
- {name: 苹果服务, type: select, proxies: [全球直连, 节点选择], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/apple-cn.png"}
- {name: 国内域名, type: select, proxies: [全球直连, 节点选择], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/cn.png"}
- {name: 国内 IP, type: select, proxies: [全球直连, 节点选择], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/cnip.png"}
- {name: 国外域名, type: select, proxies: [节点选择, 香港节点, 台湾节点, 日本节点, 新加坡节点, 美国节点, 免费节点, 🆚 vless 节点], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/global.png"}
- {name: 电报消息, type: select, proxies: [节点选择, 香港节点, 台湾节点, 日本节点, 新加坡节点, 美国节点, 免费节点, 🆚 vless 节点], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/telegram.png"}
- {name: 直连软件, type: select, proxies: [全球直连], hidden: true, icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/applications.png"}
- {name: 私有网络, type: select, proxies: [全球直连], hidden: true, icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/private.png"}
# 若机场的 UDP 质量不是很好,导致某游戏无法登录或进入房间,可以添加 `disable-udp: true` 配置项解决
- {name: 漏网之鱼, type: select, proxies: [节点选择, 香港节点, 台湾节点, 日本节点, 新加坡节点, 美国节点, 免费节点, 🆚 vless 节点, 全球直连], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/match.png"}
- {name: 全球直连, type: select, proxies: [DIRECT], hidden: true, icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/direct.png"}
- {name: 香港节点, type: url-test, tolerance: 50, use: [🛫 机场订阅], filter: "(?i)(🇭🇰|港|hk|hongkong|hong kong)", icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/hongkong.png"}
- {name: 台湾节点, type: url-test, tolerance: 50, use: [🛫 机场订阅], filter: "(?i)(🇹🇼|台|tw|taiwan|tai wan)", icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/taiwan.png"}
- {name: 日本节点, type: url-test, tolerance: 50, use: [🛫 机场订阅], filter: "(?i)(🇯🇵|日|jp|japan)", icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/japan.png"}
- {name: 新加坡节点, type: url-test, tolerance: 50, use: [🛫 机场订阅], filter: "(?i)(🇸🇬|新|sg|singapore)", icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/singapore.png"}
- {name: 美国节点, type: url-test, tolerance: 100, use: [🛫 机场订阅], filter: "(?i)(🇺🇸|美|us|unitedstates|united states)", icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/unitedstates.png"}
- {name: 免费节点, type: url-test, tolerance: 100, use: [🆓 免费订阅], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/free.png"}
rule-providers:
trackerslist:
type: http
behavior: domain
format: mrs
path: ./ruleset/trackerslist.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/trackerslist.mrs"
interval: 86400
ads:
type: http
behavior: domain
format: mrs
path: ./ruleset/ads.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/ads.mrs"
interval: 86400
private:
type: http
behavior: domain
format: mrs
path: ./ruleset/private.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/private.mrs"
interval: 86400
applications:
type: http
behavior: classical
format: text
path: ./ruleset/applications.list
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/applications.list"
interval: 86400
microsoft-cn:
type: http
behavior: domain
format: mrs
path: ./ruleset/microsoft-cn.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/microsoft-cn.mrs"
interval: 86400
apple-cn:
type: http
behavior: domain
format: mrs
path: ./ruleset/apple-cn.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/apple-cn.mrs"
interval: 86400
google-cn:
type: http
behavior: domain
format: mrs
path: ./ruleset/google-cn.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/google-cn.mrs"
interval: 86400
games-cn:
type: http
behavior: domain
format: mrs
path: ./ruleset/games-cn.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/games-cn.mrs"
interval: 86400
games:
type: http
behavior: domain
format: mrs
path: ./ruleset/games.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/games.mrs"
interval: 86400
ai:
type: http
behavior: domain
format: mrs
path: ./ruleset/ai.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/ai.mrs"
interval: 86400
networktest:
type: http
behavior: domain
format: mrs
path: ./ruleset/networktest.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/networktest.mrs"
interval: 86400
proxy:
type: http
behavior: domain
format: mrs
path: ./ruleset/proxy.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/proxy.mrs"
interval: 86400
cn:
type: http
behavior: domain
format: mrs
path: ./ruleset/cn.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/cn.mrs"
interval: 86400
privateip:
type: http
behavior: ipcidr
format: mrs
path: ./ruleset/privateip.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/privateip.mrs"
interval: 86400
cnip:
type: http
behavior: ipcidr
format: mrs
path: ./ruleset/cnip.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/cnip.mrs"
interval: 86400
telegramip:
type: http
behavior: ipcidr
format: mrs
path: ./ruleset/telegramip.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/telegramip.mrs"
interval: 86400
rules:
- RULE-SET,private,私有网络
- RULE-SET,applications,直连软件
- RULE-SET,microsoft-cn,微软服务
- RULE-SET,apple-cn,苹果服务
- RULE-SET,google-cn,谷歌服务
- RULE-SET,games-cn,游戏服务
- RULE-SET,games,游戏平台
- RULE-SET,ai,AI 平台
- RULE-SET,networktest,网络测试
- RULE-SET,proxy,国外域名
- RULE-SET,cn,国内域名
- RULE-SET,privateip,私有网络,no-resolve
- RULE-SET,cnip,国内 IP
- RULE-SET,telegramip,电报消息,no-resolve
- MATCH,漏网之鱼
```
---
>`DNS` 私货
{: .prompt-tip }
注:
- ① 本 `dns` 配置中,国内域名走国内 DNS 解析,国外域名走 `fake-ip`,未知域名也走 `fake-ip`,在匹配 `RULE-SET:cn` 规则时会由国外 DNS 解析且配置 `ecs` 提高了兼容性,解析出 IP 在国内则走 `国内 IP` 规则,否则走 `漏网之鱼` 规则(有效解决了“心理 DNS 泄露问题”,详见《[搭载 mihomo 内核配置 DNS 不泄露教程-ruleset 方案](https://proxy-tutorials.dustinwin.us.kg/posts/dnsnoleaks-mihomo-ruleset/)》)
- ② 推荐将 `ecs` 设置为当前宽带运营商分配的默认 DNS(可进入光猫或路由器拨号页面查看,或者前往[公共 DNS 大全](https://toolb.cn/publicdns)查询)的 IP 段,如默认 DNS 为 `211.137.58.20`,可设置为 `211.137.58.0/24`
```yaml
hosts:
miwifi.com: [192.168.31.1, 127.0.0.1]
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]
dns:
enable: true
ipv6: true
listen: 0.0.0.0:1053
enhanced-mode: fake-ip
fake-ip-range: 28.0.0.0/8
fake-ip-range6: fc00::/16
fake-ip-filter-mode: rule
fake-ip-filter:
- RULE-SET,private,real-ip
- RULE-SET,trackerslist,real-ip
- RULE-SET,microsoft-cn,real-ip
- RULE-SET,apple-cn,real-ip
- RULE-SET,google-cn,real-ip
- RULE-SET,games-cn,real-ip
- RULE-SET,games,fake-ip
- RULE-SET,ai,fake-ip
- RULE-SET,proxy,fake-ip
- RULE-SET,cn,real-ip
- MATCH,fake-ip
respect-rules: true
nameserver:
# 推荐将 `ecs` 设置为当前宽带运营商分配的默认 DNS 的 IP 段
- 'https://dns.google/dns-query#ecs=211.137.58.0/24&ecs-override=true'
- 'quic://dns11.quad9.net:853#ecs=211.137.58.0/24&ecs-override=true'
proxy-server-nameserver:
- quic://dns.alidns.com:853
- https://doh.pub/dns-query
direct-nameserver:
- quic://dns.alidns.com:853
- https://doh.pub/dns-query
direct-nameserver-follow-policy: true
nameserver-policy:
'rule-set:private': [system]
'rule-set:ads': [rcode://success]
'rule-set:trackerslist,microsoft-cn,apple-cn,google-cn,games-cn,cn': [quic://dns.alidns.com:853, https://doh.pub/dns-query]
```
---
>`proxy-groups` 私货
{: .prompt-tip }
注:
- ① 本 `proxy-groups` 配置中,将不同的节点类型(如:`Shadowsocks``Trojan`)分别配置 `type: url-test` 进行延迟测试,且配置 `hidden: true` 以简化 Dashboard 面板中的显示。再将延迟测试最低的策略组配置 `type: load-balance` 进行负载均衡供用户选择使用
- ② 将不同的优选节点分别配置 `type: fallback` 进行故障转移,且配置 `hidden: true` 以简化 Dashboard 面板中的显示。再将故障转移后的策略组配置 `type: url-test` 进行延迟测试供用户选择使用
```yaml
proxy-groups:
- {name: 香港节点, type: load-balance, strategy: consistent-hashing, proxies: [香港-ss, 香港-trojan], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/hongkong.png"}
- {name: 香港-ss, type: url-test, tolerance: 50, use: [🛫 机场订阅], filter: "(?i)((🇭🇰|港|hk|hongkong|hong kong).*ss)", hidden: true, icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/shadowsocks.png"}
- {name: 香港-trojan, type: url-test, tolerance: 50, use: [🛫 机场订阅], filter: "(?i)(🇭🇰|港|hk|hongkong|hong kong)", exclude-filter: "(?i)(ss)", hidden: true, icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/trojan.png"}
- {name: 台湾节点, type: load-balance, strategy: consistent-hashing, proxies: [台湾-ss, 台湾-trojan], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/taiwan.png"}
- {name: 台湾-ss, type: url-test, tolerance: 50, use: [🛫 机场订阅], filter: "(?i)((🇹🇼|台|tw|taiwan|tai wan).*ss)", hidden: true, icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/shadowsocks.png"}
- {name: 台湾-trojan, type: url-test, tolerance: 50, use: [🛫 机场订阅], filter: "(?i)(🇹🇼|台|tw|taiwan|tai wan)", exclude-filter: "(?i)(ss)", hidden: true, icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/trojan.png"}
- {name: 日本节点, type: load-balance, strategy: consistent-hashing, proxies: [日本-ss, 日本-trojan], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/japan.png"}
- {name: 日本-ss, type: url-test, tolerance: 50, use: [🛫 机场订阅], filter: "(?i)((🇯🇵|日|jp|japan).*ss)", hidden: true, icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/shadowsocks.png"}
- {name: 日本-trojan, type: url-test, tolerance: 50, use: [🛫 机场订阅], filter: "(?i)(🇯🇵|日|jp|japan)", exclude-filter: "(?i)(ss)", hidden: true, icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/trojan.png"}
- {name: 新加坡节点, type: load-balance, strategy: consistent-hashing, proxies: [新加坡-ss, 新加坡-trojan], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/singapore.png"}
- {name: 新加坡-ss, type: url-test, tolerance: 50, use: [🛫 机场订阅], filter: "(?i)((🇸🇬|新|sg|singapore).*ss)", hidden: true, icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/shadowsocks.png"}
- {name: 新加坡-trojan, type: url-test, tolerance: 50, use: [🛫 机场订阅], filter: "(?i)(🇸🇬|新|sg|singapore)", exclude-filter: "(?i)(ss)", hidden: true, icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/trojan.png"}
- {name: 美国节点, type: load-balance, strategy: consistent-hashing, proxies: [美国-ss, 美国-trojan], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/unitedstates.png"}
- {name: 美国-ss, type: url-test, tolerance: 100, use: [🛫 机场订阅], filter: "(?i)((🇺🇸|美|us|unitedstates|united states).*ss)", hidden: true, icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/shadowsocks.png"}
- {name: 美国-trojan, type: url-test, tolerance: 100, use: [🛫 机场订阅], filter: "(?i)(🇺🇸|美|us|unitedstates|united states)", exclude-filter: "(?i)(ss)", hidden: true, icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/trojan.png"}
- {name: 免费节点, type: url-test, tolerance: 100, proxies: [移动优选节点, CF 优选节点], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/free.png"}
- {name: 移动优选节点, type: fallback, use: [🆓 免费订阅], filter: "(?i)(cmcc)", hidden: true, icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/cmcc.png"}
- {name: CF 优选节点, type: fallback, use: [🆓 免费订阅], filter: "(?i)(cfip)", hidden: true, icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/cfip.png"}
```
## 二、 导入配置文件并启动
1. 进入 [Clash Mi for Android](https://github.com/KaringX/clashmi) → “+”图标 → 添加配置链接,“配置链接/内容”输入《[](https://proxy-tutorials.dustinwin.us.kg/posts/share-android-mihomo-ruleset/#%E4%B8%80-%E7%94%9F%E6%88%90%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6-yaml-%E6%96%87%E4%BB%B6%E7%9B%B4%E9%93%BE)》中生成的配置文件 .yaml 直链,点击“✓”
2. 待配置下载完成后返回到主界面,进入核心设置,关闭所有配置项的覆写功能
3. 再次返回到主界面,点击“未连接”右边的灰色按钮即可启动服务
4. 待服务启动成功后可直接点击“面板”来使用 [zashboard](https://github.com/Zephyruso/zashboard)
@@ -0,0 +1,390 @@
---
title: 分享 sing-boxr for Android 采用 ruleset 方案的一套配置
description: 此配置搭载 sing-boxr 内核,采用 <code>rule_set</code> 规则搭配 .srs 规则集文件
date: 2024-08-22 19:58:51 +0800
categories: [分享配置, Android]
tags: [sing-box, sing-boxr, Android, ruleset, rule_set, 分享]
---
> 声明
{: .prompt-warning }
1. 请根据自身情况进行修改,**适合自己的方案才是最好的方案**,如无特殊需求,可以照搬
2. 本教程搭载 [sing-box 内核 reF1nd-Testing 版](https://github.com/reF1nd/sing-box/tree/reF1nd-testing)(可前往 <https://github.com/reF1nd/sing-box-releases/releases> 下载“SFA-[version]-reF1nd-arm64-v8a.apk”文件进行安装)
## 一、 生成配置文件 .json 文件直链
具体方法请参考《[生成带有自定义出站和规则的 sing-boxr 配置文件直链-ruleset 方案](https://proxy-tutorials.dustinwin.us.kg/posts/link-singboxr-ruleset)》,贴一下我使用的配置:
- 注:推荐将 `client_subnet` 设置为当前宽带运营商分配的默认 DNS(可进入光猫或路由器拨号页面查看,或者前往[公共 DNS 大全](https://toolb.cn/publicdns)查询)的 IP 段,如默认 DNS 为 `211.137.58.20`,可设置为 `211.137.58.0/24`
```json
{
"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"
}
}
],
"log": { "level": "error", "timestamp": true },
"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_local", "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": "28.0.0.0/8", "inet6_range": "fc00::/16" }
],
"rules": [
{ "preferred_by": [ "hosts" ], "server": "hosts" },
{ "clash_mode": [ "Direct" ], "server": "dns_direct" },
{ "clash_mode": [ "Global" ], "server": "dns_proxy" },
{ "rule_set": [ "private" ], "server": "dns_local" },
{ "rule_set": [ "ads" ], "action": "predefined" },
{ "rule_set": [ "trackerslist", "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" },
{ "query_type": [ "A", "AAAA" ], "server": "dns_fakeip" }
],
"final": "dns_direct",
"strategy": "prefer_ipv4",
"optimistic": true,
"reverse_mapping": true
},
"http_clients": [ { "tag": "detour_proxy", "detour": "GLOBAL" } ],
"inbounds": [
// 启动服务时如果出现 `tun-in` 报错,可新增 `"stack": "system"` 配置项
{ "tag": "tun-in", "type": "tun", "interface_name": "sing-box", "address": [ "172.18.0.1/30", "fdfe:dcba:9876::1/126" ], "auto_route": true, "strict_route": true }
],
"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": [ "全球直连", "节点选择" ] },
{ "tag": "国内 IP", "type": "selector", "outbounds": [ "全球直连", "节点选择" ] },
{ "tag": "国外域名", "type": "selector", "outbounds": [ "节点选择", "香港节点", "台湾节点", "日本节点", "新加坡节点", "美国节点", "免费节点", "🆚 vless 节点" ] },
{ "tag": "电报消息", "type": "selector", "outbounds": [ "节点选择", "香港节点", "台湾节点", "日本节点", "新加坡节点", "美国节点", "免费节点", "🆚 vless 节点" ] },
{ "tag": "直连软件", "type": "selector", "outbounds": [ "全球直连" ] },
{ "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": {
"default_domain_resolver": "dns_direct",
"rules": [
{ "rule_set": [ "telegramip" ], "domain": [ "Mijia Cloud" ], "invert": true, "action": "sniff" },
{ "type": "logical", "mode": "or", "rules": [ { "protocol": [ "dns" ] }, { "port": 53 } ], "action": "hijack-dns" },
{ "clash_mode": [ "Direct" ], "outbound": "DIRECT" },
{ "clash_mode": [ "Global" ], "outbound": "GLOBAL" },
{ "rule_set": [ "private" ], "outbound": "私有网络" },
{ "rule_set": [ "applications" ], "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": "国外域名" },
{ "rule_set": [ "cn" ], "outbound": "国内域名" },
{ "ip_is_private": true, "outbound": "私有网络" },
{ "rule_set": [ "telegramip" ], "outbound": "电报消息" },
{ "action": "resolve", "match_only": true },
{ "rule_set": [ "cnip" ], "outbound": "国内 IP" }
],
"rule_set": [
{
"tag": "trackerslist",
"type": "remote",
"format": "binary",
"path": "./ruleset/trackerslist.srs",
"url": "https://github.com/DustinWin/ruleset_geodata/releases/download/sing-box-ruleset/trackerslist.srs"
},
{
"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": "applications",
"type": "remote",
"format": "binary",
"path": "./ruleset/applications.srs",
"url": "https://github.com/DustinWin/ruleset_geodata/releases/download/sing-box-ruleset/applications.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": "telegramip",
"type": "remote",
"format": "binary",
"path": "./ruleset/telegramip.srs",
"url": "https://github.com/DustinWin/ruleset_geodata/releases/download/sing-box-ruleset/telegramip.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"
}
],
"final": "漏网之鱼",
"auto_detect_interface": true,
"override_android_vpn": true
},
"services": [
{
"type": "api",
"listen": "::",
"listen_port": 9999,
"secret": "",
"access_control_allow_private_network": true
}
],
"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
}
}
```
---
>`DNS` 私货
{: .prompt-tip }
注:
- ① 本 `dns` 配置中,国内域名走国内 DNS 解析,国外域名走 `fakeip`,未知域名也走 `fakeip`,在匹配 `rule_set:cnip` 规则时会先由国外 DNS 解析且配置 `client_subnet` 提高了兼容性,解析出 IP 在国内则走 `国内 IP` 规则,否则走 `漏网之鱼` 规则(有效解决了“心理 DNS 泄露问题”,详见《[搭载 sing-boxr 内核配置 DNS 不泄露教程-ruleset 方案](https://proxy-tutorials.dustinwin.us.kg/posts/dnsnoleaks-singboxr-ruleset/)》)
- ② 推荐将 `client_subnet` 设置为当前宽带运营商分配的默认 DNS(可进入光猫或路由器拨号页面查看,或者前往[公共 DNS 大全](https://toolb.cn/publicdns)查询)的 IP 段,如默认 DNS 为 `211.137.58.20`,可设置为 `211.137.58.0/24`
```json
{
"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_local", "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": "28.0.0.0/8", "inet6_range": "fc00::/16" }
],
"rules": [
{ "preferred_by": [ "hosts" ], "server": "hosts" },
{ "clash_mode": [ "Direct" ], "server": "dns_direct" },
{ "clash_mode": [ "Global" ], "server": "dns_proxy" },
{ "rule_set": [ "private" ], "server": "dns_local" },
{ "rule_set": [ "ads" ], "action": "predefined" },
{ "rule_set": [ "trackerslist", "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" },
{ "query_type": [ "A", "AAAA" ], "server": "dns_fakeip" }
],
"final": "dns_proxy",
"strategy": "prefer_ipv4",
"optimistic": true,
"reverse_mapping": true,
// 推荐将 `client_subnet` 设置为当前宽带运营商分配的默认 DNS 的 IP 段
"client_subnet": "211.137.58.0/24"
}
}
```
---
>`outbounds` 私货
{: .prompt-tip }
注:
- ① 本 `outbounds` 配置中,将不同的节点类型(如:`Shadowsocks``Trojan`)分别配置 `"type": "urltest"` 进行延迟测试(可进入 [zashboard](https://github.com/Zephyruso/zashboard) → 代理 → 设置 → 管理隐藏代理组,设置隐藏以简化 Dashboard 面板中的显示)。再将延迟测试最低的策略组配置 `"type": "loadbalance"` 进行负载均衡供用户选择使用
- ② 将不同的优选节点分别配置 `"fallback": { "enabled": true }` 进行故障转移(可进入 zashboard → 代理 → 设置 → 管理隐藏代理组,设置隐藏以简化 Dashboard 面板中的显示)。再将故障转移后的策略组配置 `"type": "urltest"` 进行延迟测试供用户选择使用
```json
{
"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-boxr
1. 进入 [sing-boxr for Android](https://github.com/DustinWin/proxy-tools/releases/tag/sing-box) → 仪表 → 新配置 → 手动创建,“类型”选择“远程”,在“URL”处粘贴《[](https://proxy-tutorials.dustinwin.us.kg/posts/share-android-singboxr-ruleset/#%E4%B8%80-%E7%94%9F%E6%88%90%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6-json-%E6%96%87%E4%BB%B6%E7%9B%B4%E9%93%BE)》中生成的配置文件 .json 直链,“自动更新间隔”填写 `1440`,最后点击“创建”
2. 进入 sing-boxr for Android → 仪表,点击“▶️”图标即可启动 sing-boxr 服务
- 注:首次启用可能会报错,重试几次即可
## 三、 访问 Dashboard 面板
1. 打开 zashboard 在线面板地址 <http://board.zash.run.place> 可直接通过 [Clash API](https://sing-boxr.dustinwin.us.kg/zh/configuration/experimental/clash-api/) 的方式访问 Dashboard 面板
2. 进入设置 → 后端设置,点击“+”图标,切换到“[sing-box API](https://sing-boxr.dustinwin.us.kg/zh/configuration/service/api/)”标签,将“端口”修改为 `9999` 并点击“提交”
<img src="/assets/img/share/172-9090-dashboard-singbox-phone.png" alt="面板设置" width="60%" />
3. 通过切换后端配置可以分别使用 Clash API(支持“代理提供商”和“规则提供商”的更新)和 sing-box API Dashboard 面板
> 推荐设置
{: .prompt-tip }
1. 进入 zashboard → 代理 → 代理设置 → 管理隐藏代理组,隐藏不必要显示的代理组
2. 进入 zashboard → 设置 → 图标,设置“自定义图标”,可参考 [icon 文件](https://github.com/DustinWin/ruleset_geodata/releases/tag/icons)
3. 进入 zashboard → 设置 → 后端设置 → 修改后端配置,可设置“标签 (可选)”来快速识别不同设备
@@ -0,0 +1,273 @@
---
title: 分享 ShellCrash 搭载 mihomo 内核采用 geodata 方案的一套配置
description: 此配置搭载 mihomo 内核,采用 <code>GEOSITE</code> 和 <code>GEOIP</code> 规则搭配 geosite.dat 和 geoip.dat(或 Country.mmdb)路由规则文件
date: 2024-08-21 18:12:46 +0800
categories: [分享配置, Router]
tags: [Clash, mihomo, ShellCrash, geodata, geosite, 分享, Router]
---
> 声明
{: .prompt-warning }
1. 请根据自身情况进行修改,**适合自己的方案才是最好的方案**,如无特殊需求,可以照搬
2. 此方案适用于 [ShellCrash](https://github.com/juewuy/ShellCrash)(以 ARM64 架构为例,且安装路径为 `/data/ShellCrash`{: .filepath}
3. 本方案绕过了 CNIP 且不搭配 [AdGuard Home](https://github.com/AdguardTeam/AdGuardHome),在 DNS 层拦截广告
4. 本人将路由器设置了每天早上 6 点重启,使得《[](https://proxy-tutorials.dustinwin.us.kg/posts/share-shellcrash-mihomo-geodata/#%E4%BA%94-%E6%B7%BB%E5%8A%A0%E5%AE%9A%E6%97%B6%E4%BB%BB%E5%8A%A1)》中设置的定时任务生效
## 一、 生成配置文件 .yaml 文件直链
具体方法此处不再赘述,请看《[生成带有自定义策略组和规则的 mihomo 配置文件直链-geodata 方案](https://proxy-tutorials.dustinwin.us.kg/posts/link-mihomo-geodata)》,贴一下我使用的配置:
- 注:`rules` 部分的 `geosite``geoip` 内容须与 `geodata-url` 中的路由规则文件相匹配
```yaml
proxy-providers:
🛫 机场订阅:
type: http
# 修改为你的 Clash 订阅链接
url: "https://example.com/xxx/xxx&flag=clash"
path: ./proxies/airport.yaml
interval: 86400
filter: "(?i)(🇭🇰|港|hk|hongkong|hong kong|🇹🇼|台|tw|taiwan|tai wan|🇯🇵|日|jp|japan|🇸🇬|新|sg|singapore|🇺🇸|美|us|unitedstates|united states)"
health-check:
enable: true
url: https://www.gstatic.com/generate_204
interval: 600
🆓 免费订阅:
type: http
# 修改为你的 Clash 订阅链接
url: "https://example.com/xxx/xxx&flag=clash"
path: ./proxies/free.yaml
interval: 86400
health-check:
enable: true
url: https://www.gstatic.com/generate_204
interval: 600
# 若没有单个出站代理节点,须删除所有 `🆚 vless 节点` 相关内容
proxies:
- name: 🆚 vless 节点
type: vless
server: example.com
port: 443
uuid: {uuid}
network: ws
tls: true
udp: false
sni: example.com
client-fingerprint: chrome
ws-opts:
path: "/?ed=2048"
headers:
host: example.com
proxy-groups:
- {name: 节点选择, type: select, proxies: [香港节点, 台湾节点, 日本节点, 新加坡节点, 美国节点, 免费节点, 🆚 vless 节点], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/proxy.png"}
- {name: 网络测试, type: select, proxies: [全球直连, 节点选择, 香港节点, 台湾节点, 日本节点, 新加坡节点, 美国节点, 免费节点, 🆚 vless 节点], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/networktest.png"}
- {name: 游戏平台, type: select, proxies: [节点选择, 香港节点, 台湾节点, 日本节点, 新加坡节点, 美国节点, 🆚 vless 节点], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/games.png"}
- {name: AI 平台, type: select, proxies: [节点选择, 香港节点, 台湾节点, 日本节点, 新加坡节点, 美国节点, 🆚 vless 节点], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/ai.png"}
- {name: 游戏服务, type: select, proxies: [全球直连, 节点选择], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/games-cn.png"}
- {name: 微软服务, type: select, proxies: [全球直连, 节点选择], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/microsoft-cn.png"}
- {name: 谷歌服务, type: select, proxies: [全球直连, 节点选择], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/google-cn.png"}
- {name: 苹果服务, type: select, proxies: [全球直连, 节点选择], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/apple-cn.png"}
- {name: 国外域名, type: select, proxies: [节点选择, 香港节点, 台湾节点, 日本节点, 新加坡节点, 美国节点, 免费节点, 🆚 vless 节点], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/global.png"}
- {name: 电报消息, type: select, proxies: [节点选择, 香港节点, 台湾节点, 日本节点, 新加坡节点, 美国节点, 免费节点, 🆚 vless 节点], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/telegram.png"}
- {name: 私有网络, type: select, proxies: [全球直连], hidden: true, icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/private.png"}
# 若机场的 UDP 质量不是很好,导致某游戏无法登录或进入房间,可以添加 `disable-udp: true` 配置项解决
- {name: 漏网之鱼, type: select, proxies: [节点选择, 香港节点, 台湾节点, 日本节点, 新加坡节点, 美国节点, 免费节点, 🆚 vless 节点, 全球直连], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/match.png"}
- {name: 全球直连, type: select, proxies: [DIRECT], hidden: true, icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/direct.png"}
- {name: 香港节点, type: url-test, tolerance: 50, use: [🛫 机场订阅], filter: "(?i)(🇭🇰|港|hk|hongkong|hong kong)", icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/hongkong.png"}
- {name: 台湾节点, type: url-test, tolerance: 50, use: [🛫 机场订阅], filter: "(?i)(🇹🇼|台|tw|taiwan|tai wan)", icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/taiwan.png"}
- {name: 日本节点, type: url-test, tolerance: 50, use: [🛫 机场订阅], filter: "(?i)(🇯🇵|日|jp|japan)", icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/japan.png"}
- {name: 新加坡节点, type: url-test, tolerance: 50, use: [🛫 机场订阅], filter: "(?i)(🇸🇬|新|sg|singapore)", icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/singapore.png"}
- {name: 美国节点, type: url-test, tolerance: 100, use: [🛫 机场订阅], filter: "(?i)(🇺🇸|美|us|unitedstates|united states)", icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/unitedstates.png"}
- {name: 免费节点, type: url-test, tolerance: 100, use: [🆓 免费订阅], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/free.png"}
rules:
- GEOSITE,private,私有网络
- GEOSITE,microsoft-cn,微软服务
- GEOSITE,apple-cn,苹果服务
- GEOSITE,google-cn,谷歌服务
- GEOSITE,games-cn,游戏服务
- GEOSITE,games,游戏平台
- GEOSITE,ai,AI 平台
- GEOSITE,networktest,网络测试
- GEOSITE,proxy,国外域名
- GEOIP,private,私有网络,no-resolve
- GEOIP,cn,全球直连
- GEOIP,telegram,电报消息,no-resolve
- MATCH,漏网之鱼
```
---
>`proxy-groups` 私货
{: .prompt-tip }
注:
- ① 本 `proxy-groups` 配置中,将不同的节点类型(如:`Shadowsocks``Trojan`)分别配置 `type: url-test` 进行延迟测试,且配置 `hidden: true` 以简化 Dashboard 面板中的显示。再将延迟测试最低的策略组配置 `type: load-balance` 进行负载均衡供用户选择使用
- ② 将不同的优选节点分别配置 `type: fallback` 进行故障转移,且配置 `hidden: true` 以简化 Dashboard 面板中的显示。再将故障转移后的策略组配置 `type: url-test` 进行延迟测试供用户选择使用
```yaml
proxy-groups:
- {name: 香港节点, type: load-balance, strategy: consistent-hashing, proxies: [香港-ss, 香港-trojan], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/hongkong.png"}
- {name: 香港-ss, type: url-test, tolerance: 50, use: [🛫 机场订阅], filter: "(?i)((🇭🇰|港|hk|hongkong|hong kong).*ss)", hidden: true, icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/shadowsocks.png"}
- {name: 香港-trojan, type: url-test, tolerance: 50, use: [🛫 机场订阅], filter: "(?i)(🇭🇰|港|hk|hongkong|hong kong)", exclude-filter: "(?i)(ss)", hidden: true, icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/trojan.png"}
- {name: 台湾节点, type: load-balance, strategy: consistent-hashing, proxies: [台湾-ss, 台湾-trojan], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/taiwan.png"}
- {name: 台湾-ss, type: url-test, tolerance: 50, use: [🛫 机场订阅], filter: "(?i)((🇹🇼|台|tw|taiwan|tai wan).*ss)", hidden: true, icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/shadowsocks.png"}
- {name: 台湾-trojan, type: url-test, tolerance: 50, use: [🛫 机场订阅], filter: "(?i)(🇹🇼|台|tw|taiwan|tai wan)", exclude-filter: "(?i)(ss)", hidden: true, icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/trojan.png"}
- {name: 日本节点, type: load-balance, strategy: consistent-hashing, proxies: [日本-ss, 日本-trojan], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/japan.png"}
- {name: 日本-ss, type: url-test, tolerance: 50, use: [🛫 机场订阅], filter: "(?i)((🇯🇵|日|jp|japan).*ss)", hidden: true, icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/shadowsocks.png"}
- {name: 日本-trojan, type: url-test, tolerance: 50, use: [🛫 机场订阅], filter: "(?i)(🇯🇵|日|jp|japan)", exclude-filter: "(?i)(ss)", hidden: true, icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/trojan.png"}
- {name: 新加坡节点, type: load-balance, strategy: consistent-hashing, proxies: [新加坡-ss, 新加坡-trojan], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/singapore.png"}
- {name: 新加坡-ss, type: url-test, tolerance: 50, use: [🛫 机场订阅], filter: "(?i)((🇸🇬|新|sg|singapore).*ss)", hidden: true, icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/shadowsocks.png"}
- {name: 新加坡-trojan, type: url-test, tolerance: 50, use: [🛫 机场订阅], filter: "(?i)(🇸🇬|新|sg|singapore)", exclude-filter: "(?i)(ss)", hidden: true, icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/trojan.png"}
- {name: 美国节点, type: load-balance, strategy: consistent-hashing, proxies: [美国-ss, 美国-trojan], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/unitedstates.png"}
- {name: 美国-ss, type: url-test, tolerance: 100, use: [🛫 机场订阅], filter: "(?i)((🇺🇸|美|us|unitedstates|united states).*ss)", hidden: true, icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/shadowsocks.png"}
- {name: 美国-trojan, type: url-test, tolerance: 100, use: [🛫 机场订阅], filter: "(?i)(🇺🇸|美|us|unitedstates|united states)", exclude-filter: "(?i)(ss)", hidden: true, icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/trojan.png"}
- {name: 免费节点, type: url-test, tolerance: 100, proxies: [移动优选节点, CF 优选节点], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/free.png"}
- {name: 移动优选节点, type: fallback, use: [🆓 免费订阅], filter: "(?i)(cmcc)", hidden: true, icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/cmcc.png"}
- {name: CF 优选节点, type: fallback, use: [🆓 免费订阅], filter: "(?i)(cfip)", hidden: true, icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/cfip.png"}
```
---
## 二、 导入 [mihomo 内核](https://github.com/MetaCubeX/mihomo)和 [CN_IP 文件](https://github.com/DustinWin/geoip)
连接 SSH 后执行如下命令:
```shell
curl -sS -o /tmp/CrashCore.upx -L https://ghfast.top/https://github.com/DustinWin/proxy-tools/releases/download/mihomo/mihomo-meta-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 加载,后选择 3 Mihomo(Meta) 内核
## 三、 导入路由规则文件
> 路由规则文件和 user.yaml 都属高度定制,牵一发而动全身
{: .prompt-warning }
连接 SSH 后执行如下命令:
```shell
curl -sS -o $CRASHDIR/GeoSite.dat -L https://cdn.jsdelivr.net/gh/DustinWin/ruleset_geodata@mihomo-geodata/geosite.dat
curl -sS -o $CRASHDIR/GeoIP.dat -L https://cdn.jsdelivr.net/gh/DustinWin/ruleset_geodata@mihomo-geodata/geoip-lite.dat
curl -sS -o $CRASHDIR/Country.mmdb -L https://cdn.jsdelivr.net/gh/DustinWin/ruleset_geodata@mihomo-geodata/Country-lite.mmdb
```
## 四、 编辑 user.yaml 文件
连接 SSH 后执行命令 `vi $CRASHDIR/yamls/user.yaml`,按一下 Ins 键(Insert 键),粘贴如下内容:
```yaml
log-level: error
allow-lan: true
unified-delay: true
tcp-concurrent: true
profile: {store-selected: true, store-fake-ip: true}
geodata-mode: true
hosts:
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:
enable: true
prefer-h3: true
ipv6: true
listen: 0.0.0.0:1053
enhanced-mode: fake-ip
fake-ip-range: 28.0.0.0/8
fake-ip-range6: fc00::/16
fake-ip-filter-mode: rule
fake-ip-filter:
- GEOSITE,private,real-ip
- GEOSITE,trackerslist,real-ip
- GEOSITE,microsoft-cn,real-ip
- GEOSITE,apple-cn,real-ip
- GEOSITE,google-cn,real-ip
- GEOSITE,games-cn,real-ip
- GEOSITE,games,fake-ip
- GEOSITE,ai,fake-ip
- GEOSITE,proxy,fake-ip
- GEOSITE,cn,real-ip
- MATCH,fake-ip
nameserver:
- quic://dns.alidns.com:853
- https://dns.pub/dns-query
nameserver-policy:
'geosite:private': [system]
'geosite:ads': [rcode://success]
```
按一下 Esc 键(退出键),输入英文冒号 `:`,继续输入 `wq` 并回车
---
>`DNS` 私货
{: .prompt-tip }
注:
- ① 本 `dns` 配置中,国内域名走国内 DNS 解析,国外域名走 `fake-ip`,未知域名也走 `fake-ip`,在匹配 `GEOIP:cn` 规则时会由国外 DNS 解析且配置 `ecs` 提高了兼容性,解析出 IP 在国内则走 `国内 IP` 规则,否则走 `漏网之鱼` 规则(有效解决了“心理 DNS 泄露问题”,详见《[搭载 mihomo 内核配置 DNS 不泄露教程-geodata 方案](https://proxy-tutorials.dustinwin.us.kg/posts/dnsnoleaks-mihomo-geodata/)》)
- ② 推荐将 `ecs` 设置为当前宽带运营商分配的默认 DNS(可进入光猫或路由器拨号页面查看,或者前往[公共 DNS 大全](https://toolb.cn/publicdns)查询)的 IP 段,如默认 DNS 为 `211.137.58.20`,可设置为 `211.137.58.0/24`
```yaml
hosts:
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]
dns:
enable: true
ipv6: true
listen: 0.0.0.0:1053
enhanced-mode: fake-ip
fake-ip-range: 28.0.0.0/8
fake-ip-range6: fc00::/16
fake-ip-filter-mode: rule
fake-ip-filter:
- GEOSITE,private,real-ip
- GEOSITE,trackerslist,real-ip
- GEOSITE,microsoft-cn,real-ip
- GEOSITE,apple-cn,real-ip
- GEOSITE,google-cn,real-ip
- GEOSITE,games-cn,real-ip
- GEOSITE,games,fake-ip
- GEOSITE,ai,fake-ip
- GEOSITE,proxy,fake-ip
- GEOSITE,cn,real-ip
- MATCH,fake-ip
respect-rules: true
nameserver:
# 推荐将 `ecs` 设置为当前宽带运营商分配的默认 DNS 的 IP 段
- 'https://dns.google/dns-query#ecs=211.137.58.0/24&ecs-override=true'
- 'quic://dns11.quad9.net:853#ecs=211.137.58.0/24&ecs-override=true'
proxy-server-nameserver:
- quic://dns.alidns.com:853
- https://doh.pub/dns-query
direct-nameserver:
- quic://dns.alidns.com:853
- https://doh.pub/dns-query
direct-nameserver-follow-policy: true
nameserver-policy:
'geosite:private': [system]
'geosite:ads': [rcode://success]
'geosite:trackerslist,microsoft-cn,apple-cn,google-cn,games-cn,cn': [quic://dns.alidns.com:853, https://doh.pub/dns-query]
```
## 五、 添加定时任务
可参考《[ShellCrash 搭载 mihomo 内核的配置-geodata 方案/添加定时任务](https://proxy-tutorials.dustinwin.us.kg/posts/toolsettings-shellcrash-mihomo-geodata/#%E4%B8%89-%E6%B7%BB%E5%8A%A0%E5%AE%9A%E6%97%B6%E4%BB%BB%E5%8A%A1)》
## 六、 设置部分
1. 设置可参考《[ShellCrash 搭载 mihomo 内核的配置-geodata 方案/设置部分](https://proxy-tutorials.dustinwin.us.kg/posts/toolsettings-shellcrash-mihomo-geodata/#%E5%9B%9B-%E8%AE%BE%E7%BD%AE%E9%83%A8%E5%88%86)》,此处只列举配置的不同之处
2. 进入 ShellCrash 配置脚本 → 2) 功能设置 → 2) DNS 设置 → 9) 修改 DNS 服务器,设置如下:
<img src="/assets/img/dns/dns-null.png" alt="设置部分 2" width="60%" />
3. 进入 2) 功能设置 → 6) 自定义端口及密钥 → 5) 修改面板访问端口,修改为 `9090`
## 七、 访问 Dashboard 面板
打开 [zashboard](https://github.com/Zephyruso/zashboard) 在线面板地址 <http://board.zash.run.place> 后,直接在 [Clash API](https://sing-boxr.dustinwin.us.kg/zh/configuration/experimental/clash-api/) 标签里将“主机”修改为 `192.168.31.1`,点击“提交”即可访问 Dashboard 面板
> 推荐设置
{: .prompt-tip }
进入 zashboard → 设置 → 后端设置 → 修改后端配置,可设置“标签 (可选)”来快速识别不同设备
@@ -0,0 +1,379 @@
---
title: 分享 ShellCrash 搭载 mihomo 内核采用 ruleset 方案的一套配置
description: 此配置搭载 mihomo 内核,采用 <code>RULE-SET</code> 规则搭配 .list 和 .mrs 规则集合文件
date: 2024-08-21 18:18:29 +0800
categories: [分享配置, Router]
tags: [Clash, mihomo, ShellCrash, ruleset, rule-set, 分享, Router]
---
> 声明
{: .prompt-warning }
1. 请根据自身情况进行修改,**适合自己的方案才是最好的方案**,如无特殊需求,可以照搬
2. 此方案适用于 [ShellCrash](https://github.com/juewuy/ShellCrash)(以 ARM64 架构为例,且安装路径为 `/data/ShellCrash`{: .filepath}
3. 本方案绕过了 CNIP 且不搭配 [AdGuard Home](https://github.com/AdguardTeam/AdGuardHome),在 DNS 层拦截广告
4. 本人将路由器设置了每天早上 6 点重启,使得《[](https://proxy-tutorials.dustinwin.us.kg/posts/share-shellcrash-mihomo-ruleset/#%E5%9B%9B-%E6%B7%BB%E5%8A%A0%E5%AE%9A%E6%97%B6%E4%BB%BB%E5%8A%A1)》中设置的定时任务生效
## 一、 生成配置文件 .yaml 文件直链
具体方法此处不再赘述,请看《[生成带有自定义策略组和规则的 mihomo 配置文件直链-ruleset 方案](https://proxy-tutorials.dustinwin.us.kg/posts/link-mihomo-ruleset)》,贴一下我使用的配置:
```yaml
proxy-providers:
🛫 机场订阅:
type: http
# 修改为你的 Clash 订阅链接
url: "https://example.com/xxx/xxx&flag=clash"
path: ./proxies/airport.yaml
interval: 86400
filter: "(?i)(🇭🇰|港|hk|hongkong|hong kong|🇹🇼|台|tw|taiwan|tai wan|🇯🇵|日|jp|japan|🇸🇬|新|sg|singapore|🇺🇸|美|us|unitedstates|united states)"
health-check:
enable: true
url: https://www.gstatic.com/generate_204
interval: 600
🆓 免费订阅:
type: http
# 修改为你的 Clash 订阅链接
url: "https://example.com/xxx/xxx&flag=clash"
path: ./proxies/free.yaml
interval: 86400
health-check:
enable: true
url: https://www.gstatic.com/generate_204
interval: 600
# 若没有单个出站代理节点,须删除所有 `🆚 vless 节点` 相关内容
proxies:
- name: 🆚 vless 节点
type: vless
server: example.com
port: 443
uuid: {uuid}
network: ws
tls: true
udp: false
sni: example.com
client-fingerprint: chrome
ws-opts:
path: "/?ed=2048"
headers:
host: example.com
proxy-groups:
- {name: 节点选择, type: select, proxies: [香港节点, 台湾节点, 日本节点, 新加坡节点, 美国节点, 免费节点, 🆚 vless 节点], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/proxy.png"}
- {name: 网络测试, type: select, proxies: [全球直连, 节点选择, 香港节点, 台湾节点, 日本节点, 新加坡节点, 美国节点, 免费节点, 🆚 vless 节点], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/networktest.png"}
- {name: 游戏平台, type: select, proxies: [节点选择, 香港节点, 台湾节点, 日本节点, 新加坡节点, 美国节点, 🆚 vless 节点], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/games.png"}
- {name: AI 平台, type: select, proxies: [节点选择, 香港节点, 台湾节点, 日本节点, 新加坡节点, 美国节点, 🆚 vless 节点], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/ai.png"}
- {name: 游戏服务, type: select, proxies: [全球直连, 节点选择], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/games-cn.png"}
- {name: 微软服务, type: select, proxies: [全球直连, 节点选择], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/microsoft-cn.png"}
- {name: 谷歌服务, type: select, proxies: [全球直连, 节点选择], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/google-cn.png"}
- {name: 苹果服务, type: select, proxies: [全球直连, 节点选择], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/apple-cn.png"}
- {name: 国外域名, type: select, proxies: [节点选择, 香港节点, 台湾节点, 日本节点, 新加坡节点, 美国节点, 免费节点, 🆚 vless 节点], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/global.png"}
- {name: 电报消息, type: select, proxies: [节点选择, 香港节点, 台湾节点, 日本节点, 新加坡节点, 美国节点, 免费节点, 🆚 vless 节点], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/telegram.png"}
- {name: 私有网络, type: select, proxies: [全球直连], hidden: true, icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/private.png"}
# 若机场的 UDP 质量不是很好,导致某游戏无法登录或进入房间,可以添加 `disable-udp: true` 配置项解决
- {name: 漏网之鱼, type: select, proxies: [节点选择, 香港节点, 台湾节点, 日本节点, 新加坡节点, 美国节点, 免费节点, 🆚 vless 节点, 全球直连], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/match.png"}
- {name: 全球直连, type: select, proxies: [DIRECT], hidden: true, icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/direct.png"}
- {name: 香港节点, type: url-test, tolerance: 50, use: [🛫 机场订阅], filter: "(?i)(🇭🇰|港|hk|hongkong|hong kong)", icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/hongkong.png"}
- {name: 台湾节点, type: url-test, tolerance: 50, use: [🛫 机场订阅], filter: "(?i)(🇹🇼|台|tw|taiwan|tai wan)", icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/taiwan.png"}
- {name: 日本节点, type: url-test, tolerance: 50, use: [🛫 机场订阅], filter: "(?i)(🇯🇵|日|jp|japan)", icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/japan.png"}
- {name: 新加坡节点, type: url-test, tolerance: 50, use: [🛫 机场订阅], filter: "(?i)(🇸🇬|新|sg|singapore)", icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/singapore.png"}
- {name: 美国节点, type: url-test, tolerance: 100, use: [🛫 机场订阅], filter: "(?i)(🇺🇸|美|us|unitedstates|united states)", icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/unitedstates.png"}
- {name: 免费节点, type: url-test, tolerance: 100, use: [🆓 免费订阅], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/free.png"}
rule-providers:
trackerslist:
type: http
behavior: domain
format: mrs
path: ./ruleset/trackerslist.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/trackerslist.mrs"
interval: 86400
ads:
type: http
behavior: domain
format: mrs
path: ./ruleset/ads.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/ads.mrs"
interval: 86400
private:
type: http
behavior: domain
format: mrs
path: ./ruleset/private.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/private.mrs"
interval: 86400
microsoft-cn:
type: http
behavior: domain
format: mrs
path: ./ruleset/microsoft-cn.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/microsoft-cn.mrs"
interval: 86400
apple-cn:
type: http
behavior: domain
format: mrs
path: ./ruleset/apple-cn.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/apple-cn.mrs"
interval: 86400
google-cn:
type: http
behavior: domain
format: mrs
path: ./ruleset/google-cn.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/google-cn.mrs"
interval: 86400
games-cn:
type: http
behavior: domain
format: mrs
path: ./ruleset/games-cn.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/games-cn.mrs"
interval: 86400
games:
type: http
behavior: domain
format: mrs
path: ./ruleset/games.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/games.mrs"
interval: 86400
ai:
type: http
behavior: domain
format: mrs
path: ./ruleset/ai.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/ai.mrs"
interval: 86400
networktest:
type: http
behavior: domain
format: mrs
path: ./ruleset/networktest.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/networktest.mrs"
interval: 86400
proxy:
type: http
behavior: domain
format: mrs
path: ./ruleset/proxy.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/proxy.mrs"
interval: 86400
cn:
type: http
behavior: domain
format: mrs
path: ./ruleset/cn.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/cn.mrs"
interval: 86400
privateip:
type: http
behavior: ipcidr
format: mrs
path: ./ruleset/privateip.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/privateip.mrs"
interval: 86400
cnip:
type: http
behavior: ipcidr
format: mrs
path: ./ruleset/cnip.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/cnip.mrs"
interval: 86400
telegramip:
type: http
behavior: ipcidr
format: mrs
path: ./ruleset/telegramip.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/telegramip.mrs"
interval: 86400
rules:
- RULE-SET,private,私有网络
- RULE-SET,microsoft-cn,微软服务
- RULE-SET,apple-cn,苹果服务
- RULE-SET,google-cn,谷歌服务
- RULE-SET,games-cn,游戏服务
- RULE-SET,games,游戏平台
- RULE-SET,ai,AI 平台
- RULE-SET,networktest,网络测试
- RULE-SET,proxy,国外域名
- RULE-SET,privateip,私有网络,no-resolve
- RULE-SET,cnip,全球直连
- RULE-SET,telegramip,电报消息,no-resolve
- MATCH,漏网之鱼
```
---
>`proxy-groups` 私货
{: .prompt-tip }
注:
- ① 本 `proxy-groups` 配置中,将不同的节点类型(如:`Shadowsocks``Trojan`)分别配置 `type: url-test` 进行延迟测试,且配置 `hidden: true` 以简化 Dashboard 面板中的显示。再将延迟测试最低的策略组配置 `type: load-balance` 进行负载均衡供用户选择使用
- ② 将不同的优选节点分别配置 `type: fallback` 进行故障转移,且配置 `hidden: true` 以简化 Dashboard 面板中的显示。再将故障转移后的策略组配置 `type: url-test` 进行延迟测试供用户选择使用
```yaml
proxy-groups:
- {name: 香港节点, type: load-balance, strategy: consistent-hashing, proxies: [香港-ss, 香港-trojan], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/hongkong.png"}
- {name: 香港-ss, type: url-test, tolerance: 50, use: [🛫 机场订阅], filter: "(?i)((🇭🇰|港|hk|hongkong|hong kong).*ss)", hidden: true, icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/shadowsocks.png"}
- {name: 香港-trojan, type: url-test, tolerance: 50, use: [🛫 机场订阅], filter: "(?i)(🇭🇰|港|hk|hongkong|hong kong)", exclude-filter: "(?i)(ss)", hidden: true, icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/trojan.png"}
- {name: 台湾节点, type: load-balance, strategy: consistent-hashing, proxies: [台湾-ss, 台湾-trojan], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/taiwan.png"}
- {name: 台湾-ss, type: url-test, tolerance: 50, use: [🛫 机场订阅], filter: "(?i)((🇹🇼|台|tw|taiwan|tai wan).*ss)", hidden: true, icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/shadowsocks.png"}
- {name: 台湾-trojan, type: url-test, tolerance: 50, use: [🛫 机场订阅], filter: "(?i)(🇹🇼|台|tw|taiwan|tai wan)", exclude-filter: "(?i)(ss)", hidden: true, icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/trojan.png"}
- {name: 日本节点, type: load-balance, strategy: consistent-hashing, proxies: [日本-ss, 日本-trojan], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/japan.png"}
- {name: 日本-ss, type: url-test, tolerance: 50, use: [🛫 机场订阅], filter: "(?i)((🇯🇵|日|jp|japan).*ss)", hidden: true, icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/shadowsocks.png"}
- {name: 日本-trojan, type: url-test, tolerance: 50, use: [🛫 机场订阅], filter: "(?i)(🇯🇵|日|jp|japan)", exclude-filter: "(?i)(ss)", hidden: true, icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/trojan.png"}
- {name: 新加坡节点, type: load-balance, strategy: consistent-hashing, proxies: [新加坡-ss, 新加坡-trojan], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/singapore.png"}
- {name: 新加坡-ss, type: url-test, tolerance: 50, use: [🛫 机场订阅], filter: "(?i)((🇸🇬|新|sg|singapore).*ss)", hidden: true, icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/shadowsocks.png"}
- {name: 新加坡-trojan, type: url-test, tolerance: 50, use: [🛫 机场订阅], filter: "(?i)(🇸🇬|新|sg|singapore)", exclude-filter: "(?i)(ss)", hidden: true, icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/trojan.png"}
- {name: 美国节点, type: load-balance, strategy: consistent-hashing, proxies: [美国-ss, 美国-trojan], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/unitedstates.png"}
- {name: 美国-ss, type: url-test, tolerance: 100, use: [🛫 机场订阅], filter: "(?i)((🇺🇸|美|us|unitedstates|united states).*ss)", hidden: true, icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/shadowsocks.png"}
- {name: 美国-trojan, type: url-test, tolerance: 100, use: [🛫 机场订阅], filter: "(?i)(🇺🇸|美|us|unitedstates|united states)", exclude-filter: "(?i)(ss)", hidden: true, icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/trojan.png"}
- {name: 免费节点, type: url-test, tolerance: 100, proxies: [移动优选节点, CF 优选节点], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/free.png"}
- {name: 移动优选节点, type: fallback, use: [🆓 免费订阅], filter: "(?i)(cmcc)", hidden: true, icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/cmcc.png"}
- {name: CF 优选节点, type: fallback, use: [🆓 免费订阅], filter: "(?i)(cfip)", hidden: true, icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/cfip.png"}
```
---
## 二、 导入 [mihomo 内核](https://github.com/MetaCubeX/mihomo)和 [CN_IP 文件](https://github.com/DustinWin/geoip)
连接 SSH 后执行如下命令:
```shell
curl -sS -o /tmp/CrashCore.upx -L https://ghfast.top/https://github.com/DustinWin/proxy-tools/releases/download/mihomo/mihomo-meta-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 加载,后选择 3 Mihomo(Meta) 内核
## 三、 编辑 user.yaml 文件
连接 SSH 后执行命令 `vi $CRASHDIR/yamls/user.yaml`,按一下 Ins 键(Insert 键),粘贴如下内容:
```yaml
log-level: error
allow-lan: true
unified-delay: true
tcp-concurrent: true
profile: {store-selected: true, store-fake-ip: true}
hosts:
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:
enable: true
prefer-h3: true
ipv6: true
listen: 0.0.0.0:1053
enhanced-mode: fake-ip
fake-ip-range: 28.0.0.0/8
fake-ip-range6: fc00::/16
fake-ip-filter-mode: rule
fake-ip-filter:
- RULE-SET,private,real-ip
- RULE-SET,trackerslist,real-ip
- RULE-SET,microsoft-cn,real-ip
- RULE-SET,apple-cn,real-ip
- RULE-SET,google-cn,real-ip
- RULE-SET,games-cn,real-ip
- RULE-SET,games,fake-ip
- RULE-SET,ai,fake-ip
- RULE-SET,proxy,fake-ip
- RULE-SET,cn,real-ip
- MATCH,fake-ip
nameserver:
- quic://dns.alidns.com:853
- https://dns.pub/dns-query
nameserver-policy:
'rule-set:private': [system]
'rule-set:ads': [rcode://success]
```
按一下 Esc 键(退出键),输入英文冒号 `:`,继续输入 `wq` 并回车
---
>`DNS` 私货
{: .prompt-tip }
注:
- ① 本 `dns` 配置中,国内域名走国内 DNS 解析,国外域名走 `fake-ip`,未知域名也走 `fake-ip`,在匹配 `RULE-SET:cn` 规则时会由国外 DNS 解析且配置 `ecs` 提高了兼容性,解析出 IP 在国内则走 `国内 IP` 规则,否则走 `漏网之鱼` 规则(有效解决了“心理 DNS 泄露问题”,详见《[搭载 mihomo 内核配置 DNS 不泄露教程-ruleset 方案](https://proxy-tutorials.dustinwin.us.kg/posts/dnsnoleaks-mihomo-ruleset/)》)
- ② 推荐将 `ecs` 设置为当前宽带运营商分配的默认 DNS(可进入光猫或路由器拨号页面查看,或者前往[公共 DNS 大全](https://toolb.cn/publicdns)查询)的 IP 段,如默认 DNS 为 `211.137.58.20`,可设置为 `211.137.58.0/24`
```yaml
hosts:
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]
dns:
enable: true
ipv6: true
listen: 0.0.0.0:1053
enhanced-mode: fake-ip
fake-ip-range: 28.0.0.0/8
fake-ip-range6: fc00::/16
fake-ip-filter-mode: rule
fake-ip-filter:
- RULE-SET,private,real-ip
- RULE-SET,trackerslist,real-ip
- RULE-SET,microsoft-cn,real-ip
- RULE-SET,apple-cn,real-ip
- RULE-SET,google-cn,real-ip
- RULE-SET,games-cn,real-ip
- RULE-SET,games,fake-ip
- RULE-SET,ai,fake-ip
- RULE-SET,proxy,fake-ip
- RULE-SET,cn,real-ip
- MATCH,fake-ip
respect-rules: true
nameserver:
# 推荐将 `ecs` 设置为当前宽带运营商分配的默认 DNS 的 IP 段
- 'https://dns.google/dns-query#ecs=211.137.58.0/24&ecs-override=true'
- 'quic://dns11.quad9.net:853#ecs=211.137.58.0/24&ecs-override=true'
proxy-server-nameserver:
- quic://dns.alidns.com:853
- https://doh.pub/dns-query
direct-nameserver:
- quic://dns.alidns.com:853
- https://doh.pub/dns-query
direct-nameserver-follow-policy: true
nameserver-policy:
'rule-set:private': [system]
'rule-set:ads': [rcode://success]
'rule-set:trackerslist,microsoft-cn,apple-cn,google-cn,games-cn,cn': [quic://dns.alidns.com:853, https://doh.pub/dns-query]
```
## 四、 添加定时任务
可参考《[ShellCrash 搭载 mihomo 内核的配置-ruleset 方案/添加定时任务](https://proxy-tutorials.dustinwin.us.kg/posts/toolsettings-shellcrash-mihomo-ruleset/#%E4%BA%8C-%E6%B7%BB%E5%8A%A0%E5%AE%9A%E6%97%B6%E4%BB%BB%E5%8A%A1)》
## 五、 设置部分
1. 设置可参考《[ShellCrash 搭载 mihomo 内核的配置-ruleset 方案/设置部分](https://proxy-tutorials.dustinwin.us.kg/posts/toolsettings-shellcrash-mihomo-ruleset/#%E4%B8%89-%E8%AE%BE%E7%BD%AE%E9%83%A8%E5%88%86)》,此处只列举配置的不同之处
2. 进入 ShellCrash 配置脚本 → 2) 功能设置 → 2) DNS 设置 → 9) 修改 DNS 服务器,设置如下:
<img src="/assets/img/dns/dns-null.png" alt="设置部分 2" width="60%" />
3. 进入 2) 功能设置 → 6) 自定义端口及密钥 → 5) 修改面板访问端口,修改为 `9090`
## 六、 访问 Dashboard 面板
打开 [zashboard](https://github.com/Zephyruso/zashboard) 在线面板地址 <http://board.zash.run.place> 后,直接在 [Clash API](https://sing-boxr.dustinwin.us.kg/zh/configuration/experimental/clash-api/) 标签里将“主机”修改为 `192.168.31.1`,点击“提交”即可访问 Dashboard 面板
> 推荐设置
{: .prompt-tip }
进入 zashboard → 设置 → 后端设置 → 修改后端配置,可设置“标签 (可选)”来快速识别不同设备
@@ -0,0 +1,422 @@
---
title: 分享 ShellCrash 搭载 mihomo 内核搭配 AdGuard Home 采用 ruleset 方案的一套配置
description: 此配置搭载 mihomo 内核,采用 <code>RULE-SET</code> 规则搭配 .list 和 .mrs 规则集合文件
date: 2024-08-21 18:23:54 +0800
categories: [分享配置, Router]
tags: [Clash, mihomo, ShellCrash, AdGuard Home, ruleset, rule-set, 分享, Router]
---
> 声明
{: .prompt-warning }
1. 此方案采用 [ShellCrash](https://github.com/juewuy/ShellCrash) 作为上游,[AdGuard Home](https://github.com/AdguardTeam/AdGuardHome) 作为下游的模式
2. 请根据自身情况进行修改,**适合自己的方案才是最好的方案**,如无特殊需求,可以照搬
3. 此方案中 ShellCrash 采用了**绕过 CN_IP** 的模式(仍与 AdGuard Home 配合完美)
4. 此方案适用于 ShellCrash(以 ARM64 架构为例,且安装路径为 `/data/ShellCrash`{: .filepath}
5. 此方案适用于 AdGuard Home(以 ARM64 架构为例,且安装路径为 `/data/AdGuardHome`{: .filepath}
6. 此方案不建议启用 ShellCrash 配置脚本 → 2) 功能设置 → 3) 透明路由流量过滤 → 2) 过滤局域网设备,因不经过内核的设备在访问 `漏网之鱼` 域名时会遇到无法访问的情况
7. 本人将路由器设置了每天早上 6 点重启,使得《[](https://proxy-tutorials.dustinwin.us.kg/posts/share-shellcrashadguardhome-mihomo-ruleset/#%E5%9B%9B-%E6%B7%BB%E5%8A%A0%E5%AE%9A%E6%97%B6%E4%BB%BB%E5%8A%A1)》中设置的定时任务生效
## 一、 生成配置文件 .yaml 文件直链
具体方法此处不再赘述,请看《[生成带有自定义策略组和规则的 mihomo 配置文件直链-ruleset 方案](https://proxy-tutorials.dustinwin.us.kg/posts/link-mihomo-ruleset)》,贴一下我使用的配置:
```yaml
proxy-providers:
🛫 机场订阅:
type: http
# 修改为你的 Clash 订阅链接
url: "https://example.com/xxx/xxx&flag=clash"
path: ./proxies/airport.yaml
interval: 86400
filter: "(?i)(🇭🇰|港|hk|hongkong|hong kong|🇹🇼|台|tw|taiwan|tai wan|🇯🇵|日|jp|japan|🇸🇬|新|sg|singapore|🇺🇸|美|us|unitedstates|united states)"
health-check:
enable: true
url: https://www.gstatic.com/generate_204
interval: 600
🆓 免费订阅:
type: http
# 修改为你的 Clash 订阅链接
url: "https://example.com/xxx/xxx&flag=clash"
path: ./proxies/free.yaml
interval: 86400
health-check:
enable: true
url: https://www.gstatic.com/generate_204
interval: 600
# 若没有单个出站代理节点,须删除所有 `🆚 vless 节点` 相关内容
proxies:
- name: 🆚 vless 节点
type: vless
server: example.com
port: 443
uuid: {uuid}
network: ws
tls: true
udp: false
sni: example.com
client-fingerprint: chrome
ws-opts:
path: "/?ed=2048"
headers:
host: example.com
proxy-groups:
- {name: 节点选择, type: select, proxies: [香港节点, 台湾节点, 日本节点, 新加坡节点, 美国节点, 免费节点, 🆚 vless 节点], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/proxy.png"}
- {name: 网络测试, type: select, proxies: [全球直连, 节点选择, 香港节点, 台湾节点, 日本节点, 新加坡节点, 美国节点, 免费节点, 🆚 vless 节点], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/networktest.png"}
- {name: 游戏平台, type: select, proxies: [节点选择, 香港节点, 台湾节点, 日本节点, 新加坡节点, 美国节点, 🆚 vless 节点], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/games.png"}
- {name: AI 平台, type: select, proxies: [节点选择, 香港节点, 台湾节点, 日本节点, 新加坡节点, 美国节点, 🆚 vless 节点], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/ai.png"}
- {name: 游戏服务, type: select, proxies: [全球直连, 节点选择], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/games-cn.png"}
- {name: 微软服务, type: select, proxies: [全球直连, 节点选择], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/microsoft-cn.png"}
- {name: 谷歌服务, type: select, proxies: [全球直连, 节点选择], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/google-cn.png"}
- {name: 苹果服务, type: select, proxies: [全球直连, 节点选择], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/apple-cn.png"}
- {name: 国外域名, type: select, proxies: [节点选择, 香港节点, 台湾节点, 日本节点, 新加坡节点, 美国节点, 免费节点, 🆚 vless 节点], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/global.png"}
- {name: 电报消息, type: select, proxies: [节点选择, 香港节点, 台湾节点, 日本节点, 新加坡节点, 美国节点, 免费节点, 🆚 vless 节点], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/telegram.png"}
- {name: 私有网络, type: select, proxies: [全球直连], hidden: true, icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/private.png"}
# 若机场的 UDP 质量不是很好,导致某游戏无法登录或进入房间,可以添加 `disable-udp: true` 配置项解决
- {name: 漏网之鱼, type: select, proxies: [节点选择, 香港节点, 台湾节点, 日本节点, 新加坡节点, 美国节点, 免费节点, 🆚 vless 节点, 全球直连], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/match.png"}
- {name: 全球直连, type: select, proxies: [DIRECT], hidden: true, icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/direct.png"}
- {name: 香港节点, type: url-test, tolerance: 50, use: [🛫 机场订阅], filter: "(?i)(🇭🇰|港|hk|hongkong|hong kong)", icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/hongkong.png"}
- {name: 台湾节点, type: url-test, tolerance: 50, use: [🛫 机场订阅], filter: "(?i)(🇹🇼|台|tw|taiwan|tai wan)", icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/taiwan.png"}
- {name: 日本节点, type: url-test, tolerance: 50, use: [🛫 机场订阅], filter: "(?i)(🇯🇵|日|jp|japan)", icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/japan.png"}
- {name: 新加坡节点, type: url-test, tolerance: 50, use: [🛫 机场订阅], filter: "(?i)(🇸🇬|新|sg|singapore)", icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/singapore.png"}
- {name: 美国节点, type: url-test, tolerance: 100, use: [🛫 机场订阅], filter: "(?i)(🇺🇸|美|us|unitedstates|united states)", icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/unitedstates.png"}
- {name: 免费节点, type: url-test, tolerance: 100, use: [🆓 免费订阅], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/free.png"}
rule-providers:
fakeip-filter:
type: http
behavior: domain
format: mrs
path: ./ruleset/fakeip-filter.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/fakeip-filter-lite.mrs"
interval: 86400
trackerslist:
type: http
behavior: domain
format: mrs
path: ./ruleset/trackerslist.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/trackerslist.mrs"
interval: 86400
private:
type: http
behavior: domain
format: mrs
path: ./ruleset/private.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/private.mrs"
interval: 86400
microsoft-cn:
type: http
behavior: domain
format: mrs
path: ./ruleset/microsoft-cn.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/microsoft-cn.mrs"
interval: 86400
apple-cn:
type: http
behavior: domain
format: mrs
path: ./ruleset/apple-cn.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/apple-cn.mrs"
interval: 86400
google-cn:
type: http
behavior: domain
format: mrs
path: ./ruleset/google-cn.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/google-cn.mrs"
interval: 86400
games-cn:
type: http
behavior: domain
format: mrs
path: ./ruleset/games-cn.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/games-cn.mrs"
interval: 86400
games:
type: http
behavior: domain
format: mrs
path: ./ruleset/games.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/games.mrs"
interval: 86400
ai:
type: http
behavior: domain
format: mrs
path: ./ruleset/ai.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/ai.mrs"
interval: 86400
networktest:
type: http
behavior: domain
format: mrs
path: ./ruleset/networktest.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/networktest.mrs"
interval: 86400
proxy:
type: http
behavior: domain
format: mrs
path: ./ruleset/proxy.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/proxy.mrs"
interval: 86400
cn:
type: http
behavior: domain
format: mrs
path: ./ruleset/cn.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/cn.mrs"
interval: 86400
privateip:
type: http
behavior: ipcidr
format: mrs
path: ./ruleset/privateip.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/privateip.mrs"
interval: 86400
cnip:
type: http
behavior: ipcidr
format: mrs
path: ./ruleset/cnip.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/cnip.mrs"
interval: 86400
telegramip:
type: http
behavior: ipcidr
format: mrs
path: ./ruleset/telegramip.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/telegramip.mrs"
interval: 86400
rules:
- RULE-SET,private,私有网络
- RULE-SET,microsoft-cn,微软服务
- RULE-SET,apple-cn,苹果服务
- RULE-SET,google-cn,谷歌服务
- RULE-SET,games-cn,游戏服务
- RULE-SET,games,游戏平台
- RULE-SET,ai,AI 平台
- RULE-SET,networktest,网络测试
- RULE-SET,proxy,国外域名
- RULE-SET,privateip,私有网络,no-resolve
- RULE-SET,cnip,全球直连
- RULE-SET,telegramip,电报消息,no-resolve
- MATCH,漏网之鱼
```
---
>`proxy-groups` 私货
{: .prompt-tip }
注:
- ① 本 `proxy-groups` 配置中,将不同的节点类型(如:`Shadowsocks``Trojan`)分别配置 `type: url-test` 进行延迟测试,且配置 `hidden: true` 以简化 Dashboard 面板中的显示。再将延迟测试最低的策略组配置 `type: load-balance` 进行负载均衡供用户选择使用
- ② 将不同的优选节点分别配置 `type: fallback` 进行故障转移,且配置 `hidden: true` 以简化 Dashboard 面板中的显示。再将故障转移后的策略组配置 `type: url-test` 进行延迟测试供用户选择使用
```yaml
proxy-groups:
- {name: 香港节点, type: load-balance, strategy: consistent-hashing, proxies: [香港-ss, 香港-trojan], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/hongkong.png"}
- {name: 香港-ss, type: url-test, tolerance: 50, use: [🛫 机场订阅], filter: "(?i)((🇭🇰|港|hk|hongkong|hong kong).*ss)", hidden: true, icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/shadowsocks.png"}
- {name: 香港-trojan, type: url-test, tolerance: 50, use: [🛫 机场订阅], filter: "(?i)(🇭🇰|港|hk|hongkong|hong kong)", exclude-filter: "(?i)(ss)", hidden: true, icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/trojan.png"}
- {name: 台湾节点, type: load-balance, strategy: consistent-hashing, proxies: [台湾-ss, 台湾-trojan], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/taiwan.png"}
- {name: 台湾-ss, type: url-test, tolerance: 50, use: [🛫 机场订阅], filter: "(?i)((🇹🇼|台|tw|taiwan|tai wan).*ss)", hidden: true, icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/shadowsocks.png"}
- {name: 台湾-trojan, type: url-test, tolerance: 50, use: [🛫 机场订阅], filter: "(?i)(🇹🇼|台|tw|taiwan|tai wan)", exclude-filter: "(?i)(ss)", hidden: true, icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/trojan.png"}
- {name: 日本节点, type: load-balance, strategy: consistent-hashing, proxies: [日本-ss, 日本-trojan], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/japan.png"}
- {name: 日本-ss, type: url-test, tolerance: 50, use: [🛫 机场订阅], filter: "(?i)((🇯🇵|日|jp|japan).*ss)", hidden: true, icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/shadowsocks.png"}
- {name: 日本-trojan, type: url-test, tolerance: 50, use: [🛫 机场订阅], filter: "(?i)(🇯🇵|日|jp|japan)", exclude-filter: "(?i)(ss)", hidden: true, icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/trojan.png"}
- {name: 新加坡节点, type: load-balance, strategy: consistent-hashing, proxies: [新加坡-ss, 新加坡-trojan], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/singapore.png"}
- {name: 新加坡-ss, type: url-test, tolerance: 50, use: [🛫 机场订阅], filter: "(?i)((🇸🇬|新|sg|singapore).*ss)", hidden: true, icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/shadowsocks.png"}
- {name: 新加坡-trojan, type: url-test, tolerance: 50, use: [🛫 机场订阅], filter: "(?i)(🇸🇬|新|sg|singapore)", exclude-filter: "(?i)(ss)", hidden: true, icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/trojan.png"}
- {name: 美国节点, type: load-balance, strategy: consistent-hashing, proxies: [美国-ss, 美国-trojan], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/unitedstates.png"}
- {name: 美国-ss, type: url-test, tolerance: 100, use: [🛫 机场订阅], filter: "(?i)((🇺🇸|美|us|unitedstates|united states).*ss)", hidden: true, icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/shadowsocks.png"}
- {name: 美国-trojan, type: url-test, tolerance: 100, use: [🛫 机场订阅], filter: "(?i)(🇺🇸|美|us|unitedstates|united states)", exclude-filter: "(?i)(ss)", hidden: true, icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/trojan.png"}
- {name: 免费节点, type: url-test, tolerance: 100, proxies: [移动优选节点, CF 优选节点], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/free.png"}
- {name: 移动优选节点, type: fallback, use: [🆓 免费订阅], filter: "(?i)(cmcc)", hidden: true, icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/cmcc.png"}
- {name: CF 优选节点, type: fallback, use: [🆓 免费订阅], filter: "(?i)(cfip)", hidden: true, icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/cfip.png"}
```
## 二、 导入 [mihomo 内核](https://github.com/MetaCubeX/mihomo)和 [CN_IP 文件](https://github.com/DustinWin/geoip)
连接 SSH 后执行如下命令:
```shell
curl -sS -o /tmp/CrashCore.upx -L https://ghfast.top/https://github.com/DustinWin/proxy-tools/releases/download/mihomo/mihomo-meta-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 加载,后选择 3 Mihomo(Meta) 内核
## 三、 编辑 user.yaml 文件
连接 SSH 后执行命令 `vi $CRASHDIR/yamls/user.yaml`,按一下 Ins 键(Insert 键),粘贴如下内容:
注:
- ① 由于 ShellCrash 采用的 DNS 模式为 `mix`**ShellCrash 传给 AdGuard Home 的国外域名对应 IP 为假 IP**,会导致 AdGuard Home 检查更新和下载更新 DNS 黑名单时失败
-`dns.fake-ip-filter` 中添加了 AdGuard Home 常用域名,包括:`adguardteam.github.io`AdGuard Home 自带 DNS 黑名单下载域名)、`adrules.top`(常用广告拦截下载域名)、`anti-ad.net`(常用广告拦截下载域名)和 `static.adtidy.org`AdGuard Home 检查更新域名),可使这些域名不走 `fakeip`
- ③ 不推荐使用自带更新去更新,推荐《[](https://proxy-tutorials.dustinwin.us.kg/posts/share-shellcrashadguardhome-mihomo-ruleset/#%E5%9B%9B-%E6%B7%BB%E5%8A%A0%E5%AE%9A%E6%97%B6%E4%BB%BB%E5%8A%A1)》中通过定时任务去自动更新(AdGuard Home 程序已被压缩,节省空间)
<img src="/assets/img/share/update-adguardhome.png" alt="编辑 user.yaml 文件" width="60%" />
```yaml
log-level: error
allow-lan: true
unified-delay: true
tcp-concurrent: true
profile: {store-selected: true, store-fake-ip: true}
hosts:
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:
enable: true
prefer-h3: true
ipv6: true
listen: 0.0.0.0:1053
enhanced-mode: fake-ip
fake-ip-range: 28.0.0.0/8
fake-ip-range6: fc00::/16
fake-ip-filter-mode: rule
fake-ip-filter:
- RULE-SET,fakeip-filter,real-ip
- RULE-SET,private,real-ip
- RULE-SET,trackerslist,real-ip
- RULE-SET,microsoft-cn,real-ip
- RULE-SET,apple-cn,real-ip
- RULE-SET,google-cn,real-ip
- RULE-SET,games-cn,real-ip
- RULE-SET,games,fake-ip
- RULE-SET,ai,fake-ip
- RULE-SET,proxy,fake-ip
- RULE-SET,cn,real-ip
- MATCH,fake-ip
nameserver:
- quic://dns.alidns.com:853
- https://dns.pub/dns-query
nameserver-policy:
'rule-set:private': [system]
```
按一下 Esc 键(退出键),输入英文冒号 `:`,继续输入 `wq` 并回车
---
>`DNS` 私货
{: .prompt-tip }
注:
- ① 本 `dns` 配置中,国内域名走国内 DNS 解析,国外域名走 `fake-ip`,未知域名也走 `fake-ip`,在匹配 `RULE-SET:cn` 规则时会由国外 DNS 解析且配置 `ecs` 提高了兼容性,解析出 IP 在国内则走 `国内 IP` 规则,否则走 `漏网之鱼` 规则(有效解决了“心理 DNS 泄露问题”,详见《[搭载 mihomo 内核配置 DNS 不泄露教程-ruleset 方案](https://proxy-tutorials.dustinwin.us.kg/posts/dnsnoleaks-mihomo-ruleset/)》)
- ② 推荐将 `ecs` 设置为当前宽带运营商分配的默认 DNS(可进入光猫或路由器拨号页面查看,或者前往[公共 DNS 大全](https://toolb.cn/publicdns)查询)的 IP 段,如默认 DNS 为 `211.137.58.20`,可设置为 `211.137.58.0/24`
```yaml
hosts:
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]
dns:
enable: true
ipv6: true
listen: 0.0.0.0:1053
enhanced-mode: fake-ip
fake-ip-range: 28.0.0.0/8
fake-ip-range6: fc00::/16
fake-ip-filter-mode: rule
fake-ip-filter:
- RULE-SET,fakeip-filter,real-ip
- RULE-SET,private,real-ip
- RULE-SET,trackerslist,real-ip
- RULE-SET,microsoft-cn,real-ip
- RULE-SET,apple-cn,real-ip
- RULE-SET,google-cn,real-ip
- RULE-SET,games-cn,real-ip
- RULE-SET,games,fake-ip
- RULE-SET,ai,fake-ip
- RULE-SET,proxy,fake-ip
- RULE-SET,cn,real-ip
- MATCH,fake-ip
respect-rules: true
nameserver:
# 推荐将 `ecs` 设置为当前宽带运营商分配的默认 DNS 的 IP 段
- 'https://dns.google/dns-query#ecs=211.137.58.0/24&ecs-override=true'
- 'quic://dns11.quad9.net:853#ecs=211.137.58.0/24&ecs-override=true'
proxy-server-nameserver:
- quic://dns.alidns.com:853
- https://doh.pub/dns-query
direct-nameserver:
- quic://dns.alidns.com:853
- https://doh.pub/dns-query
direct-nameserver-follow-policy: true
nameserver-policy:
'rule-set:private': [system]
'rule-set:fakeip-filter,trackerslist,microsoft-cn,apple-cn,google-cn,games-cn,cn': [quic://dns.alidns.com:853, https://doh.pub/dns-query]
```
## 四、 添加定时任务
1. 连接 SSH 后执行命令 `vi $CRASHDIR/configs/task/task.user`,按一下 Ins 键(Insert 键),粘贴如下内容:
```shell
201#curl -sS -o $CRASHDIR/cn_ip.txt -L https://ghfast.top/https://github.com/DustinWin/geoip/releases/download/ips/cn_ipv4.txt && curl -sS -o $CRASHDIR/cn_ipv6.txt -L https://ghfast.top/https://github.com/DustinWin/geoip/releases/download/ips/cn_ipv6.txt >/dev/null 2>&1#更新CN_IP文件
202#curl -sS -o /data/AdGuardHome/AdGuardHome -L https://ghfast.top/https://github.com/DustinWin/proxy-tools/releases/download/AdGuardHome/AdGuardHome_beta_linux_arm64 >/dev/null 2>&1#更新AdGuardHome
```
2. 按一下 Esc 键(退出键),输入英文冒号 `:`,继续输入 `wq` 并回车
3. 执行 `sc`,进入 ShellCrash 配置脚本 → 5) 自动任务 → 1) 添加自动任务,可以看到末尾就有添加的定时任务,输入对应的数字并回车后可设置执行条件
<img src="/assets/img/share/task-adguardhome.png" alt="添加定时任务" width="60%" />
## 五、 ShellCrash 设置
1. 设置可参考《[ShellCrash 搭载 mihomo 内核的配置-ruleset 方案/设置部分](https://proxy-tutorials.dustinwin.us.kg/posts/toolsettings-shellcrash-mihomo-ruleset/#%E4%B8%89-%E8%AE%BE%E7%BD%AE%E9%83%A8%E5%88%86)》,此处只列举配置的不同之处
2. 进入 ShellCrash 配置脚本 → 2) 功能设置 → 2) DNS 设置 → 7) DNS 劫持端口,设置为“5353”(须完成《[](https://proxy-tutorials.dustinwin.us.kg/posts/share-shellcrashadguardhome-mihomo-ruleset/#%E5%85%AD-%E5%AE%89%E8%A3%85-adguard-home)》后才可设置)
3. 进入 2) DNS 设置 → 9) 修改 DNS 服务器,设置如下:
<img src="/assets/img/dns/dns-null.png" alt="ShellCrash 设置 2" width="60%" />
3. 进入 2) 功能设置 → 6) 自定义端口及密钥 → 5) 修改面板访问端口,修改为 `9090`
## 六、 安装 AdGuard Home
连接 SSH 后执行如下命令:
```shell
mkdir -p /data/AdGuardHome
curl -sS -o /data/AdGuardHome/AdGuardHome -L https://ghfast.top/https://github.com/DustinWin/proxy-tools/releases/download/AdGuardHome/AdGuardHome_beta_linux_arm64
chmod +x /data/AdGuardHome/AdGuardHome
/data/AdGuardHome/AdGuardHome -s install
/data/AdGuardHome/AdGuardHome -s start
iptables -t nat -A PREROUTING -p tcp --dport 53 -j REDIRECT --to-ports 5353
iptables -t nat -A PREROUTING -p udp --dport 53 -j REDIRECT --to-ports 5353
ip6tables -t nat -A PREROUTING -p tcp --dport 53 -j REDIRECT --to-ports 5353
ip6tables -t nat -A PREROUTING -p udp --dport 53 -j REDIRECT --to-ports 5353
cat <<EOF >> /data/auto_ssh/auto_ssh.sh
sleep 10s
/data/AdGuardHome/AdGuardHome -s install
/data/AdGuardHome/AdGuardHome -s start
iptables -t nat -A PREROUTING -p tcp --dport 53 -j REDIRECT --to-ports 5353
iptables -t nat -A PREROUTING -p udp --dport 53 -j REDIRECT --to-ports 5353
ip6tables -t nat -A PREROUTING -p tcp --dport 53 -j REDIRECT --to-ports 5353
ip6tables -t nat -A PREROUTING -p udp --dport 53 -j REDIRECT --to-ports 5353
EOF
```
## 七、 AdGuard Home 设置
设置可参考《[全网最详细的解锁 SSH ShellCrash 搭载 mihomo 内核搭配 AdGuard Home 安装和配置教程/AdGuard Home 配置](https://proxy-tutorials.dustinwin.us.kg/posts/pin-shellcrashadguardhome-mihomo/#2-adguard-home-%E9%85%8D%E7%BD%AE)》
## 八、 访问面板
1. 打开 [zashboard](https://github.com/Zephyruso/zashboard) 在线面板地址 <http://board.zash.run.place> 后,直接在 [Clash API](https://sing-boxr.dustinwin.us.kg/zh/configuration/experimental/clash-api/) 标签里将“主机”修改为 `192.168.31.1`,点击“提交”即可访问 Dashboard 面板
2. 打开 <http://miwifi.com:3000> 即可访问 AdGuard Home 面板
> 推荐设置
{: .prompt-tip }
进入 zashboard → 设置 → 后端设置 → 修改后端配置,可设置“标签 (可选)”来快速识别不同设备
@@ -0,0 +1,77 @@
---
title: ShellCrash 搭载 mihomo 内核的配置-geodata 方案
description: 此配置搭载 mihomo 内核,包括 ShellCrash 的安装、导入路由规则文件、配置和使用方法
date: 2024-08-21 06:30:11 +0800
categories: [工具配置, ShellCrash 配置]
tags: [Clash, mihomo, ShellCrash, geodata, geosite, 基础, Router]
---
> 说明
{: .prompt-tip }
1. 本教程中的下载链接以 CPU 架构 ARM64 为例,若为别的 CPU 架构,请注意修改链接后缀
2. 查看 CPU 架构可连接 SSH 后执行命令 `uname -ms`,若执行结果是“linux aarch64”,就是搭载的 ARM64 架构
## 一、 导入 [mihomo 内核](https://github.com/MetaCubeX/mihomo)
连接 SSH 后执行如下命令:
```shell
curl -sS -o /tmp/CrashCore.upx -L https://ghfast.top/https://github.com/DustinWin/proxy-tools/releases/download/mihomo/mihomo-meta-linux-arm64.upx
```
## 二、 导入路由规则文件
连接 SSH 后执行如下命令:
```shell
curl -sS -o $CRASHDIR/GeoSite.dat -L https://cdn.jsdelivr.net/gh/DustinWin/ruleset_geodata@mihomo-geodata/geosite.dat
curl -sS -o $CRASHDIR/Country.mmdb -L https://cdn.jsdelivr.net/gh/DustinWin/ruleset_geodata@mihomo-geodata/Country-lite.mmdb
```
## 三、 添加定时任务
1. 连接 SSH 后执行命令 `vi $CRASHDIR/configs/task/task.user`,按一下 Ins 键(Insert 键),粘贴如下内容:
- 注:须重启 ShellCrash 服务后生效
```shell
201#curl -sS -o $CRASHDIR/GeoSite.dat -L https://cdn.jsdelivr.net/gh/DustinWin/ruleset_geodata@mihomo-geodata/geosite.dat && curl -sS -o $CRASHDIR/Country.mmdb -L https://cdn.jsdelivr.net/gh/DustinWin/ruleset_geodata@mihomo-geodata/Country-lite.mmdb >/dev/null 2>&1#更新geodata路由规则文件
202#curl -sS -o $CRASHDIR/cn_ip.txt -L https://ghfast.top/https://github.com/DustinWin/geoip/releases/download/ips/cn_ipv4.txt && curl -sS -o $CRASHDIR/cn_ipv6.txt -L https://ghfast.top/https://github.com/DustinWin/geoip/releases/download/ips/cn_ipv6.txt >/dev/null 2>&1#更新CN_IP文件
```
2. 按一下 Esc 键(退出键),输入英文冒号 `:`,继续输入 `wq` 并回车
3. 执行 `sc`,进入 ShellCrash 配置脚本 → 5) 自动任务 → 1) 添加自动任务,可以看到末尾就有添加的定时任务,输入对应的数字并回车后可设置执行条件
<img src="/assets/img/share/task-geodata.png" alt="添加定时任务" width="60%" />
## 四、 设置部分
1. 连接 SSH 后执行命令 `sc` 即可打开 ShellCrash 配置脚本(若安装 ShellCrash 后自定义别名选择的是“2) 【 sc 】”)
2. 新手引导
- ① 选择“1) 路由设备配置局域网透明代理”
- ② 根据需要是否启用小内存模式(此处选择“0”)
- ③ 启用推荐的自动任务配置
- ④ 根据需要是否开始导入配置文件(此处选择“0”)
- ⑤ 此时脚本会自动“发现可用的内核文件”,选择“1) 立即加载”,后选择“1) Mihomo(Meta)”
<img src="/assets/img/pin/import-mihomo.png" alt="ShellCrash 配置 1" width="60%" />
- ⑥ 内核加载完成后根据需要是否保留相关数据库文件(此处选择“0) 不保留”)
3. 功能设置
- ① 进入 2) DNS 设置 → 9) 修改 DNS 服务器,选择“4) 一键配置加密 DNS”(推荐设置 DNS 分流,请看《[搭载 mihomo 内核进行 DNS 分流教程-geodata 方案](https://proxy-tutorials.dustinwin.us.kg/posts/dnsbypass-mihomo-geodata)》)
- ② 进入 2) 功能设置 → 5) 启用域名嗅探,选择“1) 是”
4. 进入主菜单 → 4 启动设置,启用“1) 开机自启动”
5. 进入主菜单 → 5) 自动任务 → 1) 添加自动任务,选择 8) 自动更新内核,回车后可设置执行条件
6. 进入主菜单 → 8) 工具与优化,选择“6) 小米设备软固化 SSH”(无需输入需要还原的 SSH 密码)
7. 进入 8) 工具与优化 → 8) 小米设备Tun模块修复,选择“1) 我已知晓,出现问题会自行承担!”
8. 进入主菜单 → 9) 更新与支持 → 2) 切换/更新内核文件 → 6) 使用自定义内核 → 9) 自定义内核链接,输入导入内核命令里的链接并回车,选择“1) Mihomo(Meta)”
9. 进入 9) 更新与支持 → 4) 安装/更新本地Dashboard面板,推荐安装“1) 安装 zashboard 面板”
10. 导入配置文件
- ① 进入主菜单 → 6) 配置文件管理 → a) 添加提供者 → 1) 设置名称或代号,如输入“mihomo”;后进入 2) 设置链接或路径,粘贴《[生成带有自定义策略组和规则的 mihomo 配置文件直链-geodata 方案](https://proxy-tutorials.dustinwin.us.kg/posts/link-mihomo-geodata)》中生成的 .yaml 配置文件直链,选择“a) 保存此提供者”
- ② 进入 6) 配置文件管理 → c) 在线生成配置文件 → 6) 自定义浏览器 UA,选择“2) 不使用 UA”
- ③ 进入 6) 配置文件管理 → 1) mihomo,选择“e) 在线获取此配置文件”,启动服务即可
11. 访问 Dashboard 面板
- ① 打开 <http://192.168.31.1:9999/ui/> 后,直接在“[Clash API](https://sing-boxr.dustinwin.us.kg/zh/configuration/experimental/clash-api/)”标签里将“主机”和“端口”分别修改为 `192.168.31.1``9999`,点击“提交”即可访问 Dashboard 面板
<img src="/assets/img/tools/192-9999-dashboard.png" alt="设置部分 2" width="60%" />
- ② 进入 Dashboard 面板 → 代理 → 代理提供者,点击“转圈”图标,可手动更新节点
## 五、 在线 Dashboard 面板(可选)
1. 若使用基于 [Chromium 项目](https://www.chromium.org/Home/)开发的浏览器无法访问在线 Dashboard 面板时,以 [Chrome 浏览器](https://www.google.com/chrome/)为例,需要设置该网址域名“允许显示不安全内容”,进入设置 → 隐私和安全 → 网站设置 → 更多内容设置 → 不安全内容(或者直接在地址栏打开 `chrome://settings/content/insecureContent` 进行设置),在“允许显示不安全内容”内添加网址域名 `board.zash.run.place`
<img src="/assets/img/tools/chrome-setting-dashboard.png" alt="在线 Dashboard 面板 1" width="60%" />
1. 打开 [zashboard](https://github.com/Zephyruso/zashboard) 在线面板地址 <http://board.zash.run.place> 后,直接在“Clash API”标签里将“主机”和“端口”分别修改为 `192.168.31.1``9999`,点击“提交”即可访问 Dashboard 面板
<img src="/assets/img/tools/192-9999-dashboard.png" alt="在线 Dashboard 面板 2" width="60%" />
@@ -0,0 +1,374 @@
---
title: ShellCrash 搭载 mihomo 内核本地配置自定义策略组和规则-geodata 方案
description: 此教程搭载 mihomo 内核,可通过修改本地配置文件的方式来自定义策略组和规则 <code>GEOSITE</code> 和 <code>GEOIP</code>
date: 2024-08-21 08:27:14 +0800
categories: [工具配置, ShellCrash 配置]
tags: [Clash, mihomo, ShellCrash, geodata, geosite, 进阶, 本地, Router]
---
> 说明
{: .prompt-tip }
1. 本教程只适用于 [ShellCrash](https://github.com/juewuy/ShellCrash)
2. 本教程**仅适合白名单模式**(没有命中规则的网络流量统统使用代理,适用于服务器线路网络质量稳定、快速,不缺服务器流量的用户)
3. 本教程最终效果媲美《[生成带有自定义策略组和规则的 mihomo 配置文件直链-geodata 方案](https://proxy-tutorials.dustinwin.us.kg/posts/link-mihomo-geodata)》(策略组更直观,操作更方便)
4. 若仅配置自定义策略组和规则,可直接跳过《[](https://proxy-tutorials.dustinwin.us.kg/posts/toolsettings-shellcrash-mihomo-local-geodata/#%E4%BA%8C-%E5%AF%BC%E5%85%A5%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6)》
5. 所有步骤完成后,请连接 SSH 后执行命令 `$CRASHDIR/start.sh restart` 生效
6. 推荐使用 [Visual Studio Code](https://code.visualstudio.com/Download) 等专业编辑器来修改配置文件
## 一、 导入 [mihomo 内核](https://github.com/MetaCubeX/mihomo)和[路由规则文件](https://github.com/DustinWin/ruleset_geodata?tab=readme-ov-file#%E4%B8%80-geodata-%E6%96%87%E4%BB%B6%E8%AF%B4%E6%98%8E)
可参考《[ShellCrash 搭载 mihomo 内核的配置-geodata 方案](https://proxy-tutorials.dustinwin.us.kg/posts/toolsettings-shellcrash-mihomo-geodata)》里的《[](https://proxy-tutorials.dustinwin.us.kg/posts/toolsettings-shellcrash-mihomo-geodata/#%E4%B8%80-%E5%AF%BC%E5%85%A5-mihomo-%E5%86%85%E6%A0%B8)》和《[](https://proxy-tutorials.dustinwin.us.kg/posts/toolsettings-shellcrash-mihomo-geodata/#%E4%BA%8C-%E5%AF%BC%E5%85%A5%E8%B7%AF%E7%94%B1%E8%A7%84%E5%88%99%E6%96%87%E4%BB%B6)》进行操作
## 二、 导入配置文件
1. 进入 ShellCrash → 6 管理配置文件 → 1 在线生成配置文件 → 4 选取在线配置规则模版,选择 4 [ACL4SSR](https://acl4ssr-sub.github.io) 极简版(适合自建节点)
<img src="/assets/img/tools/subscribe-easy.png" alt="导入配置文件" width="60%" />
2. 进入 ShellCrash → 6 管理配置文件 → 1 在线生成配置文件,输入订阅链接后回车,再输入 `1` 并回车即可
## 三、 自定义策略组和规则
### 1. 自定义 others.yaml(用于编写自定义的锚点、入站、代理集合 `proxy-providers`、子规则 `sub-rules` 和 script 脚本等功能)
连接 SSH 后执行命令 `vi $CRASHDIR/yamls/others.yaml`,按一下 Ins 键(Insert 键),粘贴如下内容:
```yaml
# 代理集合(获取机场订阅链接内的所有节点)
proxy-providers:
🛫 机场订阅 1:
type: http
# 机场订阅链接,使用 Clash 链接
url: "https://example.com/xxx/xxx&flag=clash"
path: ./proxies/airport1.yaml
interval: 86400
# 初步筛选需要的节点,可有效减轻路由器压力,支持正则表达式,不筛选可删除此配置项
filter: "(?i)(🇭🇰|港|hk|hongkong|hong kong|🇹🇼|台|tw|taiwan|tai wan|🇯🇵|日|jp|japan|🇸🇬|新|sg|singapore|🇺🇸|美|us|unitedstates|united states)"
# 初步排除不需要的节点,支持正则表达式,若不排除可删除此配置项
exclude-filter: "高倍|直连|×10"
health-check:
enable: true
url: https://www.gstatic.com/generate_204
interval: 600
override:
# 为节点名称添加固定前缀,如节点名称原为“香港节点”会变成“🛫 机场订阅 1-香港节点”;推荐有多个机场时使用
additional-prefix: "🛫 机场订阅 1-"
# 为节点名称添加固定后缀,如节点名称原为“香港节点”会变成“香港节点-🛫 机场订阅 1”;推荐有多个机场时使用
additional-suffix: "-🛫 机场订阅 1"
🛫 机场订阅 2:
type: http
url: "https://example.com/xxx/xxx&flag=clash"
path: ./proxies/airport2.yaml
interval: 43200
filter: "(?i)(🇭🇰|港|hk|hongkong|hong kong|🇹🇼|台|tw|taiwan|tai wan|🇯🇵|日|jp|japan|🇸🇬|新|sg|singapore|🇺🇸|美|us|unitedstates|united states)"
exclude-filter: "高倍|直连|×10"
health-check:
enable: true
url: https://www.gstatic.com/generate_204
interval: 600
override:
# 为节点名称添加固定前缀,如节点名称原为“香港节点”会变成“🛫 机场订阅 2-香港节点”;推荐有多个机场时使用
additional-prefix: "🛫 机场订阅 2-"
# 为节点名称添加固定后缀,如节点名称原为“香港节点”会变成“香港节点-🛫 机场订阅 2”;推荐有多个机场时使用
additional-suffix: "-🛫 机场订阅 2"
```
按一下 Esc 键(退出键),输入英文冒号 `:`,继续输入 `wq` 并回车
### 2. 自定义 proxies.yaml(用于添加自定义出站代理 `proxies`)
连接 SSH 后执行命令 `vi $CRASHDIR/yamls/proxies.yaml`,按一下 Ins 键(Insert 键),粘贴如下内容:
注:
- ① 此处以“vless”节点类型为例,其它节点类型写法可参考[通用字段](https://wiki.metacubex.one/config/proxies)
- ② 必须在 proxy-groups.yaml 里添加自定义的节点才可以正常选择和使用
```yaml
- name: 🆓 免费节点
# 节点类型
type: vless
# 代理节点服务器(域名/IP
server: example.com
port: 443
uuid: {uuid}
network: ws
tls: true
udp: false
sni: example.com
client-fingerprint: chrome
ws-opts:
path: "/?ed=2048"
headers:
host: example.com
```
按一下 Esc 键(退出键),输入英文冒号 `:`,继续输入 `wq` 并回车
### 3. 自定义 proxy-groups.yaml(用于添加自定义策略组 `proxy-groups`
连接 SSH 后执行命令 `vi $CRASHDIR/yamls/proxy-groups.yaml`,按一下 Ins 键(Insert 键),粘贴如下内容:
```yaml
# 策略组
# 手动选择国家或地区节点;根据“国家或地区策略组”名称对 `proxies` 值进行增删改,须一一对应
- name: 🈯 节点指定
type: select
proxies:
- ♻️ 自动选择
- 👉 手动选择
- 🇭🇰 香港节点
- 🇹🇼 台湾节点
- 🇯🇵 日本节点
- 🇸🇬 新加坡节点
- 🇺🇸 美国节点
# 添加 proxies.yaml 中的自定义节点
- 🆓 免费节点
# 选择 `🎯 全球直连` 为测试本地网络(运营商网络速度和 IPv6 支持情况),可选择其它节点用于测试机场节点速度和 IPv6 支持情况
- name: 📈 网络测试
type: select
proxies:
- 🎯 全球直连
- 🈯 节点指定
- 🇭🇰 香港节点
- 🇹🇼 台湾节点
- 🇯🇵 日本节点
- 🇸🇬 新加坡节点
- 🇺🇸 美国节点
- 🆓 免费节点
- name: 🕹️ 游戏平台
type: select
proxies:
- 🈯 节点指定
- 🇭🇰 香港节点
- 🇹🇼 台湾节点
- 🇯🇵 日本节点
- 🇸🇬 新加坡节点
- 🇺🇸 美国节点
- name: 🤖 AI 平台
type: select
proxies:
- 🈯 节点指定
- 🇭🇰 香港节点
- 🇹🇼 台湾节点
- 🇯🇵 日本节点
- 🇸🇬 新加坡节点
- 🇺🇸 美国节点
- name: 🎮 游戏服务
type: select
proxies:
- 🎯 全球直连
- 🈯 节点指定
- name: 🪟 微软服务
type: select
proxies:
- 🎯 全球直连
- 🈯 节点指定
- name: 🇬 谷歌服务
type: select
proxies:
- 🎯 全球直连
- 🈯 节点指定
- name: 🍎 苹果服务
type: select
proxies:
- 🎯 全球直连
- 🈯 节点指定
- name: 🌍 国外媒体
type: select
proxies:
- 🈯 节点指定
- 🇭🇰 香港节点
- 🇹🇼 台湾节点
- 🇯🇵 日本节点
- 🇸🇬 新加坡节点
- 🇺🇸 美国节点
- name: 🇨🇳 国内域名
type: select
proxies:
- 🎯 全球直连
- 🈯 节点指定
- name: 🀄️ 国内 IP
type: select
proxies:
- 🎯 全球直连
- 🈯 节点指定
- name: 🌎 国外域名
type: select
proxies:
- 🈯 节点指定
- 🇭🇰 香港节点
- 🇹🇼 台湾节点
- 🇯🇵 日本节点
- 🇸🇬 新加坡节点
- 🇺🇸 美国节点
- 🆓 免费节点
- name: 📲 电报消息
type: select
proxies:
- 🈯 节点指定
- 🇭🇰 香港节点
- 🇹🇼 台湾节点
- 🇯🇵 日本节点
- 🇸🇬 新加坡节点
- 🇺🇸 美国节点
- 🆓 免费节点
- name: 🔒 私有网络
type: select
proxies:
- 🎯 全球直连
hidden: true
- name: 🛑 广告域名
type: select
proxies:
- 🔴 全球拦截
- 🟢 全球绕过
- name: 🔴 全球拦截
type: select
proxies:
- REJECT
hidden: true
- name: 🟢 全球绕过
type: select
proxies:
- PASS
hidden: true
# ----------------国家或地区策略组---------------------
# 自动选择节点,即按照 url 测试结果使用延迟最低的节点
- name: 🇭🇰 香港节点
type: url-test
# 测试后容差大于 50ms 才会切换到延迟低的那个节点
tolerance: 50
include-all: true
# 筛选出“香港”节点,支持正则表达式
filter: "(?i)(🇭🇰|港|hk|hongkong|hong kong)"
- name: 🇹🇼 台湾节点
type: url-test
tolerance: 50
include-all: true
filter: "(?i)(🇹🇼|台|tw|taiwan|tai wan)"
- name: 🇯🇵 日本节点
type: url-test
tolerance: 50
include-all: true
filter: "(?i)(🇯🇵|日|jp|japan)"
- name: 🇸🇬 新加坡节点
type: url-test
tolerance: 50
include-all: true
filter: "(?i)(🇸🇬|新|sg|singapore)"
- name: 🇺🇸 美国节点
type: url-test
tolerance: 100
include-all: true
filter: "(?i)(🇺🇸|美|us|unitedstates|united states)"
- name: 👉 手动选择
type: select
include-all: true
```
按一下 Esc 键(退出键),输入英文冒号 `:`,继续输入 `wq` 并回车
### 4. 自定义 rules.yaml(用于添加自定义规则 `rules`)
连接 SSH 后执行命令 `vi $CRASHDIR/yamls/rules.yaml`,按一下 Ins 键(Insert 键),粘贴如下内容:
```yaml
# 规则
# 自定义规则优先放前面
- GEOSITE,private,🔒 私有网络
- GEOSITE,ads,🛑 广告域名
- GEOSITE,microsoft-cn,🪟 微软服务
- GEOSITE,apple-cn,🍎 苹果服务
- GEOSITE,google-cn,🇬 谷歌服务
- GEOSITE,games-cn,🎮 游戏服务
- GEOSITE,games,🕹️ 游戏平台
- GEOSITE,media,🌍 国外媒体
- GEOSITE,ai,🤖 AI 平台
- GEOSITE,networktest,📈 网络测速
- GEOSITE,proxy,🌎 国外域名
- GEOSITE,cn,🇨🇳 国内域名
- GEOIP,private,🔒 私有网络,no-resolve
- GEOIP,cn,🀄️ 国内 IP
- GEOIP,telegram,📲 电报消息,no-resolve
- GEOIP,media,🌍 国外媒体
```
按一下 Esc 键(退出键),输入英文冒号 `:`,继续输入 `wq` 并回车
## 四、 修改策略组或规则
**举例:我想让 [Netflix](https://www.netflix.com/) 和 [Disney+](https://www.disneyplus.com/) 等国外媒体自动选择延迟最低的新加坡节点**
> 一定要保证缩进对齐!一定要保证缩进对齐!一定要保证缩进对齐!
{: .prompt-warning }
### 1. 修改 proxy-groups.yaml 文件
连接 SSH 后执行命令 `vi $CRASHDIR/yamls/proxy-groups.yaml`,按一下 Ins 键(Insert 键),粘贴如下内容:
```yaml
# 策略组
# 默认选择新加坡节点
- name: 🌍 国外媒体
type: select
proxies:
- 🇸🇬 新加坡节点
# 自动选择延迟最低的新加坡节点;容差大于 50ms 才会切换到延迟低的那个节点
- name: 🇸🇬 新加坡节点
type: url-test
tolerance: 50
include-all: true
filter: "(?i)(🇸🇬|新|sg|singapore)"
```
按一下 Esc 键(退出键),输入英文冒号 `:`,继续输入 `wq` 并回车
### 2. 修改 rules.yaml 文件
连接 SSH 后执行命令 `vi $CRASHDIR/yamls/rules.yaml`,按一下 Ins 键(Insert 键),**优先在最上方**粘贴如下内容:
```yaml
# 规则
# 自定义规则优先放前面
- GEOSITE,media,🌍 国外媒体
- GEOIP,media,🌍 国外媒体
```
按一下 Esc 键(退出键),输入英文冒号 `:`,继续输入 `wq` 并回车
> 若有其它需求,可导入 [MetaCubeX/meta-rules-dat](https://github.com/MetaCubeX/meta-rules-dat) 路由规则文件,并分别进入 [MetaCubeX/meta-rules-dat/meta/geo](https://github.com/MetaCubeX/meta-rules-dat/tree/meta/geo) 的 *geosite* 和 *geoip* 目录搜索关键字,通过能够搜索到的关键字来编写策略组和规则
{: .prompt-tip }
## 五、 添加小规则
仅添加特定网址走直连或走代理,连接 SSH 后执行命令 `vi $CRASHDIR/yamls/rules.yaml`,按一下 Ins 键(Insert 键),在**最上方**粘贴如下内容:
注:
- ① 以下内容只是举例,请根据自身需要进行增删改
- ② 其它规则请参考《[mihomo Wiki](https://wiki.metacubex.one/config/rules)》
```yaml
# 规则
# 以 googleapis.cn 为后缀(包括 googleapis.cn)的所有域名走代理
- DOMAIN-SUFFIX,googleapis.cn,🈯 节点指定
# 与哔哩哔哩相关的所有域名走直连
- GEOSITE,bilibili,DIRECT
# 含有 ipv6 关键字的所有域名走直连
- DOMAIN-KEYWORD,ipv6,DIRECT
```
按一下 Esc 键(退出键),输入英文冒号 `:`,继续输入 `wq` 并回车
@@ -0,0 +1,549 @@
---
title: ShellCrash 搭载 mihomo 内核本地配置自定义策略组和规则-ruleset 方案
description: 此教程搭载 mihomo 内核,可通过修改本地配置文件的方式来自定义策略组和规则 <code>RULE-SET</code>
date: 2024-08-21 08:39:18 +0800
categories: [工具配置, ShellCrash 配置]
tags: [Clash, ShellCrash, ruleset, rule-set, 进阶, 本地, Router]
---
> 说明
{: .prompt-tip }
1. 本教程只适用于 [ShellCrash](https://github.com/juewuy/ShellCrash)
2. 本教程**仅适合白名单模式**(没有命中规则的网络流量统统使用代理,适用于服务器线路网络质量稳定、快速,不缺服务器流量的用户)
3. 本教程最终效果媲美《[生成带有自定义策略组和规则的 mihomo 配置文件直链-ruleset 方案](https://proxy-tutorials.dustinwin.us.kg/posts/link-mihomo-ruleset)》(策略组更直观,操作更方便)
4. 若仅配置自定义策略组和规则,可直接跳过《[](https://proxy-tutorials.dustinwin.us.kg/posts/toolsettings-shellcrash-mihomo-local-ruleset/#%E4%BA%8C-%E5%AF%BC%E5%85%A5%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6)》
5. 所有步骤完成后,请连接 SSH 后执行命令 `$CRASHDIR/start.sh restart` 生效
6. 推荐使用 [Visual Studio Code](https://code.visualstudio.com/Download) 等专业编辑器来修改配置文件
## 一、 导入 [mihomo 内核](https://github.com/MetaCubeX/mihomo)
可参考《[ShellCrash 搭载 mihomo 内核的配置-ruleset 方案/导入 mihomo 内核](https://proxy-tutorials.dustinwin.us.kg/posts/toolsettings-shellcrash-mihomo-ruleset/#%E4%B8%80-%E5%AF%BC%E5%85%A5-mihomo-%E5%86%85%E6%A0%B8)》里的步骤进行操作
## 二、 导入配置文件
1. 进入 ShellCrash → 6 管理配置文件 → 1 在线生成配置文件 → 4 选取在线配置规则模版,选择 4 [ACL4SSR](https://acl4ssr-sub.github.io) 极简版(适合自建节点)
<img src="/assets/img/tools/subscribe-easy.png" alt="导入配置文件" width="60%" />
2. 进入 ShellCrash → 6 管理配置文件 → 1 在线生成配置文件,输入订阅链接后回车,再输入 `1` 并回车即可
## 三、 自定义策略组和规则
### 1. 自定义 others.yaml(用于编写自定义的锚点、入站、代理集合 `proxy-providers`、子规则 `sub-rules`、规则集合 `rule-provider` 和 script 脚本等功能)
连接 SSH 后执行命令 `vi $CRASHDIR/yamls/others.yaml`,按一下 Ins 键(Insert 键),粘贴如下内容:
```yaml
# 代理集合(获取机场订阅链接内的所有节点)
proxy-providers:
🛫 机场订阅 1:
type: http
# 机场订阅链接,使用 Clash 链接
url: "https://example.com/xxx/xxx&flag=clash"
path: ./proxies/airport1.yaml
interval: 86400
# 初步筛选需要的节点,可有效减轻路由器压力,支持正则表达式,不筛选可删除此配置项
filter: "(?i)(🇭🇰|港|hk|hongkong|hong kong|🇹🇼|台|tw|taiwan|tai wan|🇯🇵|日|jp|japan|🇸🇬|新|sg|singapore|🇺🇸|美|us|unitedstates|united states)"
# 初步排除不需要的节点,支持正则表达式,若不排除可删除此配置项
exclude-filter: "高倍|直连|×10"
health-check:
enable: true
url: https://www.gstatic.com/generate_204
interval: 600
override:
# 为节点名称添加固定前缀,如节点名称原为“香港节点”会变成“🛫 机场订阅 1-香港节点”;推荐有多个机场时使用
additional-prefix: "🛫 机场订阅 1-"
# 为节点名称添加固定后缀,如节点名称原为“香港节点”会变成“香港节点-🛫 机场订阅 1”;推荐有多个机场时使用
additional-suffix: "-🛫 机场订阅 1"
🛫 机场订阅 2:
type: http
url: "https://example.com/xxx/xxx&flag=clash"
path: ./proxies/airport2.yaml
interval: 43200
filter: "(?i)(🇭🇰|港|hk|hongkong|hong kong|🇹🇼|台|tw|taiwan|tai wan|🇯🇵|日|jp|japan|🇸🇬|新|sg|singapore|🇺🇸|美|us|unitedstates|united states)"
exclude-filter: "高倍|直连|×10"
health-check:
enable: true
url: https://www.gstatic.com/generate_204
interval: 600
override:
# 为节点名称添加固定前缀,如节点名称原为“香港节点”会变成“🛫 机场订阅 2-香港节点”;推荐有多个机场时使用
additional-prefix: "🛫 机场订阅 2-"
# 为节点名称添加固定后缀,如节点名称原为“香港节点”会变成“香港节点-🛫 机场订阅 2”;推荐有多个机场时使用
additional-suffix: "-🛫 机场订阅 2"
# 规则集(yaml 文件每天自动更新)
rule-providers:
ads:
type: http
behavior: domain
format: mrs
path: ./ruleset/ads.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/ads.mrs"
interval: 86400
private:
type: http
behavior: domain
format: mrs
path: ./ruleset/private.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/private.mrs"
interval: 86400
microsoft-cn:
type: http
behavior: domain
format: mrs
path: ./ruleset/microsoft-cn.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/microsoft-cn.mrs"
interval: 86400
apple-cn:
type: http
behavior: domain
format: mrs
path: ./ruleset/apple-cn.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/apple-cn.mrs"
interval: 86400
google-cn:
type: http
behavior: domain
format: mrs
path: ./ruleset/google-cn.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/google-cn.mrs"
interval: 86400
games-cn:
type: http
behavior: domain
format: mrs
path: ./ruleset/games-cn.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/games-cn.mrs"
interval: 86400
games:
type: http
behavior: domain
format: mrs
path: ./ruleset/games.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/games.mrs"
interval: 86400
media:
type: http
behavior: domain
format: mrs
path: ./ruleset/media.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/media.mrs"
interval: 86400
ai:
type: http
behavior: domain
format: mrs
path: ./ruleset/ai.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/ai.mrs"
interval: 86400
networktest:
type: http
behavior: classical
format: text
path: ./ruleset/networktest.list
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/networktest.list"
interval: 86400
proxy:
type: http
behavior: domain
format: mrs
path: ./ruleset/proxy.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/proxy.mrs"
interval: 86400
cn:
type: http
behavior: domain
format: mrs
path: ./ruleset/cn.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/cn.mrs"
interval: 86400
privateip:
type: http
behavior: ipcidr
format: mrs
path: ./ruleset/privateip.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/privateip.mrs"
interval: 86400
cnip:
type: http
behavior: ipcidr
format: mrs
path: ./ruleset/cnip.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/cnip.mrs"
interval: 86400
telegramip:
type: http
behavior: ipcidr
format: mrs
path: ./ruleset/telegramip.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/telegramip.mrs"
interval: 86400
mediaip:
type: http
behavior: ipcidr
format: mrs
path: ./ruleset/mediaip.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/mediaip.mrs"
interval: 86400
```
按一下 Esc 键(退出键),输入英文冒号 `:`,继续输入 `wq` 并回车
### 2. 自定义 proxies.yaml(用于添加自定义出站代理 `proxies`)
连接 SSH 后执行命令 `vi $CRASHDIR/yamls/proxies.yaml`,按一下 Ins 键(Insert 键),粘贴如下内容:
注:
- ① 此处以“vless”节点类型为例,其它节点类型写法可参考[通用字段](https://wiki.metacubex.one/config/proxies)
- ② 必须在 proxy-groups.yaml 里添加自定义的节点才可以正常选择和使用
```yaml
- name: 🆓 免费节点
# 节点类型
type: vless
# 代理节点服务器(域名/IP
server: example.com
port: 443
uuid: {uuid}
network: ws
tls: true
udp: false
sni: example.com
client-fingerprint: chrome
ws-opts:
path: "/?ed=2048"
headers:
host: example.com
```
按一下 Esc 键(退出键),输入英文冒号 `:`,继续输入 `wq` 并回车
### 3. 自定义 proxy-groups.yaml(用于添加自定义策略组 `proxy-groups`
连接 SSH 后执行命令 `vi $CRASHDIR/yamls/proxy-groups.yaml`,按一下 Ins 键(Insert 键),粘贴如下内容:
```yaml
# 策略组
# 手动选择国家或地区节点;根据“国家或地区策略组”名称对 `proxies` 值进行增删改,须一一对应
- name: 🈯 节点指定
type: select
proxies:
- ♻️ 自动选择
- 👉 手动选择
- 🇭🇰 香港节点
- 🇹🇼 台湾节点
- 🇯🇵 日本节点
- 🇸🇬 新加坡节点
- 🇺🇸 美国节点
# 添加 proxies.yaml 中的自定义节点
- 🆓 免费节点
# 选择 `🎯 全球直连` 为测试本地网络(运营商网络速度和 IPv6 支持情况),可选择其它节点用于测试机场节点速度和 IPv6 支持情况
- name: 📈 网络测试
type: select
proxies:
- 🎯 全球直连
- 🈯 节点指定
- 🇭🇰 香港节点
- 🇹🇼 台湾节点
- 🇯🇵 日本节点
- 🇸🇬 新加坡节点
- 🇺🇸 美国节点
- 🆓 免费节点
- name: 🕹️ 游戏平台
type: select
proxies:
- 🈯 节点指定
- 🇭🇰 香港节点
- 🇹🇼 台湾节点
- 🇯🇵 日本节点
- 🇸🇬 新加坡节点
- 🇺🇸 美国节点
- name: 🤖 AI 平台
type: select
proxies:
- 🈯 节点指定
- 🇭🇰 香港节点
- 🇹🇼 台湾节点
- 🇯🇵 日本节点
- 🇸🇬 新加坡节点
- 🇺🇸 美国节点
- name: 🎮 游戏服务
type: select
proxies:
- 🎯 全球直连
- 🈯 节点指定
- name: 🪟 微软服务
type: select
proxies:
- 🎯 全球直连
- 🈯 节点指定
- name: 🇬 谷歌服务
type: select
proxies:
- 🎯 全球直连
- 🈯 节点指定
- name: 🍎 苹果服务
type: select
proxies:
- 🎯 全球直连
- 🈯 节点指定
- name: 🌍 国外媒体
type: select
proxies:
- 🈯 节点指定
- 🇭🇰 香港节点
- 🇹🇼 台湾节点
- 🇯🇵 日本节点
- 🇸🇬 新加坡节点
- 🇺🇸 美国节点
- name: 🇨🇳 国内域名
type: select
proxies:
- 🎯 全球直连
- 🈯 节点指定
- name: 🀄️ 国内 IP
type: select
proxies:
- 🎯 全球直连
- 🈯 节点指定
- name: 🌎 国外域名
type: select
proxies:
- 🈯 节点指定
- 🇭🇰 香港节点
- 🇹🇼 台湾节点
- 🇯🇵 日本节点
- 🇸🇬 新加坡节点
- 🇺🇸 美国节点
- 🆓 免费节点
- name: 📲 电报消息
type: select
proxies:
- 🈯 节点指定
- 🇭🇰 香港节点
- 🇹🇼 台湾节点
- 🇯🇵 日本节点
- 🇸🇬 新加坡节点
- 🇺🇸 美国节点
- 🆓 免费节点
- name: 🔒 私有网络
type: select
proxies:
- 🎯 全球直连
hidden: true
- name: 🛑 广告域名
type: select
proxies:
- 🔴 全球拦截
- 🟢 全球绕过
- name: 🔴 全球拦截
type: select
proxies:
- REJECT
hidden: true
- name: 🟢 全球绕过
type: select
proxies:
- PASS
hidden: true
# ----------------国家或地区策略组---------------------
# 自动选择节点,即按照 url 测试结果使用延迟最低的节点
- name: 🇭🇰 香港节点
type: url-test
# 测试后容差大于 50ms 才会切换到延迟低的那个节点
tolerance: 50
include-all: true
# 筛选出“香港”节点,支持正则表达式
filter: "(?i)(🇭🇰|港|hk|hongkong|hong kong)"
- name: 🇹🇼 台湾节点
type: url-test
tolerance: 50
include-all: true
filter: "(?i)(🇹🇼|台|tw|taiwan|tai wan)"
- name: 🇯🇵 日本节点
type: url-test
tolerance: 50
include-all: true
filter: "(?i)(🇯🇵|日|jp|japan)"
- name: 🇸🇬 新加坡节点
type: url-test
tolerance: 50
include-all: true
filter: "(?i)(🇸🇬|新|sg|singapore)"
- name: 🇺🇸 美国节点
type: url-test
tolerance: 100
include-all: true
filter: "(?i)(🇺🇸|美|us|unitedstates|united states)"
- name: 👉 手动选择
type: select
include-all: true
```
按一下 Esc 键(退出键),输入英文冒号 `:`,继续输入 `wq` 并回车
### 4. 自定义 rules.yaml(用于添加自定义规则 `rules`)
连接 SSH 后执行命令 `vi $CRASHDIR/yamls/rules.yaml`,按一下 Ins 键(Insert 键),粘贴如下内容:
```yaml
# 规则
# 自定义规则优先放前面
- RULE-SET,private,🔒 私有网络
- RULE-SET,ads,🛑 广告域名
- RULE-SET,microsoft-cn,🪟 微软服务
- RULE-SET,apple-cn,🍎 苹果服务
- RULE-SET,google-cn,🇬 谷歌服务
- RULE-SET,games-cn,🎮 游戏服务
- RULE-SET,games,🕹️ 游戏平台
- RULE-SET,media,🌍 国外媒体
- RULE-SET,ai,🤖 AI 平台
- RULE-SET,networktest,📈 网络测试
- RULE-SET,proxy,🌎 国外域名
- RULE-SET,cn,🇨🇳 国内域名
- RULE-SET,privateip,🔒 私有网络,no-resolve
- RULE-SET,cnip,🀄️ 国内 IP
- RULE-SET,telegramip,📲 电报消息,no-resolve
- RULE-SET,mediaip,🌍 国外媒体
```
按一下 Esc 键(退出键),输入英文冒号 `:`,继续输入 `wq` 并回车
## 四、 修改策略组或规则
**举例:我的机场包含有 2 个节点,分别是新加坡节点和日本节点,我想让 [Netflix](https://www.netflix.com/) 自动选择延迟最低的新加坡节点,[哔哩哔哩](https://www.bilibili.com)可以手动选择日本任一节点**
> 一定要保证缩进对齐!一定要保证缩进对齐!一定要保证缩进对齐!
{: .prompt-warning }
### 1. 修改 others.yaml 文件
连接 SSH 后执行命令 `vi $CRASHDIR/yamls/others.yaml`,按一下 Ins 键(Insert 键),在 `rule-providers` 内粘贴如下内容:
```yaml
# 规则集(yaml 文件每天自动更新)
netflix:
type: http
behavior: domain
format: mrs
path: ./ruleset/netflix.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/netflix.mrs"
interval: 86400
netflixip:
type: http
behavior: ipcidr
format: mrs
path: ./ruleset/netflixip.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/netflixip.mrs"
interval: 86400
bilibili:
type: http
behavior: domain
format: mrs
path: ./ruleset/bilibili.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/bilibili.mrs"
interval: 86400
```
按一下 Esc 键(退出键),输入英文冒号 `:`,继续输入 `wq` 并回车
### 2. 修改 proxy-groups.yaml 文件
连接 SSH 后执行命令 `vi $CRASHDIR/yamls/proxy-groups.yaml`,按一下 Ins 键(Insert 键),粘贴如下内容:
```yaml
# 策略组
# 默认选择新加坡节点
- name: 🎥 奈飞视频
type: select
proxies:
- 🇸🇬 新加坡节点
# 默认选择日本节点,也可切换到直连
- name: 📺 哔哩哔哩
type: select
proxies:
- 🇯🇵 日本节点
- 🎯 全球直连
# 自动选择延迟最低的新加坡节点;容差大于 50ms 才会切换到延迟低的那个节点
- name: 🇸🇬 新加坡节点
type: url-test
tolerance: 50
include-all: true
filter: "(?i)(🇸🇬|新|sg|singapore)"
# 手动选择日本任一节点
- name: 🇯🇵 日本节点
type: select
include-all: true
filter: "(?i)(🇯🇵|日|jp|japan)"
```
按一下 Esc 键(退出键),输入英文冒号 `:`,继续输入 `wq` 并回车
### 3. 修改 rules.yaml 文件
连接 SSH 后执行命令 `vi $CRASHDIR/yamls/rules.yaml`,按一下 Ins 键(Insert 键),**优先在最上方**粘贴如下内容:
```yaml
# 规则
# 自定义规则优先放前面
- RULE-SET,netflix,🎥 奈飞视频
- RULE-SET,netflixip,🎥 奈飞视频
- RULE-SET,bilibili,📺 哔哩哔哩
```
按一下 Esc 键(退出键),输入英文冒号 `:`,继续输入 `wq` 并回车
> 若有其它需求,可进入 [blackmatrix7/ios_rule_script/rule/Clash](https://github.com/blackmatrix7/ios_rule_script/tree/master/rule/Clash) 搜索关键字,通过能够搜索到的关键字来编写策略组和规则(推荐使用“xxx_Classical.yaml”文件,`rule-provider` 内须配置 `behavior: classical`
{: .prompt-tip }
## 五、 添加小规则
仅添加特定网址走直连或走代理,连接 SSH 后执行命令 `vi $CRASHDIR/yamls/rules.yaml`,按一下 Ins 键(Insert 键),在**最上方**粘贴如下内容:
注:
- ① 以下内容只是举例,请根据自身需要进行增删改
- ② 其它规则请参考《[mihomo Wiki](https://wiki.metacubex.one/config/rules)》
```yaml
# 规则
# 以 googleapis.cn 为后缀(包括 googleapis.cn)的所有域名走代理
- DOMAIN-SUFFIX,googleapis.cn,🈯 节点指定
# 含有 ipv6 关键字的所有域名走直连
- DOMAIN-KEYWORD,ipv6,DIRECT
```
按一下 Esc 键(退出键),输入英文冒号 `:`,继续输入 `wq` 并回车
@@ -0,0 +1,68 @@
---
title: ShellCrash 搭载 mihomo 内核的配置-ruleset 方案
description: 此配置搭载 mihomo 内核,包括 ShellCrash 的安装、配置和使用方法
date: 2024-08-21 06:53:20 +0800
categories: [工具配置, ShellCrash 配置]
tags: [Clash, mihomo, ShellCrash, ruleset, rule-set, 基础, Router]
---
> 说明
{: .prompt-tip }
1. 本教程中的下载链接以 CPU 架构 ARM64 为例,若为别的 CPU 架构,请注意修改链接后缀
2. 查看 CPU 架构可连接 SSH 后执行命令 `uname -ms`,若执行结果是“linux aarch64”,就是搭载的 ARM64 架构
## 一、 导入 [mihomo 内核](https://github.com/MetaCubeX/mihomo)
连接 SSH 后执行如下命令:
```shell
curl -sS -o /tmp/CrashCore.upx -L https://ghfast.top/https://github.com/DustinWin/proxy-tools/releases/download/mihomo/mihomo-meta-linux-arm64.upx
```
## 二、 添加定时任务
1. 连接 SSH 后执行命令 `vi $CRASHDIR/configs/task/task.user`,按一下 Ins 键(Insert 键),粘贴(快捷键 Ctrl+Shift+V)如下内容:
- 注:须重启 ShellCrash 服务后生效
```shell
201#curl -sS -o $CRASHDIR/cn_ip.txt -L https://ghfast.top/https://github.com/DustinWin/geoip/releases/download/ips/cn_ipv4.txt && curl -sS -o $CRASHDIR/cn_ipv6.txt -L https://ghfast.top/https://github.com/DustinWin/geoip/releases/download/ips/cn_ipv6.txt >/dev/null 2>&1#更新CN_IP文件
```
2. 按一下 Esc 键(退出键),输入英文冒号 `:`,继续输入 `wq` 并回车
3. 执行 `sc`,进入 ShellCrash 配置脚本 → 5) 自动任务 → 1) 添加自动任务,可以看到末尾就有添加的定时任务,输入对应的数字并回车后可设置执行条件
<img src="/assets/img/share/task-ruleset.png" alt="添加定时任务" width="60%" />
## 三、 设置部分
1. 连接 SSH 后执行命令 `sc` 即可打开 ShellCrash 配置脚本(若安装 ShellCrash 后自定义别名选择的是“2) 【 sc 】”)
2. 新手引导
- ① 选择“1) 路由设备配置局域网透明代理”
- ② 根据需要是否启用小内存模式(此处选择“0”)
- ③ 启用推荐的自动任务配置
- ④ 根据需要是否开始导入配置文件(此处选择“0”)
- ⑤ 此时脚本会自动“发现可用的内核文件”,选择“1) 立即加载”,后选择“1) Mihomo(Meta)”
<img src="/assets/img/pin/import-mihomo.png" alt="ShellCrash 配置 1" width="60%" />
- ⑥ 内核加载完成后根据需要是否保留相关数据库文件(此处选择“0) 不保留”)
3. 功能设置
- ① 进入 2) DNS 设置 → 9) 修改 DNS 服务器,选择“4) 一键配置加密 DNS”(推荐设置 DNS 分流,请看《[搭载 mihomo 内核进行 DNS 分流教程-geodata 方案](https://proxy-tutorials.dustinwin.us.kg/posts/dnsbypass-mihomo-geodata)》)
- ② 进入 2) 功能设置 → 5) 启用域名嗅探,选择“1) 是”
4. 进入主菜单 → 4 启动设置,启用“1) 开机自启动”
5. 进入主菜单 → 5) 自动任务 → 1) 添加自动任务,选择 8) 自动更新内核,回车后可设置执行条件
6. 进入主菜单 → 8) 工具与优化,选择“6) 小米设备软固化 SSH”(无需输入需要还原的 SSH 密码)
7. 进入 8) 工具与优化 → 8) 小米设备Tun模块修复,选择“1) 我已知晓,出现问题会自行承担!”
8. 进入主菜单 → 9) 更新与支持 → 2) 切换/更新内核文件 → 6) 使用自定义内核 → 9) 自定义内核链接,输入导入内核命令里的链接并回车,选择“1) Mihomo(Meta)”
9. 进入 9) 更新与支持 → 4) 安装/更新本地Dashboard面板,推荐安装“1) 安装 zashboard 面板”
10. 导入配置文件
- ① 进入主菜单 → 6) 配置文件管理 → a) 添加提供者 → 1) 设置名称或代号,如输入“mihomo”;后进入 2) 设置链接或路径,粘贴《[生成带有自定义策略组和规则的 mihomo 配置文件直链-ruleset 方案](https://proxy-tutorials.dustinwin.us.kg/posts/link-mihomo-ruleset)》中生成的 .yaml 配置文件直链,选择“a) 保存此提供者”
- ② 进入 6) 配置文件管理 → c) 在线生成配置文件 → 6) 自定义浏览器 UA,选择“2) 不使用 UA”
- ③ 进入 6) 配置文件管理 → 1) mihomo,选择“e) 在线获取此配置文件”,启动服务即可
11. 访问 Dashboard 面板
- ① 打开 <http://192.168.31.1:9999/ui/> 后,直接在“[Clash API](https://sing-boxr.dustinwin.us.kg/zh/configuration/experimental/clash-api/)”标签里将“主机”和“端口”分别修改为 `192.168.31.1``9999`,点击“提交”即可访问 Dashboard 面板
<img src="/assets/img/tools/192-9999-dashboard.png" alt="设置部分 2" width="60%" />
- ② 进入 Dashboard 面板 → 代理 → 代理提供者,点击“转圈”图标,可手动更新节点
## 四、 在线 Dashboard 面板(可选)
1. 若使用基于 [Chromium 项目](https://www.chromium.org/Home/)开发的浏览器无法访问在线 Dashboard 面板时,以 [Chrome 浏览器](https://www.google.com/chrome/)为例,需要设置该网址域名“允许显示不安全内容”,进入设置 → 隐私和安全 → 网站设置 → 更多内容设置 → 不安全内容(或者直接在地址栏打开 `chrome://settings/content/insecureContent` 进行设置),在“允许显示不安全内容”内添加网址域名 `board.zash.run.place`
<img src="/assets/img/tools/chrome-setting-dashboard.png" alt="在线 Dashboard 面板 1" width="60%" />
1. 打开 [zashboard](https://github.com/Zephyruso/zashboard) 在线面板地址 <http://board.zash.run.place> 后,直接在“Clash API”标签里将“主机”和“端口”分别修改为 `192.168.31.1``9999`,点击“提交”即可访问 Dashboard 面板
<img src="/assets/img/tools/192-9999-dashboard.png" alt="在线 Dashboard 面板 2" width="60%" />
@@ -0,0 +1,111 @@
---
title: 搭载 sing-boxr 内核进行 DNS 分流教程-ruleset方案
description: 此教程搭载 sing-boxr 内核并使用其特性进行 DNS 分流,即指定国内域名 <code>rule_set:cn</code> 走国内 DNS 解析,国外域名走 <code>fake-ip</code>
date: 2024-08-22 18:24:06 +0800
categories: [DNS 配置, DNS 分流]
tags: [sing-box, sing-boxr, ShellCrash, ruleset, rule_set, 进阶, DNS, DNS 分流]
---
> 说明
{: .prompt-tip }
1. [ShellCrash](https://github.com/juewuy/ShellCrash) 搭配 [AdGuard Home](https://github.com/AdguardTeam/AdGuardHome) 并将 AdGuard Home 作为上游时不要使用该方法
2. 本教程以 ShellCrash 为例,其它客户端亦可参考
3. 本教程搭载 [sing-box 内核 reF1nd-Testing 版](https://github.com/reF1nd/sing-box/tree/reF1nd-testing)(导入内核方法可参考《[ShellCrash 和 AdGuard Home 快速安装教程/导入 mihomo 内核 或 sing-box 内核](https://proxy-tutorials.dustinwin.us.kg/posts/pin-toolsinstall/#%E4%BA%8C-%E5%AF%BC%E5%85%A5-mihomo-%E5%86%85%E6%A0%B8-%E6%88%96-sing-box-%E5%86%85%E6%A0%B8)》)
4. DNS 分流简单来说就是**指定国内域名走国内 DNS 解析,国外域名走 `fakeip`**。未知域名在匹配 `rule_set:cnip` 规则时会先由国内 DNS 解析,解析出 IP 在国内则直接返回解析结果且走 `国内 IP` 规则,否则走 `fakeip` 且走 `漏网之鱼` 规则
5. 部分用户觉得未知域名处理方式会导致 DNS 泄露,可参考《[搭载 sing-boxr 内核配置 DNS 不泄露教程-ruleset 方案](https://proxy-tutorials.dustinwin.us.kg/posts/dnsnoleaks-singboxr-ruleset)》
## 一、 导入规则集合文件
`route.rule_set` 须添加 `fakeip-filter``proxy``cn``cnip`,如下:
```json
{
"route": {
"rule_set": [
{
"tag": "fakeip-filter",
"type": "remote",
"format": "binary",
"path": "./ruleset/fakeip-filter.srs",
"url": "https://github.com/DustinWin/ruleset_geodata/releases/download/sing-box-ruleset/fakeip-filter.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"
}
]
}
}
```
## 二、 DNS 分流配置
1. 进入 ShellCrash 配置脚本 → 2) 功能设置 → 2) DNS 设置 → 9) 修改 DNS 服务器,将“DIRECT-DNS”、“PROXY-DNS”和“DEFAULT-DNS”都设置为 `null`
<img src="/assets/img/dns/dns-null.png" alt="ShellCrash 设置" width="60%" />
2. 连接 SSH 后执行如下命令:
```shell
sed -i 's/"ip_accept_any": true,/"preferred_by": [ "hosts" ],/' "$CRASHDIR/starts/singbox_modify.sh"
```
3. 连接 SSH 后执行命令 `vi $CRASHDIR/jsons/dns.json`,按一下 Ins 键(Insert 键),粘贴如下内容:
- 注:推荐将 `client_subnet` 设置为当前宽带运营商分配的默认 DNS(可进入光猫或路由器拨号页面查看,或者前往[公共 DNS 大全](https://toolb.cn/publicdns)查询)的 IP 段,如默认 DNS 为 `211.137.58.20`,可设置为 `211.137.58.0/24`
```json
{
"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": "28.0.0.0/8", "inet6_range": "fc00::/16" }
],
"rules": [
{ "clash_mode": [ "Direct" ], "server": "dns_direct" },
{ "clash_mode": [ "Global" ], "server": "dns_proxy" },
{ "rule_set": [ "fakeip-filter" ], "server": "dns_direct" },
{ "rule_set": [ "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" },
{ "match_response": true, "ip_accept_any": true, "invert": true, "action": "respond" },
{ "query_type": [ "A", "AAAA" ], "server": "dns_fakeip" }
],
"final": "dns_proxy",
"strategy": "prefer_ipv4",
"optimistic": true,
"reverse_mapping": true,
// 推荐将 `client_subnet` 设置为当前宽带运营商分配的默认 DNS 的 IP 段
"client_subnet": "211.137.58.0/24"
}
}
```
按一下 Esc 键(退出键),输入英文冒号 `:`,继续输入 `wq` 并回车
@@ -0,0 +1,210 @@
---
title: 搭载 sing-boxr 内核配置 DNS 不泄露教程-ruleset 方案
description: 此教程搭载 sing-boxr 内核并使用其特性防止 DNS 泄露,即针对未知域名走国外 DNS 解析
date: 2024-08-22 16:51:20 +0800
categories: [DNS 配置, DNS 防泄漏]
tags: [sing-box, sing-boxr, ShellCrash, ruleset, rule_set, 进阶, DNS, DNS 泄露]
---
> 说明
{: .prompt-tip }
1. 此方案彻底防止了 DNS 泄露(未知域名在匹配 `rule_set:cnip` 规则时会先由国外 DNS 解析且配置 `client_subnet`,解析出 IP 在国内则直接返回解析结果且走 `国内 IP` 规则,否则走 `fakeip` 且走 `漏网之鱼` 规则),兼容性高,可放心使用
2. 本教程以 [ShellCrash](https://github.com/juewuy/ShellCrash) 为例,其它客户端亦可参考
3. 本教程搭载 [sing-box 内核 reF1nd-Testing 版](https://github.com/reF1nd/sing-box/tree/reF1nd-testing)(导入内核方法可参考《[ShellCrash 和 AdGuard Home 快速安装教程/导入 mihomo 内核 或 sing-box 内核](https://proxy-tutorials.dustinwin.us.kg/posts/pin-toolsinstall/#%E4%BA%8C-%E5%AF%BC%E5%85%A5-mihomo-%E5%86%85%E6%A0%B8-%E6%88%96-sing-box-%E5%86%85%E6%A0%B8)》)
4. 可进入 <https://ipleak.net> 测试 DNS 是否泄露,“DNS Addresses” 栏目下没有中国国旗(因 `ipleak.net` 属未知域名,默认走 `漏网之鱼` 规则),即代表 DNS 没有发生泄露
## 一、 导入规则集合文件
`route.rule_set` 须添加 `fakeip-filter``proxy``cn``cnip`,如下:
```json
{
"route": {
"rule_set": [
{
"tag": "fakeip-filter",
"type": "remote",
"format": "binary",
"path": "./ruleset/fakeip-filter.srs",
"url": "https://github.com/DustinWin/ruleset_geodata/releases/download/sing-box-ruleset/fakeip-filter.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"
}
]
}
}
```
## 二、 ShellCrash 防泄漏配置
1. 进入 ShellCrash 配置脚本 → 2) 功能设置 → 2) DNS 设置 → 9) 修改 DNS 服务器,将“DIRECT-DNS”、“PROXY-DNS”和“DEFAULT-DNS”都设置为 `null`
<img src="/assets/img/dns/dns-null.png" alt="ShellCrash 设置" width="60%" />
2. 连接 SSH 后执行如下命令:
```shell
sed -i 's/"ip_accept_any": true,/"preferred_by": [ "hosts" ],/' "$CRASHDIR/starts/singbox_modify.sh"
```
## 三、 DNS 防泄漏配置
### 1. DNS 模式为 `mix`(推荐)
- ① 连接 SSH 后执行命令 `vi $CRASHDIR/jsons/dns.json`,按一下 Ins 键(Insert 键),修改为如下内容:
>推荐将 `client_subnet` 设置为当前宽带运营商分配的默认 DNS(可进入光猫或路由器拨号页面查看,或者前往[公共 DNS 大全](https://toolb.cn/publicdns)查询)的 IP 段,如默认 DNS 为 `211.137.58.20`,可设置为 `211.137.58.0/24`
{: .prompt-info }
```json
{
"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": "28.0.0.0/8", "inet6_range": "fc00::/16" }
],
"rules": [
{ "clash_mode": [ "Direct" ], "server": "dns_direct" },
{ "clash_mode": [ "Global" ], "server": "dns_proxy" },
{ "rule_set": [ "fakeip-filter" ], "server": "dns_direct" },
{ "rule_set": [ "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" },
{ "match_response": true, "ip_accept_any": true, "invert": true, "action": "respond" },
{ "query_type": [ "A", "AAAA" ], "server": "dns_fakeip" }
],
"final": "dns_proxy",
"strategy": "prefer_ipv4",
"optimistic": true,
"reverse_mapping": true
}
}
```
- ② 按一下 Esc 键(退出键),输入英文冒号 `:`,继续输入 `wq` 并回车
### 2. DNS 模式为 `fakeip`(不推荐)
- ① 连接 SSH 后执行命令 `vi $CRASHDIR/jsons/dns.json`,按一下 Ins 键(Insert 键),修改为如下内容:
>推荐将 `client_subnet` 设置为当前宽带运营商分配的默认 DNS(可进入光猫或路由器拨号页面查看,或者前往[公共 DNS 大全](https://toolb.cn/publicdns)查询)的 IP 段,如默认 DNS 为 `211.137.58.20`,可设置为 `211.137.58.0/24`
{: .prompt-info }
```json
{
"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": "28.0.0.0/8", "inet6_range": "fc00::/16" }
],
"rules": [
{ "clash_mode": [ "Direct" ], "server": "dns_direct" },
{ "clash_mode": [ "Global" ], "server": "dns_proxy" },
{ "rule_set": [ "fakeip-filter" ], "server": "dns_direct" },
{ "query_type": [ "A", "AAAA" ], "server": "dns_fakeip" }
],
"final": "dns_proxy",
"strategy": "prefer_ipv4",
"optimistic": true,
"reverse_mapping": true,
// 推荐将 `client_subnet` 设置为当前宽带运营商分配的默认 DNS 的 IP 段
"client_subnet": "211.137.58.0/24"
}
}
```
- ② 按一下 Esc 键(退出键),输入英文冒号 `:`,继续输入 `wq` 并回车
### 3. DNS 模式为 `redirhost`
- ① 连接 SSH 后执行命令 `vi $CRASHDIR/jsons/dns.json`,按一下 Ins 键(Insert 键),修改为如下内容:
>推荐将 `client_subnet` 设置为当前宽带运营商分配的默认 DNS(可进入光猫或路由器拨号页面查看,或者前往[公共 DNS 大全](https://toolb.cn/publicdns)查询)的 IP 段,如默认 DNS 为 `211.137.58.20`,可设置为 `211.137.58.0/24`
{: .prompt-info }
```json
{
"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": "28.0.0.0/8", "inet6_range": "fc00::/16" }
],
"rules": [
{ "clash_mode": [ "Direct" ], "server": "dns_direct" },
{ "clash_mode": [ "Global" ], "server": "dns_proxy" },
{ "rule_set": [ "proxy" ], "server": "dns_proxy" },
{ "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
}
}
```
- ② 按一下 Esc 键(退出键),输入英文冒号 `:`,继续输入 `wq` 并回车
+586
View File
@@ -0,0 +1,586 @@
---
title: 生成带有自定义出站和规则的 sing-boxr 配置文件直链-ruleset 方案
description: 此教程搭载 sing-boxr 内核,采用 <code>rule_set</code> 规则搭配 .srs 规则集文件
date: 2024-08-22 17:44:59 +0800
categories: [直链配置, sing-boxr 直链]
tags: [sing-box, sing-boxr, 直链, 订阅, ruleset, rule_set, 基础]
---
> 说明
{: .prompt-tip }
1. 本教程可以生成扩展名为 .json 配置文件直链,可以**一键导入使用了 [sing-box reF1nd 版内核](https://github.com/reF1nd/sing-box)的客户端**
如:[ShellCrash](https://github.com/juewuy/ShellCrash) 和 [sing-boxr for Android](https://github.com/DustinWin/proxy-tools/releases/tag/sing-box) 等
2. 生成的订阅链接地址不会改变,支持更新订阅,**支持国内访问,支持同步机场节点**
3. 生成的订阅链接**自带规则集**,规则集来源 [DustinWin/ruleset_geodata/ruleset](https://github.com/DustinWin/ruleset_geodata#%E4%BA%8C-ruleset-%E8%A7%84%E5%88%99%E9%9B%86%E6%96%87%E4%BB%B6%E8%AF%B4%E6%98%8E)
4. 本教程必须使用支持[提供者](https://sing-boxr.dustinwin.us.kg/zh/configuration/provider/) `outbound_providers`(类似于 [mihomo 内核](https://github.com/MetaCubeX/mihomo)的[代理集合](https://wiki.metacubex.one/config/proxy-providers/) `proxy-providers`)的 [sing-box reF1nd 版内核](https://github.com/reF1nd/sing-box),请先**确定自己机场的订阅链接是否为 Clash 或 sing-box 订阅链接**,若不是,需前往[肥羊在线订阅转换工具](https://suburl.v1.mk)进行转换,“生成类型”选择“Clash”或“sing-box”,其它参数保持默认即可,转换后的 Clash 订阅链接需要在末尾添加 `&flag=clash`,然后添加到 .json 文件出站提供者 `providers``url`
5. 推荐使用 [Visual Studio Code](https://code.visualstudio.com/Download) 等专业编辑器来修改配置文件
6. ShellCrash 支持本地导入配置文件,可以直接将下方的 .json 直链文件内容复制到 `$CRASHDIR/jsons/config.json`{: .filepath} 文件中,可代替通过 ShellCrash 配置脚本 → 6) 配置文件管理 → a) 添加提供者
## 一、 准备编辑 .json 直链文件
### 1. 注册 [Gist](https://gist.github.com)
进入 <https://gist.github.com> 网站并注册
### 2. 打开编辑页面
登录并打开 Gist 可以直接编辑文件,或者点击页面右上角头像左边的“+”图标新建文件
### 3. 输入描述和完整文件名
“Gist description...”输入描述,随意填写;“Filename including extension...”输入完整文件名**包括扩展名**,如 singboxlink.json
<img src="/assets/img/link/file-extension-json.png" alt="输入描述和完整文件名" width="60%" />
## 二、 添加模板
### 1. 白名单模式(没有命中规则的网络流量统统使用代理,适用于服务器线路网络质量稳定、快速,不缺服务器流量的用户,推荐)
```json
{
// 出站提供者(获取机场订阅链接内的所有节点)
"providers": [
{
"tag": "🛫 机场订阅 1",
"type": "remote",
// 机场订阅链接,使用 Clash 链接
"url": "https://example.com/xxx/xxx&flag=clash",
"path": "./providers/airport1.yaml",
// 若出现获取不了机场节点的情况,可删除此配置项
"user_agent": "clash.meta",
// 初步筛选需要的节点,可有效减轻路由器压力,支持正则表达式,若不筛选可删除此配置项
"include": "(?i)(🇭🇰|港|hk|hongkong|hong kong|🇹🇼|台|tw|taiwan|tai wan|🇯🇵|日|jp|japan|🇸🇬|新|sg|singapore|🇺🇸|美|us|unitedstates|united states)",
// 初步排除不需要的节点,支持正则表达式,若不排除可删除此配置项
"exclude": "高倍|直连|×10",
"health_check": {
"enabled": true,
"url": "https://www.gstatic.com/generate_204"
}
},
{
"tag": "🛫 机场订阅 2",
"type": "remote",
// 机场订阅链接,使用 sing-box 链接
"url": "https://example.com/xxx/xxx",
"path": "./providers/airport2.json",
"update_interval": "12h",
// 若出现获取不了机场节点的情况,可添加此配置项
"user_agent": "sing-box/1.12.12",
"include": [ "(?i)(🇭🇰|港|hk|hongkong|hong kong|🇹🇼|台|tw|taiwan|tai wan|🇯🇵|日|jp|japan|🇸🇬|新|sg|singapore|🇺🇸|美|us|unitedstates|united states)" ],
"exclude": "高倍|直连|×10",
"health_check": {
"enabled": true,
"url": "https://www.gstatic.com/generate_204"
}
}
],
// 出站
"outbounds": [
// 手动选择国家或地区节点;根据“国家或地区出站”的名称对 `outbounds` 值进行增删改,须一一对应
{ "tag": "🚀 节点选择", "type": "selector", "outbounds": [ "♻️ 自动选择", "👉 手动选择", "🇭🇰 香港节点", "🇹🇼 台湾节点", "🇯🇵 日本节点", "🇸🇬 新加坡节点", "🇺🇸 美国节点", "🆓 免费节点" ] },
// 选择`🎯 全球直连`为测试本地网络(运营商网络速度和 IPv6 支持情况),可选择其它节点用于测试机场节点速度和 IPv6 支持情况
{ "tag": "📈 网络测试", "type": "selector", "outbounds": [ "🎯 全球直连", "🚀 节点选择", "🇭🇰 香港节点", "🇹🇼 台湾节点", "🇯🇵 日本节点", "🇸🇬 新加坡节点", "🇺🇸 美国节点", "🆓 免费节点" ] },
{ "tag": "🕹️ 游戏平台", "type": "selector", "outbounds": [ "🚀 节点选择", "🇭🇰 香港节点", "🇹🇼 台湾节点", "🇯🇵 日本节点", "🇸🇬 新加坡节点", "🇺🇸 美国节点" ] },
{ "tag": "🤖 AI 平台", "type": "selector", "outbounds": [ "🚀 节点选择", "🇭🇰 香港节点", "🇹🇼 台湾节点", "🇯🇵 日本节点", "🇸🇬 新加坡节点", "🇺🇸 美国节点" ] },
{ "tag": "🎮 游戏服务", "type": "selector", "outbounds": [ "🎯 全球直连", "🚀 节点选择" ] },
{ "tag": "🪟 微软服务", "type": "selector", "outbounds": [ "🎯 全球直连", "🚀 节点选择" ] },
{ "tag": "🇬 谷歌服务", "type": "selector", "outbounds": [ "🎯 全球直连", "🚀 节点选择" ] },
{ "tag": "🍎 苹果服务", "type": "selector", "outbounds": [ "🎯 全球直连", "🚀 节点选择" ] },
{ "tag": "🌍 国外媒体", "type": "selector", "outbounds": [ "🚀 节点选择", "🇭🇰 香港节点", "🇹🇼 台湾节点", "🇯🇵 日本节点", "🇸🇬 新加坡节点", "🇺🇸 美国节点" ] },
{ "tag": "🇨🇳 国内域名", "type": "selector", "outbounds": [ "🎯 全球直连", "🚀 节点选择" ] },
{ "tag": "🀄️ 国内 IP", "type": "selector", "outbounds": [ "🎯 全球直连", "🚀 节点选择" ] },
{ "tag": "🌎 国外域名", "type": "selector", "outbounds": [ "🚀 节点选择", "🇭🇰 香港节点", "🇹🇼 台湾节点", "🇯🇵 日本节点", "🇸🇬 新加坡节点", "🇺🇸 美国节点", "🆓 免费节点" ] },
{ "tag": "📲 电报消息", "type": "selector", "outbounds": [ "🚀 节点选择", "🇭🇰 香港节点", "🇹🇼 台湾节点", "🇯🇵 日本节点", "🇸🇬 新加坡节点", "🇺🇸 美国节点", "🆓 免费节点" ] },
{ "tag": "🐟 漏网之鱼", "type": "selector", "outbounds": [ "🚀 节点选择", "🇭🇰 香港节点", "🇹🇼 台湾节点", "🇯🇵 日本节点", "🇸🇬 新加坡节点", "🇺🇸 美国节点", "🆓 免费节点", "🎯 全球直连" ] },
{ "tag": "🛑 广告域名", "type": "selector", "outbounds": [ "🔴 全球拦截", "🎯 全球直连" ] },
{ "tag": "🔴 全球拦截", "type": "block" },
{ "tag": "🎯 全球直连", "type": "selector", "outbounds": [ "DIRECT" ] },
{ "tag": "DIRECT", "type": "direct" },
{ "tag": "GLOBAL", "type": "selector", "outbounds": [ "🚀 节点选择", "DIRECT" ] },
// 单个出站节点(以 vless 为例)
{
"tag": "🆓 免费节点",
"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" } }
},
// -------------------- 国家或地区出站 --------------------
// 自动选择节点,即按照 url 测试结果使用延迟最低的节点;测试后默认容差大于 50ms 才会切换到延迟低的那个节点;筛选出“香港”节点,支持正则表达式
{ "tag": "🇭🇰 香港节点", "type": "urltest", "providers": [ "🛫 机场订阅 1", "🛫 机场订阅 2" ], "include": "(?i)(🇭🇰|港|hk|hongkong|hong kong)" },
// 节点自动回退,默认选择第一个节点,节点超时后则会按代理顺序选择下一个可用节点,以此类推。也被叫做“故障转移”
{ "tag": "🇹🇼 台湾节点", "type": "urltest", "use_all_providers": true, "include": "(?i)(🇹🇼|台|tw|taiwan|tai wan)", "fallback": { "enabled": true } },
// 节点负载均衡,即将请求均匀分配到多个节点上,优点是更稳定,速度可能有提升;将相同的目标地址请求分配给该出站内的同一个节点;推荐在节点复用比较多的情况下使用
{ "tag": "🇯🇵 日本节点", "type": "loadbalance", "strategy": "consistent-hashing", "providers": [ "🛫 机场订阅 1", "🛫 机场订阅 2" ], "include": "(?i)(🇯🇵|日|jp|japan)" },
// 可使用 `"use_all_providers": true` 代替 `"providers": [ "🛫 机场订阅 1", "🛫 机场订阅 2", ... ]`,意思为引入所有出站提供者
{ "tag": "🇸🇬 新加坡节点", "type": "urltest", "use_all_providers": true, "include": "(?i)(🇸🇬|新|sg|singapore)" },
{ "tag": "🇺🇸 美国节点", "type": "urltest", "tolerance": 100, "providers": [ "🛫 机场订阅 1", "🛫 机场订阅 2" ], "include": "(?i)(🇺🇸|美|us|unitedstates|united states)" },
{ "tag": "♻️ 自动选择", "type": "urltest", "tolerance": 100, "use_all_providers": true },
{ "tag": "👉 手动选择", "type": "selector", "use_all_providers": true }
],
// 路由
"route": {
// 规则
"rules": [
// 若使用 ShellCrash,可进入 7 → 4 启用域名嗅探后删除此条 `action`
{ "action": "sniff" },
// 若使用 ShellCrash,可进入 7 → 4 启用域名嗅探后删除此条 `action`
{ "protocol": [ "dns" ], "action": "hijack-dns" },
// 若使用 ShellCrash,会自动覆写此条,可删除此条 `clash_mode`
{ "clash_mode": [ "Direct" ], "outbound": "DIRECT" },
// 若使用 ShellCrash,会自动覆写此条,可删除此条 `clash_mode`
{ "clash_mode": [ "Global" ], "outbound": "GLOBAL" },
// 自定义规则优先放前面
{ "rule_set": [ "private" ], "outbound": "🎯 全球直连" },
{ "rule_set": [ "ads" ], "outbound": "🛑 广告域名" },
// 为了使 P2P 流量(BT 下载)走直连,可添加一条 `DST-PORT` 规则(ShellCrash 会默认启用“只代理常用端口”,可删除此条 `DST-PORT`
{ "port_range": [ "6881:6889" ], "outbound": "🎯 全球直连"},
// 若使用 ShellCrash,由于无法判断本机进程(默认删除 `process_name` 规则),需删除此条 `rule_set`
{ "rule_set": [ "applications" ], "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": [ "media" ], "outbound": "🌍 国外媒体" },
{ "rule_set": [ "ai" ], "outbound": "🤖 AI 平台" },
{ "rule_set": [ "networktest" ], "outbound": "📈 网络测试" },
{ "rule_set": [ "proxy" ], "outbound": "🌎 国外域名" },
{ "rule_set": [ "cn" ], "outbound": "🇨🇳 国内域名" },
{ "rule_set": [ "privateip" ], "outbound": "🎯 全球直连" },
{ "rule_set": [ "telegramip" ], "outbound": "📲 电报消息" },
// 将目标域名解析成 IP 后与下方的 IP 规则进行匹配,提高兼容性
{ "action": "resolve", "match_only": true },
{ "rule_set": [ "cnip" ], "outbound": "🀄️ 国内 IP" },
{ "rule_set": [ "mediaip" ], "outbound": "🌍 国外媒体" }
],
// 规则集(binary 文件每天自动更新)
"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"
},
// 若使用 ShellCrash,由于无法判断本机进程(默认删除 `process_name` 规则),需删除此条 `applications`
{
"tag": "applications",
"type": "remote",
"format": "binary",
"path": "./ruleset/applications.srs",
"url": "https://github.com/DustinWin/ruleset_geodata/releases/download/sing-box-ruleset/applications.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": "media",
"type": "remote",
"format": "binary",
"path": "./ruleset/media.srs",
"url": "https://github.com/DustinWin/ruleset_geodata/releases/download/sing-box-ruleset/media.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": "privateip",
"type": "remote",
"format": "binary",
"path": "./ruleset/privateip.srs",
"url": "https://github.com/DustinWin/ruleset_geodata/releases/download/sing-box-ruleset/privateip.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"
},
{
"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": "mediaip",
"type": "remote",
"format": "binary",
"path": "./ruleset/mediaip.srs",
"url": "https://github.com/DustinWin/ruleset_geodata/releases/download/sing-box-ruleset/mediaip.srs"
}
],
// 默认出站,即没有命中规则的域名或 IP 走该规则
"final": "🐟 漏网之鱼",
"auto_detect_interface": true
}
}
```
将模板内容复制到自己 Gist 新建的 .json 文件中
### 2. 黑名单模式(只有命中规则的网络流量才使用代理,适用于服务器线路网络质量不稳定或不够快,或服务器流量紧缺的用户。通常也是软路由用户、家庭网关用户的常用模式)
```json
{
// 出站提供者(获取机场订阅链接内的所有节点)
"providers": [
{
"tag": "🛫 机场订阅 1",
"type": "remote",
// 机场订阅链接,使用 Clash 链接
"url": "https://example.com/xxx/xxx&flag=clash",
"path": "./providers/airport1.yaml",
// 若出现获取不了机场节点的情况,可删除此配置项
"user_agent": "clash.meta",
"download_detour": "GLOBAL",
// 初步筛选需要的节点,可有效减轻路由器压力,支持正则表达式,若不筛选可删除此配置项
"include": "(?i)(🇭🇰|港|hk|hongkong|hong kong|🇹🇼|台|tw|taiwan|tai wan|🇯🇵|日|jp|japan|🇸🇬|新|sg|singapore|🇺🇸|美|us|unitedstates|united states)",
// 初步排除不需要的节点,支持正则表达式,若不排除可删除此配置项
"exclude": "高倍|直连|×10",
"health_check": {
"enabled": true,
"url": "https://www.gstatic.com/generate_204"
}
},
{
"tag": "🛫 机场订阅 2",
"type": "remote",
// 机场订阅链接,使用 sing-box 链接
"url": "https://example.com/xxx/xxx",
"path": "./providers/airport2.json",
"update_interval": "12h",
// 若出现获取不了机场节点的情况,可添加此配置项
"user_agent": "sing-box/1.12.12",
"download_detour": "GLOBAL",
"include": "(?i)(🇭🇰|港|hk|hongkong|hong kong|🇹🇼|台|tw|taiwan|tai wan|🇯🇵|日|jp|japan|🇸🇬|新|sg|singapore|🇺🇸|美|us|unitedstates|united states)",
"exclude": "高倍|直连|×10",
"health_check": {
"enabled": true,
"url": "https://www.gstatic.com/generate_204"
}
}
],
// 出站
"outbounds": [
// 手动选择国家或地区节点;根据“国家或地区出站”的名称对 `outbounds` 值进行增删改,须一一对应
{ "tag": "🚀 节点选择", "type": "selector", "outbounds": [ "♻️ 自动选择", "👉 手动选择", "🇭🇰 香港节点", "🇹🇼 台湾节点", "🇯🇵 日本节点", "🇸🇬 新加坡节点", "🇺🇸 美国节点", "🆓 免费节点" ] },
// 选择`🎯 全球直连`为测试本地网络(运营商网络速度和 IPv6 支持情况),可选择其它节点用于测试机场节点速度和 IPv6 支持情况
{ "tag": "📈 网络测试", "type": "selector", "outbounds": [ "🎯 全球直连", "🚀 节点选择", "🇭🇰 香港节点", "🇹🇼 台湾节点", "🇯🇵 日本节点", "🇸🇬 新加坡节点", "🇺🇸 美国节点", "🆓 免费节点" ] },
{ "tag": "🕹️ 游戏平台", "type": "selector", "outbounds": [ "🚀 节点选择", "🇭🇰 香港节点", "🇹🇼 台湾节点", "🇯🇵 日本节点", "🇸🇬 新加坡节点", "🇺🇸 美国节点" ] },
{ "tag": "🤖 AI 平台", "type": "selector", "outbounds": [ "🚀 节点选择", "🇭🇰 香港节点", "🇹🇼 台湾节点", "🇯🇵 日本节点", "🇸🇬 新加坡节点", "🇺🇸 美国节点" ] },
{ "tag": "🌍 国外媒体", "type": "selector", "outbounds": [ "🚀 节点选择", "🇭🇰 香港节点", "🇹🇼 台湾节点", "🇯🇵 日本节点", "🇸🇬 新加坡节点", "🇺🇸 美国节点" ] },
{ "tag": "🌎 国外域名", "type": "selector", "outbounds": [ "🚀 节点选择", "🇭🇰 香港节点", "🇹🇼 台湾节点", "🇯🇵 日本节点", "🇸🇬 新加坡节点", "🇺🇸 美国节点", "🆓 免费节点" ] },
{ "tag": "📲 电报消息", "type": "selector", "outbounds": [ "🚀 节点选择", "🇭🇰 香港节点", "🇹🇼 台湾节点", "🇯🇵 日本节点", "🇸🇬 新加坡节点", "🇺🇸 美国节点", "🆓 免费节点" ] },
{ "tag": "🐟 漏网之鱼", "type": "selector", "outbounds": [ "🎯 全球直连", "🚀 节点选择", "🇭🇰 香港节点", "🇹🇼 台湾节点", "🇯🇵 日本节点", "🇸🇬 新加坡节点", "🇺🇸 美国节点", "🆓 免费节点" ] },
{ "tag": "🛑 广告域名", "type": "selector", "outbounds": [ "🔴 全球拦截", "🎯 全球直连" ] },
{ "tag": "🔴 全球拦截", "type": "block" },
{ "tag": "🎯 全球直连", "type": "selector", "outbounds": [ "DIRECT" ] },
{ "tag": "DIRECT", "type": "direct" },
{ "tag": "GLOBAL", "type": "selector", "outbounds": [ "🚀 节点选择", "DIRECT" ] },
// 单个出站节点(以 vless 为例)
{
"tag": "🆓 免费节点",
"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" } }
},
// -------------------- 国家或地区出站 --------------------
// 自动选择节点,即按照 url 测试结果使用延迟最低的节点;测试后容差大于 50ms 才会切换到延迟低的那个节点;筛选出“香港”节点,支持正则表达式
{ "tag": "🇭🇰 香港节点", "type": "urltest", "providers": [ "🛫 机场订阅 1", "🛫 机场订阅 2" ], "include": "(?i)(🇭🇰|港|hk|hongkong|hong kong)" },
// 节点自动回退,默认选择第一个节点,节点超时后则会按代理顺序选择下一个可用节点,以此类推。也被叫做“故障转移”
{ "tag": "🇹🇼 台湾节点", "type": "urltest", "use_all_providers": true, "include": "(?i)(🇹🇼|台|tw|taiwan|tai wan)", "fallback": { "enabled": true } },
// 节点负载均衡,即将请求均匀分配到多个节点上,优点是更稳定,速度可能有提升;将相同的目标地址请求分配给该出站内的同一个节点;推荐在节点复用比较多的情况下使用
{ "tag": "🇯🇵 日本节点", "type": "loadbalance", "strategy": "consistent-hashing", "providers": [ "🛫 机场订阅 1", "🛫 机场订阅 2" ], "include": "(?i)(🇯🇵|日|jp|japan)" },
// 可使用 `"use_all_providers": true` 代替 `"providers": [ "🛫 机场订阅 1", "🛫 机场订阅 2", ... ]`,意思为引入所有出站提供者
{ "tag": "🇸🇬 新加坡节点", "type": "urltest", "use_all_providers": true, "include": "(?i)(🇸🇬|新|sg|singapore)" },
{ "tag": "🇺🇸 美国节点", "type": "urltest", "tolerance": 100, "providers": [ "🛫 机场订阅 1", "🛫 机场订阅 2" ], "include": "(?i)(🇺🇸|美|us|unitedstates|united states)" },
{ "tag": "♻️ 自动选择", "type": "urltest", "tolerance": 100, "use_all_providers": true },
{ "tag": "👉 手动选择", "type": "selector", "use_all_providers": true }
],
// 路由
"route": {
// 域名解析器,必须在 `dns.servers` 配置有 `dns_direct`
"default_domain_resolver": "dns_direct",
// 规则
"rules": [
// 若使用 ShellCrash,可进入 7 → 4 启用域名嗅探后删除此条 `action`
{ "action": "sniff" },
// 若使用 ShellCrash,可进入 7 → 4 启用域名嗅探后删除此条 `action`
{ "protocol": [ "dns" ], "action": "hijack-dns" },
// 若使用 ShellCrash,会自动覆写此条,可删除此条 `clash_mode`
{ "clash_mode": [ "Direct" ], "outbound": "DIRECT" },
// 若使用 ShellCrash,会自动覆写此条,可删除此条 `clash_mode`
{ "clash_mode": [ "Global" ], "outbound": "GLOBAL" },
// 自定义规则优先放前面
{ "rule_set": [ "private" ], "outbound": "🎯 全球直连" },
{ "rule_set": [ "ads" ], "outbound": "🛑 广告域名" },
{ "rule_set": [ "games" ], "outbound": "🕹️ 游戏平台" },
{ "rule_set": [ "media" ], "outbound": "🌍 国外媒体" },
{ "rule_set": [ "ai" ], "outbound": "🤖 AI 平台" },
{ "rule_set": [ "networktest" ], "outbound": "📈 网络测试" },
{ "rule_set": [ "tld-proxy" ], "outbound": "🌎 国外域名" },
{ "rule_set": [ "gfw" ], "outbound": "🌎 国外域名" },
{ "rule_set": [ "telegramip" ], "outbound": "📲 电报消息" },
// 将目标域名解析成 IP 后与下方的 IP 规则进行匹配,提高兼容性
{ "action": "resolve", "match_only": true },
{ "rule_set": [ "mediaip" ], "outbound": "🌍 国外媒体" }
],
// 规则集(binary 文件每天自动更新)
"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",
"download_detour": "GLOBAL"
},
{
"tag": "private",
"type": "remote",
"format": "binary",
"path": "./ruleset/private.srs",
"url": "https://github.com/DustinWin/ruleset_geodata/releases/download/sing-box-ruleset/private.srs",
"download_detour": "GLOBAL"
},
{
"tag": "games",
"type": "remote",
"format": "binary",
"path": "./ruleset/games.srs",
"url": "https://github.com/DustinWin/ruleset_geodata/releases/download/sing-box-ruleset/games.srs",
"download_detour": "GLOBAL"
},
{
"tag": "media",
"type": "remote",
"format": "binary",
"path": "./ruleset/media.srs",
"url": "https://github.com/DustinWin/ruleset_geodata/releases/download/sing-box-ruleset/media.srs",
"download_detour": "GLOBAL"
},
{
"tag": "ai",
"type": "remote",
"format": "binary",
"path": "./ruleset/ai.srs",
"url": "https://github.com/DustinWin/ruleset_geodata/releases/download/sing-box-ruleset/ai.srs",
"download_detour": "GLOBAL"
},
{
"tag": "networktest",
"type": "remote",
"format": "binary",
"path": "./ruleset/networktest.srs",
"url": "https://github.com/DustinWin/ruleset_geodata/releases/download/sing-box-ruleset/networktest.srs",
"download_detour": "GLOBAL"
},
{
"tag": "tld-proxy",
"type": "remote",
"format": "binary",
"path": "./ruleset/tld-proxy.srs",
"url": "https://github.com/DustinWin/ruleset_geodata/releases/download/sing-box-ruleset/tld-proxy.srs",
"download_detour": "GLOBAL"
},
{
"tag": "gfw",
"type": "remote",
"format": "binary",
"path": "./ruleset/gfw.srs",
"url": "https://github.com/DustinWin/ruleset_geodata/releases/download/sing-box-ruleset/gfw.srs",
"download_detour": "GLOBAL"
},
{
"tag": "telegramip",
"type": "remote",
"format": "binary",
"path": "./ruleset/telegramip.srs",
"url": "https://github.com/DustinWin/ruleset_geodata/releases/download/sing-box-ruleset/telegramip.srs",
"download_detour": "GLOBAL"
},
{
"tag": "mediaip",
"type": "remote",
"format": "binary",
"path": "./ruleset/mediaip.srs",
"url": "https://github.com/DustinWin/ruleset_geodata/releases/download/sing-box-ruleset/mediaip.srs",
"download_detour": "GLOBAL"
}
],
// 默认出站,即没有命中规则的域名或 IP 走该规则
"final": "🐟 漏网之鱼",
"auto_detect_interface": true
}
}
```
将模板内容复制到自己 Gist 新建的 .json 文件中
## 三、 修改模板
1. 将提供者 `providers` 中的 `url` 链接改成自己机场的订阅链接(必须为 Clash 或 sing-box 订阅链接,详见《说明 4》)
2. 确定自己机场中有哪些国家或地区的节点,然后对 `outbounds` 里的国家或地区进行增删改
- 注:两者中的国家或地区必须一一对应,新增就全部新增,删除就全部删除,修改就全部修改(重要)
3. 在“国家或地区出站”中的 `include` 支持[正则表达式](https://www.lddgo.net/string/golangregex),可以精确地筛选出指定的国家或地区节点
例如:我想筛选出“香港 IPLC”节点,`include` 可以这样写:`"include": "香港.*IPLC|IPLC.*香港"`
- 小窍门:使用 [ChatGPT](https://chatgpt.com) 等 AI 工具查询符合自己要求的正则表达式
4.`🚀 节点选择` 出站下的 `outbounds` 里,可以将最稳定的节点放在最前面,配置完成后会自动选择最稳定的节点
5. 在“国家或地区出站”里,`type``urltest` 就是自动选择延迟最低的节点,将 `urltest` 改成 `selector` 就是手动选择节点
举个例子:我的机场包含有 2 个节点,分别是新加坡节点和日本节点,我想让 [Netflix](https://www.netflix.com) 自动选择延迟最低的新加坡节点,[哔哩哔哩](https://www.bilibili.com)可以手动选择日本任一节点,这个需求怎么写?
注:
- ① 以下只是节选,请酌情套用
- ② 本教程搭配的规则集合文件包含有 `netflix``netflixip``bilibili`
```json
{
// 出站
"outbounds": [
// 默认选择新加坡节点
{ "tag": "🎥 奈飞视频", "type": "selector", "outbounds": [ "🇸🇬 新加坡节点" ] },
// 默认选择日本节点,也可切换到直连
{ "tag": "📺 哔哩哔哩", "type": "selector", "outbounds": [ "🇯🇵 日本节点", "🎯 全球直连" ] },
// 自动选择延迟最低的新加坡节点;容差大于 50ms 才会切换到延迟低的那个节点
{ "tag": "🇸🇬 新加坡节点", "type": "urltest", "use_all_providers": true, "include": "(?i)(🇸🇬|新|sg|singapore)" },
// 手动选择日本任一节点
{ "tag": "🇯🇵 日本节点", "type": "selector", "use_all_providers": true, "include": "(?i)(🇯🇵|日|jp|japan)" },
{ "tag": "🎯 全球直连", "type": "selector", "outbounds": [ "DIRECT" ] },
{ "tag": "DIRECT", "type": "direct" }
],
// 路由
"route": {
// 域名解析器,必须在 `dns.servers` 配置有 `dns_direct`
"default_domain_resolver": "dns_direct",
// 规则
"rules": [
// 自定义规则优先放前面
{ "rule_set": [ "bilibili" ], "outbound": "📺 哔哩哔哩" },
{ "rule_set": [ "netflix" ], "outbound": "🎥 奈飞视频" },
// 将目标域名解析成 IP 后与下方的 IP 规则进行匹配,提高兼容性
{ "action": "resolve", "match_only": true },
{ "rule_set": [ "netflixip" ], "outbound": "🎥 奈飞视频" }
],
// 规则集(binary 文件每天自动更新)
"rule_set": [
{
"tag": "bilibili",
"type": "remote",
"format": "binary",
"path": "./ruleset/bilibili.srs",
"url": "https://github.com/DustinWin/ruleset_geodata/releases/download/sing-box-ruleset/bilibili.srs"
},
{
"tag": "netflix",
"type": "remote",
"format": "binary",
"path": "./ruleset/netflix.srs",
"url": "https://github.com/DustinWin/ruleset_geodata/releases/download/sing-box-ruleset/netflix.srs"
},
{
"tag": "netflixip",
"type": "remote",
"format": "binary",
"path": "./ruleset/netflixip.srs",
"url": "https://github.com/DustinWin/ruleset_geodata/releases/download/sing-box-ruleset/netflixip.srs"
}
]
}
}
```
> 若有其它需求,可进入 [MetaCubeX/meta-rules-dat/sing](https://github.com/MetaCubeX/meta-rules-dat/tree/sing) 搜索关键字,通过能够搜索到的关键字来编写出站和规则(推荐使用“*.srs”文件,`route.rule_set` 内须配置 `"format": "binary"`
{: .prompt-tip }
## 四、 生成 .json 文件链接
1. 编辑完成后,点击右下角的“Create secret gist”按钮,然后点击右上角的“Raw”按钮
<img src="/assets/img/link/click-raw-json.png" alt="生成 .json 文件链接 1" width="60%" />
2. 取出地址栏中的网址,删除后面的一串随机码,**完成后该 .json 文件直链才是最终生成的订阅链接**,该订阅链接地址不会改变,在不更改文件名的情况下即使编辑该 .json 文件并提交了 n 次也不会改变。举个例子,这是原地址:
`https://gist.githubusercontent.com/DustinWin/e712f40922381a8d74304d592d17b90b/raw/2797de01661e33689fc980c7b6537f3d43a7d0b6/singboxlink.json`
删除后面的一串随机码(当前编辑该文件生成的随机码“2797de01661e33689fc980c7b6537f3d43a7d0b6”)
<img src="/assets/img/link/d0b6-json.png" alt="生成 .json 文件链接 2" width="60%" />
删除后变成:
`https://gist.githubusercontent.com/DustinWin/e712f40922381a8d74304d592d17b90b/raw/singboxlink.json`
- 注:若无法直连访问,可在链接上添加 `https://ghfast.top/` 前缀,即:将链接改为 `https://ghfast.top/https://gist.githubusercontent.com/DustinWin/e712f40922381a8d74304d592d17b90b/raw/singboxlink.json`
## 五、 导入订阅链接(以 ShellCrash 导入订阅链接为例)
1. 进入 ShellCrash 配置脚本 → a) 添加提供者 → 1) 设置名称或代号,如输入“sing-boxr”;后进入 2) 设置链接或路径,粘贴最终生成的订阅链接,选择“a) 保存此提供者”
2. 进入 6) 配置文件管理 → 6) 配置文件管理 → c) 在线生成配置文件 → 6) 自定义浏览器 UA,选择“2) 不使用 UA”
3. 进入 6) 配置文件管理 → 1) sing-boxr,选择“e) 在线获取此配置文件”即可
4. 具体设置请参考《[ShellCrash 搭载 sing-boxr 内核的配置-ruleset 方案](https://proxy-tutorials.dustinwin.us.kg/posts/toolsettings-shellcrash-singboxr-ruleset)》
@@ -0,0 +1,442 @@
---
title: 分享 ShellCrash 搭载 sing-boxr 内核采用 ruleset 方案的一套配置
description: 此配置搭载 sing-boxr 内核,采用 <code>rule_set</code> 规则搭配 .srs 规则集文件
date: 2024-08-22 19:45:26 +0800
categories: [分享配置, Router]
tags: [sing-box, sing-boxr, ShellCrash, ruleset, rule_set, 分享, Router]
---
> 声明
{: .prompt-warning }
1. 请根据自身情况进行修改,**适合自己的方案才是最好的方案**,如无特殊需求,可以照搬
2. 此方案适用于 [ShellCrash](https://github.com/juewuy/ShellCrash)(以 ARM64 架构为例,且安装路径为 `/data/ShellCrash`{: .filepath}
3. 本方案绕过了 CNIP 且 IP 在国内的未知域名也会被绕过
4. 本方案不搭配 [AdGuard Home](https://github.com/AdguardTeam/AdGuardHome),在 DNS 层拦截广告
5. 本人将路由器设置了每天早上 6 点重启,使得《[](https://proxy-tutorials.dustinwin.us.kg/posts/share-shellcrash-singboxr-ruleset/#%E5%85%AD-%E6%B7%BB%E5%8A%A0%E5%AE%9A%E6%97%B6%E4%BB%BB%E5%8A%A1)》中设置的定时任务生效
6. 本教程搭载 [sing-box 内核 reF1nd-Testing 版](https://github.com/reF1nd/sing-box/tree/reF1nd-testing)
## 一、 生成配置文件 .json 文件直链
具体方法此处不再赘述,请看《[生成带有自定义出站和规则的 sing-boxr 配置文件直链-ruleset 方案](https://proxy-tutorials.dustinwin.us.kg/posts/link-singboxr-ruleset)》,贴一下我使用的配置:
```json
{
"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": "trackerslist",
"type": "remote",
"format": "binary",
"path": "./ruleset/trackerslist.srs",
"url": "https://github.com/DustinWin/ruleset_geodata/releases/download/sing-box-ruleset/trackerslist.srs"
},
{
"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](https://github.com/Zephyruso/zashboard) → 代理 → 设置 → 管理隐藏代理组,设置隐藏以简化 Dashboard 面板中的显示)。再将延迟测试最低的策略组配置 `"type": "loadbalance"` 进行负载均衡供用户选择使用
- ② 将不同的优选节点分别配置 `"fallback": { "enabled": true }` 进行故障转移(可进入 zashboard → 代理 → 设置 → 管理隐藏代理组,设置隐藏以简化 Dashboard 面板中的显示)。再将故障转移后的策略组配置 `"type": "urltest"` 进行延迟测试供用户选择使用
```json
{
"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 版内核](https://github.com/reF1nd/sing-box)和 [CN_IP 文件](https://github.com/DustinWin/geoip)
连接 SSH 后执行如下命令:
```shell
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 大全](https://toolb.cn/publicdns)查询)的 IP 段,如默认 DNS 为 `211.137.58.20`,可设置为 `211.137.58.0/24`
```json
{
"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": "28.0.0.0/8", "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": [ "trackerslist", "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" },
{ "match_response": true, "ip_accept_any": true, "invert": true, "action": "respond" },
{ "query_type": [ "A", "AAAA" ], "server": "dns_fakeip" }
],
"final": "dns_direct",
"strategy": "prefer_ipv4",
"optimistic": true,
"reverse_mapping": true
}
}
```
按一下 Esc 键(退出键),输入英文冒号 `:`,继续输入 `wq` 并回车
---
>`DNS` 私货
{: .prompt-tip }
注:
- ① 本 `dns` 配置中,国内域名走国内 DNS 解析,国外域名走 `fakeip`,未知域名也走 `fakeip`,在匹配 `rule_set:cnip` 规则时会先由国外 DNS 解析且配置 `client_subnet` 提高了兼容性,解析出 IP 在国内则走 `国内 IP` 规则,否则走 `漏网之鱼` 规则(有效解决了“心理 DNS 泄露问题”,详见《[搭载 sing-boxr 内核配置 DNS 不泄露教程-ruleset 方案](https://proxy-tutorials.dustinwin.us.kg/posts/dnsnoleaks-singboxr-ruleset/)》)
- ② 推荐将 `client_subnet` 设置为当前宽带运营商分配的默认 DNS(可进入光猫或路由器拨号页面查看,或者前往[公共 DNS 大全](https://toolb.cn/publicdns)查询)的 IP 段,如默认 DNS 为 `211.137.58.20`,可设置为 `211.137.58.0/24`
```json
{
"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": "28.0.0.0/8", "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": [ "trackerslist", "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" },
{ "match_response": true, "ip_accept_any": true, "invert": true, "action": "respond" },
{ "query_type": [ "A", "AAAA" ], "server": "dns_fakeip" }
],
"final": "dns_proxy",
"strategy": "prefer_ipv4",
"optimistic": true,
"reverse_mapping": true,
// 推荐将 `client_subnet` 设置为当前宽带运营商分配的默认 DNS 的 IP 段
"client_subnet": "211.137.58.0/24"
}
}
```
## 四、 编辑 services.json 文件
连接 SSH 后执行命令 `vi $CRASHDIR/jsons/services.json`,按一下 Ins 键(Insert 键),粘贴如下内容:
```json
{
"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 键),粘贴如下内容:
```json
{
"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 方案/添加定时任务](https://proxy-tutorials.dustinwin.us.kg/posts/toolsettings-shellcrash-singboxr-ruleset/#%E4%BA%8C-%E6%B7%BB%E5%8A%A0%E5%AE%9A%E6%97%B6%E4%BB%BB%E5%8A%A1)》
## 七、 设置部分
1. 设置可参考《[ShellCrash 搭载 sing-boxr 内核的配置-ruleset 方案/设置部分](https://proxy-tutorials.dustinwin.us.kg/posts/toolsettings-shellcrash-singboxr-ruleset/#%E4%B8%89-%E8%AE%BE%E7%BD%AE%E9%83%A8%E5%88%86)》,此处只列举配置的不同之处
2. 进入 ShellCrash 配置脚本 → 2) 功能设置 → 2) DNS 设置 → 9) 修改 DNS 服务器,设置如下:
<img src="/assets/img/dns/dns-null.png" alt="设置部分 2" width="60%" />
3. 进入 2) 功能设置 → 6) 自定义端口及密钥 → 5) 修改面板访问端口,修改为 `9090`
4. 连接 SSH 后执行如下命令:
```shell
sed -i 's/"ip_accept_any": true,/"preferred_by": [ "hosts" ],/' "$CRASHDIR/starts/singbox_modify.sh"
sed -i '/#生成experimental.json/i\
#生成http_clients.json\
cat >"$TMPDIR"/jsons/http_clients.json <<EOF\
{\
"http_clients": [\
{\
"tag": "detour_proxy",\
"detour": "GLOBAL"\
},\
{\
"tag": "detour_direct",\
"detour": "DIRECT"\
}\
]\
}\
EOF
' "$CRASHDIR/starts/singbox_modify.sh"
sed -i 's/log dns ntp certificate experimental/log dns ntp certificate http_clients experimental/' "$CRASHDIR/starts/singbox_modify.sh"
sed -i 's/log dns ntp certificate experimental/log dns ntp certificate http_clients experimental/' "$CRASHDIR/menus/override.sh"
```
## 八、 访问 Dashboard 面板
1. 打开 zashboard 在线面板地址 <http://board.zash.run.place> 后,可直接在“[Clash API](https://sing-boxr.dustinwin.us.kg/zh/configuration/experimental/clash-api/)”标签里将“主机”修改为 `192.168.31.1`,点击“提交”即可访问 Dashboard
2. 进入设置 → 后端设置,点击“+”图标,切换到“[sing-box API](https://sing-boxr.dustinwin.us.kg/zh/configuration/service/api/)”标签,将“主机”和“端口分别修改为 `192.168.31.1``9999` 并点击“提交”
3. 通过切换后端配置可以分别使用 Clash API(支持“代理提供商”和“规则提供商”的更新)和 sing-box API Dashboard 面板
> 推荐设置
{: .prompt-tip }
1. 进入 zashboard → 代理 → 代理设置 → 管理隐藏代理组,隐藏不必要显示的代理组
2. 进入 zashboard → 设置 → 代理设置 → 外观 → 自定义图标,设置“组名”和“URL”,“URL”可参考 [icon 文件](https://github.com/DustinWin/ruleset_geodata/releases/tag/icons)
3. 进入 zashboard → 设置 → 后端设置 → 修改后端配置,可设置“标签 (可选)”来快速识别不同设备
@@ -0,0 +1,478 @@
---
title: 分享 ShellCrash 搭载 sing-boxr 内核搭配 AdGuard Home 采用 ruleset 方案的一套配置
description: 此配置搭载 sing-boxr 内核,采用 <code>rule_set</code> 规则搭配 .srs 规则集文件
date: 2024-08-22 19:51:07 +0800
categories: [分享配置, Router]
tags: [sing-box, sing-boxr, ShellCrash, AdGuard Home, ruleset, rule_set, 分享, Router]
---
> 声明
{: .prompt-warning }
1. 此方案采用 [ShellCrash](https://github.com/juewuy/ShellCrash) 作为上游,[AdGuard Home](https://github.com/AdguardTeam/AdGuardHome) 作为下游的模式
2. 请根据自身情况进行修改,**适合自己的方案才是最好的方案**,如无特殊需求,可以照搬
3. 此方案中 ShellCrash 采用了**绕过 CN_IP** 的模式且 IP 在国内的未知域名也会被绕过(仍与 AdGuard Home 配合完美)
4. 此方案适用于 ShellCrash(以 ARM64 架构为例,且安装路径为 `/data/ShellCrash`{: .filepath}
5. 此方案适用于 AdGuard Home(以 ARM64 架构为例,且安装路径为 `/data/AdGuardHome`{: .filepath}
6. 此方案不建议启用 ShellCrash 配置脚本 → 2) 功能设置 → 3) 透明路由流量过滤 → 2) 过滤局域网设备,因不经过内核的设备在访问 `漏网之鱼` 域名时会遇到无法访问的情况
7. 本人将路由器设置了每天早上 6 点重启,使得《[](https://proxy-tutorials.dustinwin.us.kg/posts/share-shellcrashadguardhome-singboxr-ruleset/#%E5%85%AD-%E6%B7%BB%E5%8A%A0%E5%AE%9A%E6%97%B6%E4%BB%BB%E5%8A%A1)》中设置的定时任务生效
8. 本教程搭载 [sing-box 内核 reF1nd-Testing 版](https://github.com/reF1nd/sing-box/tree/reF1nd-testing)
## 一、 生成配置文件 .json 文件直链
具体方法此处不再赘述,请看《[生成带有自定义出站和规则的 sing-boxr 配置文件直链-ruleset 方案](https://proxy-tutorials.dustinwin.us.kg/posts/link-singboxr-ruleset)》,贴一下我使用的配置:
```json
{
"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": "fakeip-filter",
"type": "remote",
"format": "binary",
"path": "./ruleset/fakeip-filter.srs",
"url": "https://github.com/DustinWin/ruleset_geodata/releases/download/sing-box-ruleset/fakeip-filter-lite.srs"
},
{
"tag": "trackerslist",
"type": "remote",
"format": "binary",
"path": "./ruleset/trackerslist.srs",
"url": "https://github.com/DustinWin/ruleset_geodata/releases/download/sing-box-ruleset/trackerslist.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](https://github.com/Zephyruso/zashboard) → 代理 → 设置 → 管理隐藏代理组,设置隐藏以简化 Dashboard 面板中的显示)。再将延迟测试最低的策略组配置 `"type": "loadbalance"` 进行负载均衡供用户选择使用
- ② 将不同的优选节点分别配置 `"fallback": { "enabled": true }` 进行故障转移(可进入 zashboard → 代理 → 设置 → 管理隐藏代理组,设置隐藏以简化 Dashboard 面板中的显示)。再将故障转移后的策略组配置 `"type": "urltest"` 进行延迟测试供用户选择使用
```json
{
"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 版内核](https://github.com/reF1nd/sing-box)和 [CN_IP 文件](https://github.com/DustinWin/geoip)
连接 SSH 后执行如下命令:
```shell
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 大全](https://toolb.cn/publicdns)查询)的 IP 段,如默认 DNS 为 `211.137.58.20`,可设置为 `211.137.58.0/24`
- ② 由于 ShellCrash 采用的 DNS 模式为 `mix`**ShellCrash 传给 AdGuard Home 的国外域名对应 IP 为假 IP**,会导致 AdGuard Home 检查更新和下载更新 DNS 黑名单时失败
-`fakeip-filter` 中添加了 AdGuard Home 常用域名,包括:`adguardteam.github.io`AdGuard Home 自带 DNS 黑名单下载域名)、`adrules.top`(常用广告拦截下载域名)、`anti-ad.net`(常用广告拦截下载域名)和 `static.adtidy.org`AdGuard Home 检查更新域名)
- ④ 不推荐使用自带更新去更新,推荐《[](https://proxy-tutorials.dustinwin.us.kg/posts/share-shellcrashadguardhome-singboxr-ruleset/#%E4%BA%94-%E6%B7%BB%E5%8A%A0%E5%AE%9A%E6%97%B6%E4%BB%BB%E5%8A%A1)》中通过定时任务去自动更新(AdGuard Home 程序已被压缩,节省空间)
<img src="/assets/img/share/update-adguardhome.png" alt="编辑 dns.json 文件" width="60%" />
```json
{
"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": "28.0.0.0/8", "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": [ "fakeip-filter", "trackerslist", "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" },
{ "match_response": true, "ip_accept_any": true, "invert": true, "action": "respond" },
{ "query_type": [ "A", "AAAA" ], "server": "dns_fakeip" }
],
"final": "dns_direct",
"strategy": "prefer_ipv4",
"optimistic": true,
"reverse_mapping": true
}
}
```
---
>`DNS` 私货
{: .prompt-tip }
注:
- ① 本 `dns` 配置中,国内域名走国内 DNS 解析,国外域名走 `fakeip`,未知域名也走 `fakeip`,在匹配 `rule_set:cnip` 规则时会先由国外 DNS 解析且配置 `client_subnet` 提高了兼容性,解析出 IP 在国内则走 `国内 IP` 规则,否则走 `漏网之鱼` 规则(有效解决了“心理 DNS 泄露问题”,详见《[搭载 sing-boxr 内核配置 DNS 不泄露教程-ruleset 方案](https://proxy-tutorials.dustinwin.us.kg/posts/dnsnoleaks-singboxr-ruleset/)》)
- ② 推荐将 `client_subnet` 设置为当前宽带运营商分配的默认 DNS(可进入光猫或路由器拨号页面查看,或者前往[公共 DNS 大全](https://toolb.cn/publicdns)查询)的 IP 段,如默认 DNS 为 `211.137.58.20`,可设置为 `211.137.58.0/24`
```json
{
"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": "28.0.0.0/8", "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": [ "fakeip-filter", "trackerslist", "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" },
{ "match_response": true, "ip_accept_any": true, "invert": true, "action": "respond" },
{ "query_type": [ "A", "AAAA" ], "server": "dns_fakeip" }
],
"final": "dns_proxy",
"strategy": "prefer_ipv4",
"optimistic": true,
"reverse_mapping": true,
// 推荐将 `client_subnet` 设置为当前宽带运营商分配的默认 DNS 的 IP 段
"client_subnet": "211.137.58.0/24"
}
}
```
## 四、 编辑 services.json 文件
连接 SSH 后执行命令 `vi $CRASHDIR/jsons/services.json`,按一下 Ins 键(Insert 键),粘贴如下内容:
```json
{
"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 键),粘贴如下内容:
```json
{
"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
}
}
```
## 六、 添加定时任务
1. 连接 SSH 后执行命令 `vi $CRASHDIR/task/task.user`,按一下 Ins 键(Insert 键),粘贴如下内容:
```shell
201#curl -sS -o $CRASHDIR/cn_ip.txt -L https://ghfast.top/https://github.com/DustinWin/geoip/releases/download/ips/cn_ipv4.txt && curl -sS -o $CRASHDIR/cn_ipv6.txt -L https://ghfast.top/https://github.com/DustinWin/geoip/releases/download/ips/cn_ipv6.txt >/dev/null 2>&1#更新CN_IP文件
202#curl -sS -o /data/AdGuardHome/AdGuardHome -L https://ghfast.top/https://github.com/DustinWin/proxy-tools/releases/download/AdGuardHome/AdGuardHome_beta_linux_arm64 >/dev/null 2>&1#更新AdGuardHome
```
2. 按一下 Esc 键(退出键),输入英文冒号 `:`,继续输入 `wq` 并回车
3. 执行 `sc`,进入 ShellCrash 配置脚本 → 5) 自动任务 → 1) 添加自动任务,可以看到末尾就有添加的定时任务,输入对应的数字并回车后可设置执行条件
<img src="/assets/img/share/task-adguardhome.png" alt="添加定时任务" width="60%" />
## 七、 ShellCrash 设置
1. 设置可参考《[ShellCrash 搭载 sing-boxr 内核的配置-ruleset 方案/设置部分](https://proxy-tutorials.dustinwin.us.kg/posts/toolsettings-shellcrash-singboxr-ruleset/#%E4%B8%89-%E8%AE%BE%E7%BD%AE%E9%83%A8%E5%88%86)》,此处只列举配置的不同之处
2. 进入 ShellCrash 配置脚本 → 2) 功能设置 → 2) DNS 设置 → 7 DNS 劫持端口,设置为“5353”(须完成《[](https://proxy-tutorials.dustinwin.us.kg/posts/share-shellcrashadguardhome-singboxr-ruleset/#%E4%B8%83-%E5%AE%89%E8%A3%85-adguard-home)》后才可设置)
3. 进入 2) DNS 设置 → 9) 修改 DNS 服务器,设置如下:
<img src="/assets/img/dns/dns-null.png" alt="设置部分 2" width="60%" />
4. 进入 2) 功能设置 → 6) 自定义端口及密钥 → 5) 修改面板访问端口,修改为 `9090`
5. 连接 SSH 后执行如下命令:
```shell
sed -i 's/"ip_accept_any": true,/"preferred_by": [ "hosts" ],/' "$CRASHDIR/starts/singbox_modify.sh"
sed -i '/#生成experimental.json/i\
#生成http_clients.json\
cat >"$TMPDIR"/jsons/http_clients.json <<EOF\
{\
"http_clients": [\
{\
"tag": "detour_proxy",\
"detour": "GLOBAL"\
},\
{\
"tag": "detour_direct",\
"detour": "DIRECT"\
}\
]\
}\
EOF
' "$CRASHDIR/starts/singbox_modify.sh"
sed -i 's/log dns ntp certificate experimental/log dns ntp certificate http_clients experimental/' "$CRASHDIR/starts/singbox_modify.sh"
sed -i 's/log dns ntp certificate experimental/log dns ntp certificate http_clients experimental/' "$CRASHDIR/menus/override.sh"
```
## 八、 安装 AdGuard Home
连接 SSH 后执行如下命令:
```shell
mkdir -p /data/AdGuardHome
curl -sS -o /data/AdGuardHome/AdGuardHome -L https://ghfast.top/https://github.com/DustinWin/proxy-tools/releases/download/AdGuardHome/AdGuardHome_beta_linux_arm64
chmod +x /data/AdGuardHome/AdGuardHome
/data/AdGuardHome/AdGuardHome -s install
/data/AdGuardHome/AdGuardHome -s start
iptables -t nat -A PREROUTING -p tcp --dport 53 -j REDIRECT --to-ports 5353
iptables -t nat -A PREROUTING -p udp --dport 53 -j REDIRECT --to-ports 5353
ip6tables -t nat -A PREROUTING -p tcp --dport 53 -j REDIRECT --to-ports 5353
ip6tables -t nat -A PREROUTING -p udp --dport 53 -j REDIRECT --to-ports 5353
cat <<EOF >> /data/auto_ssh/auto_ssh.sh
sleep 10s
/data/AdGuardHome/AdGuardHome -s install
/data/AdGuardHome/AdGuardHome -s start
iptables -t nat -A PREROUTING -p tcp --dport 53 -j REDIRECT --to-ports 5353
iptables -t nat -A PREROUTING -p udp --dport 53 -j REDIRECT --to-ports 5353
ip6tables -t nat -A PREROUTING -p tcp --dport 53 -j REDIRECT --to-ports 5353
ip6tables -t nat -A PREROUTING -p udp --dport 53 -j REDIRECT --to-ports 5353
EOF
```
## 八、 AdGuard Home 设置
设置可参考《[全网最详细的解锁 SSH ShellCrash 搭载 sing-boxr 内核搭配 AdGuard Home 安装和配置教程/AdGuard Home 配置](https://proxy-tutorials.dustinwin.us.kg/posts/pin-shellcrashadguardhome-singboxr/#2-adguard-home-%E9%85%8D%E7%BD%AE)》
## 九、 访问 Dashboard 面板
1. 打开 zashboard 在线面板地址 <http://board.zash.run.place> 后,可直接在“[Clash API](https://sing-boxr.dustinwin.us.kg/zh/configuration/experimental/clash-api/)”标签里将“主机”修改为 `192.168.31.1`,点击“提交”即可访问 Dashboard
2. 进入设置 → 后端设置,点击“+”图标,切换到“[sing-box API](https://sing-boxr.dustinwin.us.kg/zh/configuration/service/api/)”标签,将“主机”和“端口分别修改为 `192.168.31.1``9999` 并点击“提交”
3. 通过切换后端配置可以分别使用 Clash API(支持“代理提供商”和“规则提供商”的更新)和 sing-box API Dashboard 面板
4. 打开 <http://miwifi.com:3000> 即可访问 AdGuard Home 面板
> 推荐设置
{: .prompt-tip }
1. 进入 zashboard → 代理 → 代理设置 → 管理隐藏代理组,隐藏不必要显示的代理组
2. 进入 zashboard → 设置 → 代理设置 → 外观 → 自定义图标,设置“组名”和“URL”,“URL”可参考 [icon 文件](https://github.com/DustinWin/ruleset_geodata/releases/tag/icons)
3. 进入 zashboard → 设置 → 后端设置 → 修改后端配置,可设置“标签 (可选)”来快速识别不同设备
@@ -0,0 +1,646 @@
---
title: 分享 sing-boxr for Windows 采用 ruleset 方案的一套配置
description: 此配置搭载 sing-boxr 内核,采用 <code>rule_set</code> 规则搭配 .srs 规则集文件
date: 2024-08-22 20:01:28 +0800
categories: [分享配置, Windows]
tags: [sing-box, sing-boxr, Windows, ruleset, rule_set, 分享]
---
> 声明
{: .prompt-warning }
1. 请根据自身情况进行修改,**适合自己的方案才是最好的方案**,如无特殊需求,可以照搬
2. 此方案采用**裸核**的方式运行,更加精简
3. 本教程搭载 [sing-box 内核 reF1nd-Testing 版](https://github.com/reF1nd/sing-box/tree/reF1nd-testing)
## 一、 生成配置文件 .json 文件直链
具体方法请参考《[生成带有自定义出站和规则的 sing-boxr 配置文件直链-ruleset 方案](https://proxy-tutorials.dustinwin.us.kg/posts/link-singboxr-ruleset)》,贴一下我使用的配置:
- 注:推荐将 `client_subnet` 设置为当前宽带运营商分配的默认 DNS(可进入光猫或路由器拨号页面查看,或者前往[公共 DNS 大全](https://toolb.cn/publicdns)查询)的 IP 段,如默认 DNS 为 `211.137.58.20`,可设置为 `211.137.58.0/24`
```json
{
"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"
}
}
],
"log": { "level": "error", "timestamp": true },
"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_local", "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": "28.0.0.0/8", "inet6_range": "fc00::/16" }
],
"rules": [
{ "preferred_by": [ "hosts" ], "server": "hosts" },
{ "clash_mode": [ "Direct" ], "server": "dns_direct" },
{ "clash_mode": [ "Global" ], "server": "dns_proxy" },
{ "rule_set": [ "private" ], "server": "dns_local" },
{ "rule_set": [ "ads" ], "action": "predefined" },
{ "rule_set": [ "trackerslist", "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" },
{ "query_type": [ "A", "AAAA" ], "server": "dns_fakeip" }
],
"final": "dns_direct",
"strategy": "prefer_ipv4",
"optimistic": true,
"reverse_mapping": true
},
"http_clients": [ { "tag": "detour_proxy", "detour": "GLOBAL" } ],
"inbounds": [
{ "tag": "tun-in", "type": "tun", "interface_name": "sing-box", "address": [ "172.18.0.1/30", "fdfe:dcba:9876::1/126" ], "auto_route": true, "strict_route": true }
],
"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": [ "全球直连", "节点选择" ] },
{ "tag": "国内 IP", "type": "selector", "outbounds": [ "全球直连", "节点选择" ] },
{ "tag": "国外域名", "type": "selector", "outbounds": [ "节点选择", "香港节点", "台湾节点", "日本节点", "新加坡节点", "美国节点", "免费节点", "🆚 vless 节点" ] },
{ "tag": "电报消息", "type": "selector", "outbounds": [ "节点选择", "香港节点", "台湾节点", "日本节点", "新加坡节点", "美国节点", "免费节点", "🆚 vless 节点" ] },
{ "tag": "直连软件", "type": "selector", "outbounds": [ "全球直连" ] },
{ "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": {
"default_domain_resolver": "dns_direct",
"rules": [
{ "rule_set": [ "telegramip" ], "invert": true, "action": "sniff" },
{ "type": "logical", "mode": "or", "rules": [ { "protocol": [ "dns" ] }, { "port": 53 } ], "action": "hijack-dns" },
{ "clash_mode": [ "Direct" ], "outbound": "DIRECT" },
{ "clash_mode": [ "Global" ], "outbound": "GLOBAL" },
{ "rule_set": [ "private" ], "outbound": "私有网络" },
{ "rule_set": [ "applications" ], "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": "国外域名" },
{ "rule_set": [ "cn" ], "outbound": "国内域名" },
{ "ip_is_private": true, "outbound": "私有网络" },
{ "rule_set": [ "telegramip" ], "outbound": "电报消息" },
{ "action": "resolve", "match_only": true },
{ "rule_set": [ "cnip" ], "outbound": "国内 IP" }
],
"rule_set": [
{
"tag": "trackerslist",
"type": "remote",
"format": "binary",
"path": "./ruleset/trackerslist.srs",
"url": "https://github.com/DustinWin/ruleset_geodata/releases/download/sing-box-ruleset/trackerslist.srs"
},
{
"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": "applications",
"type": "remote",
"format": "binary",
"path": "./ruleset/applications.srs",
"url": "https://github.com/DustinWin/ruleset_geodata/releases/download/sing-box-ruleset/applications.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": "telegramip",
"type": "remote",
"format": "binary",
"path": "./ruleset/telegramip.srs",
"url": "https://github.com/DustinWin/ruleset_geodata/releases/download/sing-box-ruleset/telegramip.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"
}
],
"final": "漏网之鱼",
"auto_detect_interface": true
},
"services": [
{
"type": "api",
"listen": "::",
"listen_port": 9999,
"secret": "",
"access_control_allow_private_network": true
}
],
"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
}
}
```
---
>`DNS` 私货
{: .prompt-tip }
注:
- ① 本 `dns` 配置中,国内域名走国内 DNS 解析,国外域名走 `fakeip`,未知域名也走 `fakeip`,在匹配 `rule_set:cnip` 规则时会先由国外 DNS 解析且配置 `client_subnet` 提高了兼容性,解析出 IP 在国内则走 `国内 IP` 规则,否则走 `漏网之鱼` 规则(有效解决了“心理 DNS 泄露问题”,详见《[搭载 sing-boxr 内核配置 DNS 不泄露教程-ruleset 方案](https://proxy-tutorials.dustinwin.us.kg/posts/dnsnoleaks-singboxr-ruleset/)》)
- ② 推荐将 `client_subnet` 设置为当前宽带运营商分配的默认 DNS(可进入光猫或路由器拨号页面查看,或者前往[公共 DNS 大全](https://toolb.cn/publicdns)查询)的 IP 段,如默认 DNS 为 `211.137.58.20`,可设置为 `211.137.58.0/24`
```json
{
"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_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": "28.0.0.0/8", "inet6_range": "fc00::/16" }
],
"rules": [
{ "preferred_by": [ "hosts" ], "server": "hosts" },
{ "clash_mode": [ "Direct" ], "server": "dns_direct" },
{ "clash_mode": [ "Global" ], "server": "dns_proxy" },
{ "rule_set": [ "private" ], "server": "dns_local" },
{ "rule_set": [ "ads" ], "action": "predefined" },
{ "rule_set": [ "trackerslist", "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" },
{ "query_type": [ "A", "AAAA" ], "server": "dns_fakeip" }
],
"final": "dns_proxy",
"strategy": "prefer_ipv4",
"optimistic": true,
"reverse_mapping": true,
// 推荐将 `client_subnet` 设置为当前宽带运营商分配的默认 DNS 的 IP 段
"client_subnet": "211.137.58.0/24"
}
}
```
---
>`outbounds` 私货
{: .prompt-tip }
注:
- ① 本 `outbounds` 配置中,将不同的节点类型(如:`Shadowsocks``Trojan`)分别配置 `"type": "urltest"` 进行延迟测试(可进入 [zashboard](https://github.com/Zephyruso/zashboard) → 代理 → 设置 → 管理隐藏代理组,设置隐藏以简化 Dashboard 面板中的显示)。再将延迟测试最低的策略组配置 `"type": "loadbalance"` 进行负载均衡供用户选择使用
- ② 将不同的优选节点分别配置 `"fallback": { "enabled": true }` 进行故障转移(可进入 zashboard → 代理 → 设置 → 管理隐藏代理组,设置隐藏以简化 Dashboard 面板中的显示)。再将故障转移后的策略组配置 `"type": "urltest"` 进行延迟测试供用户选择使用
```json
{
"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" } }
]
}
```
## 二、 添加以管理员身份运行 Bash 文件的支持
1. 下载安装 [Git for Windows](https://github.com/git-for-windows/git/releases),安装目录默认为 `C:\Program Files\Git`{: .filepath}
2. 编辑文本文档,粘贴如下内容:
```text
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\.sh]
@="sh_auto_file"
[HKEY_CLASSES_ROOT\sh_auto_file\shell\runas\command]
@="\"C:\\Program Files\\Git\\git-bash.exe\" \"%1\""
```
另存为 .reg 文件,双击导入
## 三、 导入 [sing-box reF1nd 版内核](https://github.com/reF1nd/sing-box)和配置文件并启动 sing-boxr
### 1. 导入内核和配置文件
- ① 编辑本文文档,粘贴如下内容:
注:
- ➊ 将《[](https://proxy-tutorials.dustinwin.us.kg/posts/share-windows-singboxr-ruleset/#%E4%B8%80-%E7%94%9F%E6%88%90%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6-json-%E6%96%87%E4%BB%B6%E7%9B%B4%E9%93%BE)》中生成的配置文件 .json 文件直链替换下面命令中的 `{.json 配置文件直链}`
- ➋ 或删除此条命令,直接进入 `%PROGRAMFILES%\sing-box`{: .filepath} 文件夹,新建 config.json 文件并粘贴配置内容
```shell
#!/bin/bash
title="安装、更新 sing-boxr 内核和配置文件"
while true; do
clear
echo "==============================================="
echo " 安装、更新 sing-boxr 内核和配置文件 "
echo "==============================================="
echo
echo "1. 安装(更新)sing-boxr 内核"
echo "2. 导入(更新)配置文件"
echo "3. 启动 sing-boxr 服务"
echo "4. 停止 sing-boxr 服务"
echo "0. 退出"
echo "==============================================="
read -p "请选择操作(0-4):" choice
case $choice in
1)
echo "安装(更新)sing-boxr 内核"
cd "$PROGRAMFILES"
if [ -f "./sing-box/sing-box.exe" ]; then
echo "检测到当前系统已安装 sing-boxr 内核,是否更新?(Y/n"
while true; do
read -n1 -r choice
case $choice in
[Yy])
echo
echo "正在下载 sing-boxr 内核..."
curl -sS -o "$USERPROFILE/Downloads/sing-box.exe" -L https://ghfast.top/https://github.com/DustinWin/proxy-tools/releases/download/sing-box/sing-box-ref1nd-testing-windows-amd64-v3.exe
echo "下载 sing-boxr 内核成功"
echo "正在结束 sing-boxr 相关进程..."
taskkill //f //t //im "sing-box*"
echo "结束 sing-boxr 相关进程成功"
echo "正在更新 sing-boxr 内核..."
mv -f "$USERPROFILE/Downloads/sing-box.exe" ./sing-box
if [ -f "./sing-box/config.json" ]; then
echo "更新 sing-boxr 内核成功,是否启动服务?(Y/n)"
while true; do
read -n1 -r choice
case $choice in
[Yy])
echo
echo "正在启动 sing-boxr 服务..."
cd ./sing-box
start //min sing-box run
read -n1 -r -p "启动 sing-boxr 服务成功,按任意键返回菜单..."
break
;;
[Nn])
break
;;
*)
echo
echo "无效选择,请重新输入!"
;;
esac
done
break
else
read -n1 -r -p "更新 sing-boxr 内核成功,请返回菜单导入配置文件!按任意键返回菜单..."
break
fi
;;
[Nn])
break
;;
*)
echo
echo "无效选择,请重新输入!"
;;
esac
done
else
echo "检测到当前系统未安装 sing-boxr 内核,是否安装?(Y/n"
while true; do
read -n1 -r choice
case $choice in
[Yy])
echo
echo "正在安装 sing-boxr 内核..."
mkdir -p ./sing-box
curl -sS -o ./sing-box/sing-box.exe -L https://ghfast.top/https://github.com/DustinWin/proxy-tools/releases/download/sing-box/sing-box-ref1nd-testing-windows-amd64-v3.exe
echo "安装 sing-boxr 内核成功"
echo "正在赋予 sing-box 权限..."
cmd //c "takeown /f sing-box /a /r /d y"
icacls sing-box /inheritance:r
icacls sing-box /remove[:g] "TrustedInstaller"
icacls sing-box /remove[:g] "CREATOR OWNER"
icacls sing-box /remove[:g] "ALL APPLICATION PACKAGES"
icacls sing-box /remove[:g] "所有受限制的应用程序包"
icacls sing-box /grant[:r] "SYSTEM:(OI)(CI)F"
icacls sing-box /grant[:r] "Administrators:(OI)(CI)F"
icacls sing-box /grant[:r] "Users:(OI)(CI)F"
read -n1 -r -p "赋予 sing-box 权限成功,请返回菜单导入配置文件!按任意键返回菜单..."
break
;;
[Nn])
break
;;
*)
echo
echo "无效选择,请重新输入!"
;;
esac
done
fi
;;
2)
ask_run(){
while true; do
read -n1 -r choice
case $choice in
[Yy])
echo
echo "正在启动 sing-boxr 服务..."
cd ./sing-box
start //min sing-box run
read -n1 -r -p "启动 sing-boxr 服务成功,按任意键返回菜单..."
break
;;
[Nn])
break
;;
*)
echo
echo "无效选择,请重新输入!"
;;
esac
done
}
echo "导入(更新)sing-boxr 配置文件"
cd "$PROGRAMFILES"
if [[ -f "./sing-box/sing-box.exe" && -f "./sing-box/config.json" ]]; then
echo "检测到 sing-boxr 配置文件,是否更新?(Y/n"
while true; do
read -n1 -r choice
case $choice in
[Yy])
echo
echo "正在下载 sing-boxr 配置文件..."
curl -sS -o "$USERPROFILE/Downloads/config.json" -L https://ghfast.top/{.json 配置文件直链}
echo "下载 sing-boxr 配置文件成功"
echo "正在结束 sing-boxr 相关进程..."
taskkill //f //t //im "sing-box*"
echo "结束 sing-boxr 相关进程成功"
echo "正在更新 sing-boxr 配置文件..."
mv -f "$USERPROFILE/Downloads/config.json" ./sing-box
echo "更新 sing-boxr 配置文件成功,是否启动服务?(Y/n)"
ask_run
break
;;
[Nn])
break
;;
*)
echo
echo "无效选择,请重新输入!"
;;
esac
done
elif [ ! -f "./sing-box/config.json" ]; then
echo "未检测到 sing-boxr 配置文件,是否导入?(Y/n"
while true; do
read -n1 -r choice
case $choice in
[Yy])
echo
echo "正在导入 sing-boxr 配置文件..."
curl -sS -o "$USERPROFILE/Downloads/config.json" -L https://ghfast.top/{.json 配置文件直链}
mv -f "$USERPROFILE/Downloads/config.json" ./sing-box
echo "导入 sing-boxr 配置文件成功,是否启动服务?(Y/n)"
ask_run
break
;;
[Nn])
break
;;
*)
echo
echo "无效选择,请重新输入!"
;;
esac
done
else
read -n1 -r -p "未检测到 sing-boxr 内核,请先返回菜单安装内核!按任意键返回菜单..."
fi
;;
3)
echo "正在启动 sing-boxr 服务..."
cd "$PROGRAMFILES"
if [[ -f "./sing-box/sing-box.exe" && -f "./sing-box/config.json" ]]; then
cd "./sing-box"
start //min sing-box run
read -n1 -r -p "启动 sing-boxr 服务成功,按任意键返回菜单..."
else
read -n1 -r -p "未检测到 sing-boxr 内核和配置文件,请返回菜单安装内核并导入配置文件!按任意键返回菜单..."
fi
;;
4)
echo "正在停止 sing-boxr 服务..."
taskkill //f //t //im "sing-box*"
read -n1 -r -p "停止 sing-boxr 服务成功,按任意键返回菜单..."
;;
0)
echo "退出程序"
exit 0
;;
*)
echo "无效选择,请重新输入!"
read -n1 -r -p "按任意键返回菜单..."
;;
esac
done
```
- ② 另存为 .sh 文件,右击并选择“以管理员身份运行”
### 2. 启动 sing-boxr
- ① 编辑本文文档,粘贴如下内容:
```shell
cd "%PROGRAMFILES%\sing-box"
start /min sing-box run
```
- ② 另存为 run.bat 文件并复制到 `%PROGRAMFILES%\sing-box`{: .filepath} 文件夹中
- ③ 右击 run.bat 文件并选择“以管理员身份运行”即可
小窍门:
- ➊ 右击 run.bat 文件并选择“发送到桌面快捷方式”
- ➋ 右击快捷方式并点击“属性” → “高级”,勾选“以管理员身份运行”并“确定”
- ➌ 若想开机启动 sing-boxr,可搜索“Windows 添加任务计划”教程自行添加
## 四、 访问 Dashboard 面板
1. 打开 zashboard 在线面板地址 <http://board.zash.run.place> 可直接通过 [Clash API](https://sing-boxr.dustinwin.us.kg/zh/configuration/experimental/clash-api/) 的方式访问 Dashboard 面板
2. 进入设置 → 后端设置,点击“+”图标,切换到“[sing-box API](https://sing-boxr.dustinwin.us.kg/zh/configuration/service/api/)”标签,将“端口”修改为 `9999` 并点击“提交”
<img src="/assets/img/share/172-9090-dashboard-singbox-pc.png" alt="面板设置" width="60%" />
3. 通过切换后端配置可以分别使用 Clash API(支持“代理提供商”和“规则提供商”的更新)和 sing-box API Dashboard 面板
> 推荐设置
{: .prompt-tip }
1. 进入 zashboard → 代理 → 代理设置 → 管理隐藏代理组,隐藏不必要显示的代理组
2. 进入 zashboard → 设置 → 图标,设置“自定义图标”,可参考 [icon 文件](https://github.com/DustinWin/ruleset_geodata/releases/tag/icons)
3. 进入 zashboard → 设置 → 后端设置 → 修改后端配置,可设置“标签 (可选)”来快速识别不同设备
@@ -0,0 +1,382 @@
---
title: ShellCrash 搭载 sing-boxr 内核本地配置自定义出站和规则-ruleset 方案
description: 此教程搭载 sing-boxr 内核,可通过修改本地配置文件的方式来自定义出站和规则 <code>rule_set</code>
date: 2024-08-22 18:10:32 +0800
categories: [工具配置, ShellCrash 配置]
tags: [sing-box, sing-boxr, ShellCrash, ruleset, rule_set, 进阶, 本地, Router]
---
> 说明
{: .prompt-tip }
1. 本教程只适用于 [ShellCrash](https://github.com/juewuy/ShellCrash)
2. 本教程**仅适合白名单模式**(没有命中规则的网络流量统统使用代理,适用于服务器线路网络质量稳定、快速,不缺服务器流量的用户)
3. 本教程最终效果媲美《[生成带有自定义出站和规则的 sing-boxr 配置文件直链-ruleset 方案](https://proxy-tutorials.dustinwin.us.kg/posts/link-singboxr-ruleset)》(出站分组更直观,操作更方便)
4. 若仅配置自定义出站和规则,可直接跳过《[](https://proxy-tutorials.dustinwin.us.kg/posts/toolsettings-shellcrash-singboxr-local-ruleset/#%E4%BA%8C-%E5%AF%BC%E5%85%A5%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6)》
5. 提供者 providers.json、出站 outbounds.json 和规则 route.json 为合并模式(在基础配置上新增)
6. 所有步骤完成后,请连接 SSH 后执行命令 `$CRASHDIR/start.sh restart` 生效
7. 推荐使用 [Visual Studio Code](https://code.visualstudio.com/Download) 等专业编辑器来修改配置文件
## 一、 导入 [sing-box reF1nd 版内核](https://github.com/reF1nd/sing-box)
可参考《[ShellCrash 搭载 sing-boxr 内核的配置-ruleset 方案/导入 sing-box reF1nd 版内核](https://proxy-tutorials.dustinwin.us.kg/posts/toolsettings-shellcrash-singboxr-ruleset/#%E4%B8%80-%E5%AF%BC%E5%85%A5-sing-box-reF1nd-%E7%89%88%E5%86%85%E6%A0%B8)》里的步骤进行操作
## 二、 导入配置文件
1. 进入 ShellCrash → 6 管理配置文件 → 1 在线生成配置文件 → 4 选取在线配置规则模版,选择 4 [ACL4SSR](https://acl4ssr-sub.github.io) 极简版(适合自建节点)
<img src="/assets/img/tools/subscribe-easy.png" alt="导入配置文件" width="60%" />
2. 进入 ShellCrash → 6 管理配置文件 → 1 在线生成 singboxr 配置文件,输入订阅链接后回车,再输入 `1` 并回车即可
## 三、 自定义出站和规则
### 1. 自定义提供者 providers.json(用于添加自定义提供者 `providers`
执行命令 `vi $CRASHDIR/jsons/providers.json`,按一下 Ins 键(Insert 键),编辑如下内容并粘贴:
```json
{
// 出站提供者(获取机场订阅链接内的所有节点)
"providers": [
{
"tag": "🛫 机场订阅 1",
"type": "remote",
// 机场订阅链接,使用 Clash 链接
"url": "https://example.com/xxx/xxx&flag=clash",
"path": "./providers/airport1.yaml",
// 若出现获取不了机场节点的情况,可删除此配置项
"user_agent": "clash.meta",
// 初步筛选需要的节点,可有效减轻路由器压力,支持正则表达式,若不筛选可删除此配置项
"include": "(?i)(🇭🇰|港|hk|hongkong|hong kong|🇹🇼|台|tw|taiwan|tai wan|🇯🇵|日|jp|japan|🇸🇬|新|sg|singapore|🇺🇸|美|us|unitedstates|united states)",
// 初步排除不需要的节点,支持正则表达式,若不排除可删除此配置项
"exclude": "高倍|直连|×10",
"health_check": {
"enabled": true,
"url": "https://www.gstatic.com/generate_204"
}
},
{
"tag": "🛫 机场订阅 2",
"type": "remote",
// 机场订阅链接,使用 sing-box 链接
"url": "https://example.com/xxx/xxx",
"path": "./providers/airport2.json",
"update_interval": "12h",
// 若出现获取不了机场节点的情况,可添加此配置项
"user_agent": "sing-box/1.12.12",
"include": [ "(?i)(🇭🇰|港|hk|hongkong|hong kong|🇹🇼|台|tw|taiwan|tai wan|🇯🇵|日|jp|japan|🇸🇬|新|sg|singapore|🇺🇸|美|us|unitedstates|united states)" ],
"exclude": "高倍|直连|×10",
"health_check": {
"enabled": true,
"url": "https://www.gstatic.com/generate_204"
}
}
]
}
```
按一下 Esc 键(退出键),输入英文冒号 `:`,继续输入 `wq` 并回车
### 2. 自定义出站 outbounds.json(用于添加自定义出站 `outbounds`
连接 SSH 后执行命令 `vi $CRASHDIR/jsons/outbounds.json`,按一下 Ins 键(Insert 键),编辑如下内容并粘贴:
```json
{
// 出站
"outbounds": [
// 手动选择国家或地区节点;根据“国家或地区出站”的名称对 `outbounds` 值进行增删改,须一一对应
{ "tag": "🈯 节点指定", "type": "selector", "outbounds": [ "♻️ 自动选择", "👉 手动选择", "🇭🇰 香港节点", "🇹🇼 台湾节点", "🇯🇵 日本节点", "🇸🇬 新加坡节点", "🇺🇸 美国节点", "🆓 免费节点" ] },
// 选择`🎯 全球直连`为测试本地网络(运营商网络速度和 IPv6 支持情况),可选择其它节点用于测试机场节点速度和 IPv6 支持情况
{ "tag": "📈 网络测试", "type": "selector", "outbounds": [ "🎯 全球直连", "🈯 节点指定", "🇭🇰 香港节点", "🇹🇼 台湾节点", "🇯🇵 日本节点", "🇸🇬 新加坡节点", "🇺🇸 美国节点", "🆓 免费节点" ] },
{ "tag": "🕹️ 游戏平台", "type": "selector", "outbounds": [ "🈯 节点指定", "🇭🇰 香港节点", "🇹🇼 台湾节点", "🇯🇵 日本节点", "🇸🇬 新加坡节点", "🇺🇸 美国节点" ] },
{ "tag": "🤖 AI 平台", "type": "selector", "outbounds": [ "🈯 节点指定", "🇭🇰 香港节点", "🇹🇼 台湾节点", "🇯🇵 日本节点", "🇰🇷 韩国节点", "🇸🇬 新加坡节点", "🇺🇸 美国节点"] },
{ "tag": "🎮 游戏服务", "type": "selector", "outbounds": [ "🎯 全球直连", "🈯 节点指定" ] },
{ "tag": "🪟 微软服务", "type": "selector", "outbounds": [ "🎯 全球直连", "🈯 节点指定" ] },
{ "tag": "🇬 谷歌服务", "type": "selector", "outbounds": [ "🎯 全球直连", "🈯 节点指定" ] },
{ "tag": "🍎 苹果服务", "type": "selector", "outbounds": [ "🎯 全球直连", "🈯 节点指定" ] },
{ "tag": "🌍 国外媒体", "type": "selector", "outbounds": [ "🈯 节点指定", "🇭🇰 香港节点", "🇹🇼 台湾节点", "🇯🇵 日本节点", "🇸🇬 新加坡节点", "🇺🇸 美国节点" ] },
{ "tag": "🇨🇳 国内域名", "type": "selector", "outbounds": [ "🎯 全球直连", "🈯 节点指定" ] },
{ "tag": "🀄️ 国内 IP", "type": "selector", "outbounds": [ "🎯 全球直连", "🈯 节点指定" ] },
{ "tag": "🌎 国外域名", "type": "selector", "outbounds": [ "🈯 节点指定", "🇭🇰 香港节点", "🇹🇼 台湾节点", "🇯🇵 日本节点", "🇰🇷 韩国节点", "🇸🇬 新加坡节点", "🇺🇸 美国节点", "🆓 免费节点" ] },
{ "tag": "📲 电报消息", "type": "selector", "outbounds": [ "🈯 节点指定", "🇭🇰 香港节点", "🇹🇼 台湾节点", "🇯🇵 日本节点", "🇰🇷 韩国节点", "🇸🇬 新加坡节点", "🇺🇸 美国节点", "🆓 免费节点" ] },
// 单个出站节点(以 vless 为例)
{
"tag": "🆓 免费节点",
"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" } }
},
// -------------------- 国家或地区出站 --------------------
// 自动选择节点,即按照 url 测试结果使用延迟最低的节点;测试后默认容差大于 50ms 才会切换到延迟低的那个节点;筛选出“香港”节点,支持正则表达式
{ "tag": "🇭🇰 香港节点", "type": "urltest", "use_all_providers": true, "include": "(?i)(🇭🇰|港|hk|hongkong|hong kong)" },
{ "tag": "🇹🇼 台湾节点", "type": "urltest", "use_all_providers": true, "include": "(?i)(🇹🇼|台|tw|taiwan|tai wan)" },
{ "tag": "🇯🇵 日本节点", "type": "urltest", "use_all_providers": true, "include": "(?i)(🇯🇵|日|jp|japan)" },
{ "tag": "🇸🇬 新加坡节点", "type": "urltest", "use_all_providers": true, "include": "(?i)(🇸🇬|新|sg|singapore)" },
{ "tag": "🇺🇸 美国节点", "type": "urltest", "tolerance": 100, "use_all_providers": true, "include": "(?i)(🇺🇸|美|us|unitedstates|united states)" },
{ "tag": "👉 手动选择", "type": "selector", "use_all_providers": true }
]
}
```
按一下 Esc 键(退出键),输入英文冒号 `:`,继续输入 `wq` 并回车
### 3. 自定义规则 route.json(用于添加自定义路由和规则 `route`)
执行命令 `vi $CRASHDIR/jsons/route.json`,按一下 Ins 键(Insert 键),编辑如下内容并粘贴:
```json
{
// 路由
"route": {
// 规则
"rules": [
// 自定义规则优先放前面
{ "rule_set": [ "private" ], "outbound": "🎯 全球直连" },
{ "rule_set": [ "ads" ], "action": "reject" },
{ "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": [ "media" ], "outbound": "🌍 国外媒体" },
{ "rule_set": [ "ai" ], "outbound": "🤖 AI 平台" },
{ "rule_set": [ "networktest" ], "outbound": "📈 网络测试" },
{ "rule_set": [ "proxy" ], "outbound": "🌎 国外域名" },
{ "rule_set": [ "cn" ], "outbound": "🇨🇳 国内域名" },
{ "rule_set": [ "privateip" ], "outbound": "🎯 全球直连" },
{ "rule_set": [ "telegramip" ], "outbound": "📲 电报消息" },
// 将目标域名解析成 IP 后与下方的 IP 规则进行匹配,提高兼容性
{ "action": "resolve", "match_only": true },
{ "rule_set": [ "cnip" ], "outbound": "🀄️ 国内 IP" },
{ "rule_set": [ "mediaip" ], "outbound": "🌍 国外媒体" }
],
// 规则集(binary 文件每天自动更新)
"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": "media",
"type": "remote",
"format": "binary",
"path": "./ruleset/media.srs",
"url": "https://github.com/DustinWin/ruleset_geodata/releases/download/sing-box-ruleset/media.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": "privateip",
"type": "remote",
"format": "binary",
"path": "./ruleset/privateip.srs",
"url": "https://github.com/DustinWin/ruleset_geodata/releases/download/sing-box-ruleset/privateip.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"
},
{
"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": "mediaip",
"type": "remote",
"format": "binary",
"path": "./ruleset/mediaip.srs",
"url": "https://github.com/DustinWin/ruleset_geodata/releases/download/sing-box-ruleset/mediaip.srs"
}
]
}
}
```
按一下 Esc 键(退出键),输入英文冒号 `:`,继续输入 `wq` 并回车
## 四、 修改出站或规则
**举例:我的机场包含有 2 个节点,分别是新加坡节点和日本节点,我想让 [Netflix](https://www.netflix.com/) 自动选择延迟最低的新加坡节点,[哔哩哔哩](https://www.bilibili.com)可以手动选择日本任一节点**
> 一定要保证缩进对齐!一定要保证缩进对齐!一定要保证缩进对齐!
{: .prompt-warning }
### 1. 修改 outbounds.json 文件
连接 SSH 后执行命令 `vi $CRASHDIR/jsons/outbounds.json`,按一下 Ins 键(Insert 键),编辑如下内容并粘贴:
```json
{
// 出站
"outbounds": [
// 默认选择新加坡节点
{ "tag": "🎥 奈飞视频", "type": "selector", "outbounds": [ "🇸🇬 新加坡节点" ] },
// 默认选择日本节点,也可切换到直连
{ "tag": "📺 哔哩哔哩", "type": "selector", "outbounds": [ "🇯🇵 日本节点", "🎯 全球直连" ] },
// 自动选择延迟最低的新加坡节点;默认容差大于 50ms 才会切换到延迟低的那个节点
{ "tag": "🇸🇬 新加坡节点", "type": "urltest", "use_all_providers": true, "include": "(?i)(🇸🇬|新|sg|singapore)" },
// 手动选择日本任一节点
{ "tag": "🇯🇵 日本节点", "type": "selector", "use_all_providers": true, "include": "(?i)(🇯🇵|日|jp|japan)" }
]
}
```
按一下 Esc 键(退出键),输入英文冒号 `:`,继续输入 `wq` 并回车
### 2. 修改 route.json 文件
连接 SSH 后执行命令 `vi $CRASHDIR/jsons/route.json`,按一下 Ins 键(Insert 键),优先在最上方编辑如下内容并粘贴:
```json
{
// 路由
"route": {
// 规则
"rules": [
// 自定义规则优先放前面
{ "rule_set": [ "bilibili" ], "outbound": "📺 哔哩哔哩" },
{ "rule_set": [ "netflix" ], "outbound": "🎥 奈飞视频" },
// 将目标域名解析成 IP 后与下方的 IP 规则进行匹配,提高兼容性
{ "action": "resolve", "match_only": true },
{ "rule_set": [ "netflixip" ], "outbound": "🎥 奈飞视频" }
],
// 规则集(binary 文件每天自动更新)
"rule_set": [
{
"tag": "bilibili",
"type": "remote",
"format": "binary",
"path": "./ruleset/bilibili.srs",
"url": "https://github.com/DustinWin/ruleset_geodata/releases/download/sing-box-ruleset/bilibili.srs"
},
{
"tag": "netflix",
"type": "remote",
"format": "binary",
"path": "./ruleset/netflix.srs",
"url": "https://github.com/DustinWin/ruleset_geodata/releases/download/sing-box-ruleset/netflix.srs"
},
{
"tag": "netflixip",
"type": "remote",
"format": "binary",
"path": "./ruleset/netflixip.srs",
"url": "https://github.com/DustinWin/ruleset_geodata/releases/download/sing-box-ruleset/netflixip.srs"
}
]
}
}
```
按一下 Esc 键(退出键),输入英文冒号 `:`,继续输入 `wq` 并回车
> 若有其它需求,可进入 [MetaCubeX/meta-rules-dat/sing](https://github.com/MetaCubeX/meta-rules-dat/tree/sing) 搜索关键字,通过能够搜索到的关键字来编写出站和规则(推荐使用“*.srs”文件,`route.rule_set` 内须配置 `"format": "binary"`
{: .prompt-tip }
## 五、 添加小规则
仅添加特定网址走直连或走代理,连接 SSH 后执行命令 `vi $CRASHDIR/jsons/route.json`,按一下 Ins 键(Insert 键),在**最上方**粘贴如下内容:
注:
- ① 以下内容只是举例,请根据自身需要进行增删改
- ② 其它规则请参考《[sing-box Wiki](https://sing-box.sagernet.org/zh/configuration/route/rule)》
```json
{
// 路由
"route": {
// 规则
"rules": [
// 以 googleapis.cn 为后缀(包括 googleapis.cn)的所有域名走代理
{ "domain_suffix": [ "googleapis.cn" ], "outbound": "🈯 节点指定" },
// 与哔哩哔哩相关的所有域名走直连
{ "rule_set": [ "bilibili" ], "outbound": "DIRECT" },
// 含有 ipv6 关键字的所有域名走直连
{ "domain_keyword": [ "ipv6" ], "outbound": "DIRECT" }
],
// 规则集(binary 文件每天自动更新)
"rule_set": [
{
"tag": "bilibili",
"type": "remote",
"format": "binary",
"path": "./ruleset/bilibili.srs",
"url": "https://github.com/DustinWin/ruleset_geodata/releases/download/sing-box-ruleset/bilibili.srs"
}
]
}
}
```
按一下 Esc 键(退出键),输入英文冒号 `:`,继续输入 `wq` 并回车
@@ -0,0 +1,78 @@
---
title: ShellCrash 搭载 sing-boxr 内核的配置-ruleset 方案
description: 此配置搭载 sing-boxr 内核,包括 ShellCrash 的安装、配置和使用方法
date: 2024-08-22 17:34:34 +0800
categories: [工具配置, ShellCrash 配置]
tags: [sing-box, sing-boxr, ShellCrash, ruleset, rule_set, 基础, Router]
---
> 说明
{: .prompt-tip }
1. 本教程中的下载链接以 CPU 架构 ARM64 为例,若为别的 CPU 架构,请注意修改链接后缀
2. 查看 CPU 架构可连接 SSH 后执行命令 `uname -ms`,若执行结果是“linux aarch64”,就是搭载的 ARM64 架构
## 一、 导入 [sing-box reF1nd 版内核](https://github.com/reF1nd/sing-box)
连接 SSH 后执行如下命令:
```shell
curl -sS -o /tmp/CrashCore.upx -L https://ghfast.top/https://github.com/DustinWin/proxy-tools/releases/download/sing-box/sing-box-ref1nd-stable-linux-arm64.upx
```
## 二、 添加定时任务
1. 连接 SSH 后执行命令 `vi $CRASHDIR/configs/task/task.user`,按一下 Ins 键(Insert 键),粘贴(快捷键 Ctrl+Shift+V)如下内容:
- 注:须重启 ShellCrash 服务后生效
```shell
201#curl -sS -o $CRASHDIR/cn_ip.txt -L https://ghfast.top/https://github.com/DustinWin/geoip/releases/download/ips/cn_ipv4.txt && curl -sS -o $CRASHDIR/cn_ipv6.txt -L https://ghfast.top/https://github.com/DustinWin/geoip/releases/download/ips/cn_ipv6.txt >/dev/null 2>&1#更新CN_IP文件
```
2. 按一下 Esc 键(退出键),输入英文冒号 `:`,继续输入 `wq` 并回车
3. 执行 `sc`,进入 ShellCrash 配置脚本 → 5) 自动任务 → 1) 添加自动任务,可以看到末尾就有添加的定时任务,输入对应的数字并回车后可设置执行条件
<img src="/assets/img/share/task-ruleset.png" alt="添加定时任务" width="60%" />
## 三、 设置部分
1. 连接 SSH 后执行命令 `sc` 即可打开 ShellCrash 配置脚本(若安装 ShellCrash 后自定义别名选择的是“2) 【 sc 】”)
2. 新手引导
- ① 选择“1) 路由设备配置局域网透明代理”
- ② 根据需要是否启用小内存模式(此处选择“0”)
- ③ 启用推荐的自动任务配置
- ④ 根据需要是否开始导入配置文件(此处选择“0”)
- ⑤ 此时脚本会自动“发现可用的内核文件”,选择“1) 立即加载”,后选择“2) Singbox-reF1nd”
<img src="/assets/img/pin/import-mihomo.png" alt="ShellCrash 配置 1" width="60%" />
- ⑥ 内核加载完成后根据需要是否保留相关数据库文件(此处选择“0) 不保留”)
3. 进入 2) 功能设置 → 2) DNS 设置 → 9) 修改 DNS 服务器,选择“4) 一键配置加密 DNS”
- ① 推荐设置 DNS 分流,请看《[搭载 mihomo 内核进行 DNS 分流教程-geodata 方案](https://proxy-tutorials.dustinwin.us.kg/posts/dnsbypass-mihomo-geodata)》
- ② 进入 2) 功能设置 → 5) 启用域名嗅探,选择“1) 是”
4. 进入主菜单 → 4 启动设置,启用“1) 开机自启动”
5. 进入主菜单 → 5) 自动任务 → 1) 添加自动任务,选择 8) 自动更新内核,回车后可设置执行条件
6. 进入主菜单 → 8) 工具与优化,选择“6) 小米设备软固化 SSH”(无需输入需要还原的 SSH 密码)
7. 进入 8) 工具与优化 → 8) 小米设备Tun模块修复,选择“1) 我已知晓,出现问题会自行承担!”
8. 进入主菜单 → 9) 更新与支持 → 2) 切换/更新内核文件 → 6) 使用自定义内核 → 9) 自定义内核链接,输入导入内核命令里的链接并回车,选择“2) Singbox-reF1nd”
9. 进入 9) 更新与支持 → 4) 安装/更新本地Dashboard面板,推荐安装“1) 安装 zashboard 面板”
10. 导入配置文件
- ① 进入主菜单 → 6) 配置文件管理 → a) 添加提供者 → 1) 设置名称或代号,如输入“sing-boxr”;后进入 2) 设置链接或路径,粘贴《[生成带有自定义出站和规则的 sing-boxr 配置文件直链-ruleset 方案](https://proxy-tutorials.dustinwin.us.kg/posts/link-singboxr-ruleset)》中生成的 .yaml 配置文件直链,选择“a) 保存此提供者”
- ② 进入 6) 配置文件管理 → c) 在线生成配置文件 → 6) 自定义浏览器 UA,选择“2) 不使用 UA”
- ③ 进入 6) 配置文件管理 → 1) sing-boxr,选择“e) 在线获取此配置文件”,启动服务即可
11. 访问 Dashboard 面板
- ① 打开 <http://192.168.31.1:9090/dashboard/> 后,直接在“[Clash API](https://sing-boxr.dustinwin.us.kg/zh/configuration/experimental/clash-api/)”标签里将“主机”和“端口”分别修改为 `192.168.31.1``9999`,点击“提交”即可访问 Dashboard 面板
<img src="/assets/img/tools/192-9999-dashboard-singbox_1.png" alt="设置部分 2" width="60%" />
- ② 进入 Dashboard 面板 → 设置 → 后端设置,点击“+”图标,切换到“[sing-box API](https://sing-boxr.dustinwin.us.kg/zh/configuration/service/api/)”标签,将“主机”修改为 `192.168.31.1` 并点击“提交”
<img src="/assets/img/tools/192-9999-dashboard-singbox_2.png" alt="设置部分 3" width="60%" />
- ③ 通过切换后端配置可以分别使用 Clash API(支持“代理提供商”和“规则提供商”的更新)和 sing-box API Dashboard 面板
- ④ 无法通过手动点击“升级面板”来更新 zashboard(默认每日自动更新)
- ⑤ 进入 Dashboard 面板 → 代理 → 代理提供者,点击“转圈”图标,可手动更新节点
## 四、 在线 Dashboard 面板(可选)
1. 若使用基于 [Chromium 项目](https://www.chromium.org/Home/)开发的浏览器无法访问在线 Dashboard 面板时,以 [Chrome 浏览器](https://www.google.com/chrome/)为例,需要设置该网址域名“允许显示不安全内容”,进入设置 → 隐私和安全 → 网站设置 → 更多内容设置 → 不安全内容(或者直接在地址栏打开 `chrome://settings/content/insecureContent` 进行设置),在“允许显示不安全内容”内添加网址域名 `board.zash.run.place`
<img src="/assets/img/tools/chrome-setting-dashboard.png" alt="在线 Dashboard 面板 1" width="60%" />
2. 打开 [zashboard](https://github.com/Zephyruso/zashboard) 在线面板地址 <http://board.zash.run.place> 后,直接在“Clash API”标签里将“主机”和“端口”分别修改为 `192.168.31.1``9999`,点击“提交”即可访问 Dashboard 面板
<img src="/assets/img/tools/192-9999-dashboard-singbox_1.png" alt="在线 Dashboard 面板 2" width="60%" />
3. 进入 Dashboard 面板 → 设置 → 后端设置,点击“+”图标,切换到“sing-box API”标签,将“主机”修改为 `192.168.31.1` 并点击“提交”
<img src="/assets/img/tools/192-9999-dashboard-singbox_2.png" alt="在线 Dashboard 面板 3" width="60%" />
4. 通过切换后端配置可以分别使用 Clash API(支持“代理提供商”和“规则提供商”的更新)和 sing-box API Dashboard 面板
@@ -0,0 +1,622 @@
---
title: 分享 mihomo for Windows 采用 ruleset 方案的一套配置
description: 此配置搭载 mihomo 内核,采用 <code>RULE-SET</code> 规则搭配 .list 和 .mrs 规则集合文件
date: 2024-12-04 02:30:00 +0800
categories: [分享配置, Windows]
tags: [Clash, mihomo, Windows, ruleset, rule-set, 分享]
---
> 声明
{: .prompt-warning }
1. 请根据自身情况进行修改,**适合自己的方案才是最好的方案**,如无特殊需求,可以照搬
2. 此方案采用**裸核**的方式运行,更加精简
## 一、 生成配置文件 .yaml 文件直链
具体方法请参考《[生成带有自定义策略组和规则的 mihomo 配置文件直链-ruleset 方案](https://proxy-tutorials.dustinwin.us.kg/posts/link-mihomo-ruleset)》,贴一下我使用的配置:
```yaml
proxy-providers:
🛫 机场订阅:
type: http
# 修改为你的 Clash 订阅链接
url: "https://example.com/xxx/xxx&flag=clash"
path: ./proxies/airport.yaml
interval: 86400
filter: "(?i)(🇭🇰|港|hk|hongkong|hong kong|🇹🇼|台|tw|taiwan|tai wan|🇯🇵|日|jp|japan|🇸🇬|新|sg|singapore|🇺🇸|美|us|unitedstates|united states)"
health-check:
enable: true
url: https://www.gstatic.com/generate_204
interval: 600
🆓 免费订阅:
type: http
# 修改为你的 Clash 订阅链接
url: "https://example.com/xxx/xxx&flag=clash"
path: ./proxies/free.yaml
interval: 43200
health-check:
enable: true
url: https://www.gstatic.com/generate_204
interval: 600
log-level: error
ipv6: true
allow-lan: true
mixed-port: 7890
unified-delay: true
tcp-concurrent: true
external-controller: 0.0.0.0:9090
profile: {store-selected: true, store-fake-ip: true}
sniffer:
enable: true
parse-pure-ip: true
sniff: {HTTP: {ports: [80, 8080-8880], override-destination: true}, TLS: {ports: [443, 8443]}, QUIC: {ports: [443, 8443]}}
skip-domain: ['Mijia Cloud']
tun:
enable: true
stack: mixed
dns-hijack: [any:53]
auto-route: true
auto-detect-interface: true
device: mihomo
strict-route: true
hosts:
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:
enable: true
prefer-h3: true
ipv6: true
enhanced-mode: fake-ip
fake-ip-range: 28.0.0.0/8
fake-ip-range6: fc00::/16
fake-ip-filter-mode: rule
fake-ip-filter:
- RULE-SET,private,real-ip
- RULE-SET,trackerslist,real-ip
- RULE-SET,microsoft-cn,real-ip
- RULE-SET,apple-cn,real-ip
- RULE-SET,google-cn,real-ip
- RULE-SET,games-cn,real-ip
- RULE-SET,games,fake-ip
- RULE-SET,ai,fake-ip
- RULE-SET,proxy,fake-ip
- RULE-SET,cn,real-ip
- MATCH,fake-ip
nameserver:
- quic://dns.alidns.com:853
- https://doh.pub/dns-query
nameserver-policy:
'rule-set:private': [system]
'rule-set:ads': [rcode://success]
# 若没有单个出站代理节点,须删除所有 `🆚 vless 节点` 相关内容
proxies:
- name: 🆚 vless 节点
type: vless
server: example.com
port: 443
uuid: {uuid}
network: ws
tls: true
udp: false
sni: example.com
client-fingerprint: chrome
ws-opts:
path: "/?ed=2048"
headers:
host: example.com
proxy-groups:
- {name: 节点选择, type: select, proxies: [香港节点, 台湾节点, 日本节点, 新加坡节点, 美国节点, 免费节点, 🆚 vless 节点], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/proxy.png"}
- {name: 网络测试, type: select, proxies: [全球直连, 节点选择, 香港节点, 台湾节点, 日本节点, 新加坡节点, 美国节点, 免费节点, 🆚 vless 节点], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/networktest.png"}
- {name: 游戏平台, type: select, proxies: [节点选择, 香港节点, 台湾节点, 日本节点, 新加坡节点, 美国节点, 🆚 vless 节点], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/games.png"}
- {name: AI 平台, type: select, proxies: [节点选择, 香港节点, 台湾节点, 日本节点, 新加坡节点, 美国节点, 🆚 vless 节点], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/ai.png"}
- {name: 游戏服务, type: select, proxies: [全球直连, 节点选择], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/games-cn.png"}
- {name: 微软服务, type: select, proxies: [全球直连, 节点选择], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/microsoft-cn.png"}
- {name: 谷歌服务, type: select, proxies: [全球直连, 节点选择], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/google-cn.png"}
- {name: 苹果服务, type: select, proxies: [全球直连, 节点选择], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/apple-cn.png"}
- {name: 国内域名, type: select, proxies: [全球直连, 节点选择], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/cn.png"}
- {name: 国内 IP, type: select, proxies: [全球直连, 节点选择], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/cnip.png"}
- {name: 国外域名, type: select, proxies: [节点选择, 香港节点, 台湾节点, 日本节点, 新加坡节点, 美国节点, 免费节点, 🆚 vless 节点], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/global.png"}
- {name: 电报消息, type: select, proxies: [节点选择, 香港节点, 台湾节点, 日本节点, 新加坡节点, 美国节点, 免费节点, 🆚 vless 节点], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/telegram.png"}
- {name: 直连软件, type: select, proxies: [全球直连], hidden: true, icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/applications.png"}
- {name: 私有网络, type: select, proxies: [全球直连], hidden: true, icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/private.png"}
# 若机场的 UDP 质量不是很好,导致某游戏无法登录或进入房间,可以添加 `disable-udp: true` 配置项解决
- {name: 漏网之鱼, type: select, proxies: [节点选择, 香港节点, 台湾节点, 日本节点, 新加坡节点, 美国节点, 免费节点, 🆚 vless 节点, 全球直连], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/match.png"}
- {name: 全球直连, type: select, proxies: [DIRECT], hidden: true, icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/direct.png"}
- {name: 香港节点, type: url-test, tolerance: 50, use: [🛫 机场订阅], filter: "(?i)(🇭🇰|港|hk|hongkong|hong kong)", icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/hongkong.png"}
- {name: 台湾节点, type: url-test, tolerance: 50, use: [🛫 机场订阅], filter: "(?i)(🇹🇼|台|tw|taiwan|tai wan)", icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/taiwan.png"}
- {name: 日本节点, type: url-test, tolerance: 50, use: [🛫 机场订阅], filter: "(?i)(🇯🇵|日|jp|japan)", icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/japan.png"}
- {name: 新加坡节点, type: url-test, tolerance: 50, use: [🛫 机场订阅], filter: "(?i)(🇸🇬|新|sg|singapore)", icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/singapore.png"}
- {name: 美国节点, type: url-test, tolerance: 100, use: [🛫 机场订阅], filter: "(?i)(🇺🇸|美|us|unitedstates|united states)", icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/unitedstates.png"}
- {name: 免费节点, type: url-test, tolerance: 100, use: [🆓 免费订阅], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/free.png"}
rule-providers:
trackerslist:
type: http
behavior: domain
format: mrs
path: ./ruleset/trackerslist.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/trackerslist.mrs"
interval: 86400
ads:
type: http
behavior: domain
format: mrs
path: ./ruleset/ads.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/ads.mrs"
interval: 86400
private:
type: http
behavior: domain
format: mrs
path: ./ruleset/private.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/private.mrs"
interval: 86400
applications:
type: http
behavior: classical
format: text
path: ./ruleset/applications.list
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/applications.list"
interval: 86400
microsoft-cn:
type: http
behavior: domain
format: mrs
path: ./ruleset/microsoft-cn.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/microsoft-cn.mrs"
interval: 86400
apple-cn:
type: http
behavior: domain
format: mrs
path: ./ruleset/apple-cn.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/apple-cn.mrs"
interval: 86400
google-cn:
type: http
behavior: domain
format: mrs
path: ./ruleset/google-cn.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/google-cn.mrs"
interval: 86400
games-cn:
type: http
behavior: domain
format: mrs
path: ./ruleset/games-cn.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/games-cn.mrs"
interval: 86400
games:
type: http
behavior: domain
format: mrs
path: ./ruleset/games.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/games.mrs"
interval: 86400
ai:
type: http
behavior: domain
format: mrs
path: ./ruleset/ai.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/ai.mrs"
interval: 86400
networktest:
type: http
behavior: domain
format: mrs
path: ./ruleset/networktest.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/networktest.mrs"
interval: 86400
proxy:
type: http
behavior: domain
format: mrs
path: ./ruleset/proxy.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/proxy.mrs"
interval: 86400
cn:
type: http
behavior: domain
format: mrs
path: ./ruleset/cn.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/cn.mrs"
interval: 86400
privateip:
type: http
behavior: ipcidr
format: mrs
path: ./ruleset/privateip.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/privateip.mrs"
interval: 86400
cnip:
type: http
behavior: ipcidr
format: mrs
path: ./ruleset/cnip.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/cnip.mrs"
interval: 86400
telegramip:
type: http
behavior: ipcidr
format: mrs
path: ./ruleset/telegramip.mrs
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/telegramip.mrs"
interval: 86400
rules:
- RULE-SET,private,私有网络
- RULE-SET,applications,直连软件
- RULE-SET,microsoft-cn,微软服务
- RULE-SET,apple-cn,苹果服务
- RULE-SET,google-cn,谷歌服务
- RULE-SET,games-cn,游戏服务
- RULE-SET,games,游戏平台
- RULE-SET,ai,AI 平台
- RULE-SET,networktest,网络测试
- RULE-SET,proxy,国外域名
- RULE-SET,cn,国内域名
- RULE-SET,privateip,私有网络,no-resolve
- RULE-SET,cnip,国内 IP
- RULE-SET,telegramip,电报消息,no-resolve
- MATCH,漏网之鱼
```
---
>`DNS` 私货
{: .prompt-tip }
注:
- ① 本 `dns` 配置中,国内域名走国内 DNS 解析,国外域名走 `fake-ip`,未知域名也走 `fake-ip`,在匹配 `RULE-SET:cn` 规则时会由国外 DNS 解析且配置 `ecs` 提高了兼容性,解析出 IP 在国内则走 `国内 IP` 规则,否则走 `漏网之鱼` 规则(有效解决了“心理 DNS 泄露问题”,详见《[搭载 mihomo 内核配置 DNS 不泄露教程-ruleset 方案](https://proxy-tutorials.dustinwin.us.kg/posts/dnsnoleaks-mihomo-ruleset/)》)
- ② 推荐将 `ecs` 设置为当前宽带运营商分配的默认 DNS(可进入光猫或路由器拨号页面查看,或者前往[公共 DNS 大全](https://toolb.cn/publicdns)查询)的 IP 段,如默认 DNS 为 `211.137.58.20`,可设置为 `211.137.58.0/24`
```yaml
hosts:
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]
dns:
enable: true
ipv6: true
listen: 0.0.0.0:1053
enhanced-mode: fake-ip
fake-ip-range: 28.0.0.0/8
fake-ip-range6: fc00::/16
fake-ip-filter-mode: rule
fake-ip-filter:
- RULE-SET,private,real-ip
- RULE-SET,trackerslist,real-ip
- RULE-SET,microsoft-cn,real-ip
- RULE-SET,apple-cn,real-ip
- RULE-SET,google-cn,real-ip
- RULE-SET,games-cn,real-ip
- RULE-SET,games,fake-ip
- RULE-SET,ai,fake-ip
- RULE-SET,proxy,fake-ip
- RULE-SET,cn,real-ip
- MATCH,fake-ip
respect-rules: true
nameserver:
# 推荐将 `ecs` 设置为当前宽带运营商分配的默认 DNS 的 IP 段
- 'https://dns.google/dns-query#ecs=211.137.58.0/24&ecs-override=true'
- 'quic://dns11.quad9.net:853#ecs=211.137.58.0/24&ecs-override=true'
proxy-server-nameserver:
- quic://dns.alidns.com:853
- https://doh.pub/dns-query
direct-nameserver:
- quic://dns.alidns.com:853
- https://doh.pub/dns-query
direct-nameserver-follow-policy: true
nameserver-policy:
'rule-set:private': [system]
'rule-set:ads': [rcode://success]
'rule-set:trackerslist,microsoft-cn,apple-cn,google-cn,games-cn,cn': [quic://dns.alidns.com:853, https://doh.pub/dns-query]
```
---
>`proxy-groups` 私货
{: .prompt-tip }
注:
- ① 本 `proxy-groups` 配置中,将不同的节点类型(如:`Shadowsocks``Trojan`)分别配置 `type: url-test` 进行延迟测试,且配置 `hidden: true` 以简化 Dashboard 面板中的显示。再将延迟测试最低的策略组配置 `type: load-balance` 进行负载均衡
- ② 将不同的优选节点分别配置 `type: fallback` 进行故障转移,且配置 `hidden: true` 以简化 Dashboard 面板中的显示。再将故障转移后的策略组配置 `type: url-test` 进行延迟测试
```yaml
proxy-groups:
- {name: 香港节点, type: load-balance, strategy: consistent-hashing, proxies: [香港-ss, 香港-trojan], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/hongkong.png"}
- {name: 香港-ss, type: url-test, tolerance: 50, use: [🛫 机场订阅], filter: "(?i)((🇭🇰|港|hk|hongkong|hong kong).*ss)", hidden: true, icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/shadowsocks.png"}
- {name: 香港-trojan, type: url-test, tolerance: 50, use: [🛫 机场订阅], filter: "(?i)(🇭🇰|港|hk|hongkong|hong kong)", exclude-filter: "(?i)(ss)", hidden: true, icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/trojan.png"}
- {name: 台湾节点, type: load-balance, strategy: consistent-hashing, proxies: [台湾-ss, 台湾-trojan], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/taiwan.png"}
- {name: 台湾-ss, type: url-test, tolerance: 50, use: [🛫 机场订阅], filter: "(?i)((🇹🇼|台|tw|taiwan|tai wan).*ss)", hidden: true, icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/shadowsocks.png"}
- {name: 台湾-trojan, type: url-test, tolerance: 50, use: [🛫 机场订阅], filter: "(?i)(🇹🇼|台|tw|taiwan|tai wan)", exclude-filter: "(?i)(ss)", hidden: true, icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/trojan.png"}
- {name: 日本节点, type: load-balance, strategy: consistent-hashing, proxies: [日本-ss, 日本-trojan], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/japan.png"}
- {name: 日本-ss, type: url-test, tolerance: 50, use: [🛫 机场订阅], filter: "(?i)((🇯🇵|日|jp|japan).*ss)", hidden: true, icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/shadowsocks.png"}
- {name: 日本-trojan, type: url-test, tolerance: 50, use: [🛫 机场订阅], filter: "(?i)(🇯🇵|日|jp|japan)", exclude-filter: "(?i)(ss)", hidden: true, icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/trojan.png"}
- {name: 新加坡节点, type: load-balance, strategy: consistent-hashing, proxies: [新加坡-ss, 新加坡-trojan], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/singapore.png"}
- {name: 新加坡-ss, type: url-test, tolerance: 50, use: [🛫 机场订阅], filter: "(?i)((🇸🇬|新|sg|singapore).*ss)", hidden: true, icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/shadowsocks.png"}
- {name: 新加坡-trojan, type: url-test, tolerance: 50, use: [🛫 机场订阅], filter: "(?i)(🇸🇬|新|sg|singapore)", exclude-filter: "(?i)(ss)", hidden: true, icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/trojan.png"}
- {name: 美国节点, type: load-balance, strategy: consistent-hashing, proxies: [美国-ss, 美国-trojan], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/unitedstates.png"}
- {name: 美国-ss, type: url-test, tolerance: 100, use: [🛫 机场订阅], filter: "(?i)((🇺🇸|美|us|unitedstates|united states).*ss)", hidden: true, icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/shadowsocks.png"}
- {name: 美国-trojan, type: url-test, tolerance: 100, use: [🛫 机场订阅], filter: "(?i)(🇺🇸|美|us|unitedstates|united states)", exclude-filter: "(?i)(ss)", hidden: true, icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/trojan.png"}
- {name: 免费节点, type: url-test, tolerance: 100, proxies: [移动优选节点, CF 优选节点], icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/free.png"}
- {name: 移动优选节点, type: fallback, use: [🆓 免费订阅], filter: "(?i)(cmcc)", hidden: true, icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/cmcc.png"}
- {name: CF 优选节点, type: fallback, use: [🆓 免费订阅], filter: "(?i)(cfip)", hidden: true, icon: "https://github.com/DustinWin/ruleset_geodata/releases/download/icons/cfip.png"}
```
## 二、 添加以管理员身份运行 Bash 文件的支持
1. 下载安装 [Git for Windows](https://github.com/git-for-windows/git/releases),安装目录默认为 `C:\Program Files\Git`{: .filepath}
2. 编辑文本文档,粘贴如下内容:
```text
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\.sh]
@="sh_auto_file"
[HKEY_CLASSES_ROOT\sh_auto_file\shell\runas\command]
@="\"C:\\Program Files\\Git\\git-bash.exe\" \"%1\""
```
另存为 .reg 文件,双击导入
## 三、 导入 [mihomo 内核](https://github.com/MetaCubeX/mihomo)和配置文件并启动 mihomo
### 1. 导入内核和配置文件
- ① 编辑本文文档,粘贴如下内容:
注:
- ➊ 将《[](https://proxy-tutorials.dustinwin.us.kg/posts/share-windows-mihomo-ruleset/#%E4%B8%80-%E7%94%9F%E6%88%90%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6-yaml-%E6%96%87%E4%BB%B6%E7%9B%B4%E9%93%BE)》中生成的配置文件 .yaml 文件直链替换下面命令中的 `{.yaml 配置文件直链}`
- ➋ 或者删除此条命令,直接进入 `%PROGRAMFILES%\mihomo`{: .filepath} 文件夹,新建 config.yaml 文件并粘贴配置内容
```shell
#!/bin/bash
title="安装、更新 mihomo 内核和配置文件"
while true; do
clear
echo "==============================================="
echo " 安装、更新 mihomo 内核和配置文件 "
echo "==============================================="
echo
echo "1. 安装(更新)mihomo 内核"
echo "2. 导入(更新)配置文件"
echo "3. 启动 mihomo 服务"
echo "4. 停止 mihomo 服务"
echo "0. 退出"
echo "==============================================="
read -p "请选择操作(0-4):" choice
case $choice in
1)
echo "安装(更新)mihomo 内核"
cd "$PROGRAMFILES"
if [ -f "./mihomo/mihomo.exe" ]; then
echo "检测到当前系统已安装 mihomo 内核,是否更新?(Y/n"
while true; do
read -n1 -r choice
case $choice in
[Yy])
echo
echo "正在下载 mihomo 内核..."
curl -sS -o "$USERPROFILE/Downloads/mihomo.exe" -L https://ghfast.top/https://github.com/DustinWin/proxy-tools/releases/download/mihomo/mihomo-meta-windows-amd64-v3.exe
echo "下载 mihomo 内核成功"
echo "正在结束 mihomo 相关进程..."
taskkill //f //t //im "mihomo*"
echo "结束 mihomo 相关进程成功"
echo "正在更新 mihomo 内核..."
mv -f "$USERPROFILE/Downloads/mihomo.exe" ./mihomo
if [ -f "./mihomo/config.yaml" ]; then
echo "更新 mihomo 内核成功,是否启动服务?(Y/n)"
while true; do
read -n1 -r choice
case $choice in
[Yy])
echo
echo "正在启动 mihomo 服务..."
cd ./mihomo
start //min mihomo -d .
read -n1 -r -p "启动 mihomo 服务成功,按任意键返回菜单..."
break
;;
[Nn])
break
;;
*)
echo
echo "无效选择,请重新输入!"
;;
esac
done
break
else
read -n1 -r -p "更新 mihomo 内核成功,请返回菜单导入配置文件!按任意键返回菜单..."
break
fi
;;
[Nn])
break
;;
*)
echo
echo "无效选择,请重新输入!"
;;
esac
done
else
echo "检测到当前系统未安装 mihomo 内核,是否安装?(Y/n"
while true; do
read -n1 -r choice
case $choice in
[Yy])
echo
echo "正在安装 mihomo 内核..."
mkdir -p ./mihomo
curl -sS -o ./mihomo/mihomo.exe -L https://ghfast.top/https://github.com/DustinWin/proxy-tools/releases/download/mihomo/mihomo-meta-windows-amd64-v3.exe
echo "安装 mihomo 内核成功"
echo "正在赋予 mihomo 权限..."
cmd //c "takeown /f mihomo /a /r /d y"
icacls mihomo /inheritance:r
icacls mihomo /remove[:g] "TrustedInstaller"
icacls mihomo /remove[:g] "CREATOR OWNER"
icacls mihomo /remove[:g] "ALL APPLICATION PACKAGES"
icacls mihomo /remove[:g] "所有受限制的应用程序包"
icacls mihomo /grant[:r] "SYSTEM:(OI)(CI)F"
icacls mihomo /grant[:r] "Administrators:(OI)(CI)F"
icacls mihomo /grant[:r] "Users:(OI)(CI)F"
read -n1 -r -p "赋予 mihomo 权限成功,请返回菜单导入配置文件!按任意键返回菜单..."
[Nn])
break
;;
*)
echo
echo "无效选择,请重新输入!"
;;
esac
done
fi
;;
2)
ask_run(){
while true; do
read -n1 -r choice
case $choice in
[Yy])
echo
echo "正在启动 mihomo 服务..."
cd ./mihomo
start //min mihomo -d .
read -n1 -r -p "启动 mihomo 服务成功,按任意键返回菜单..."
break
;;
[Nn])
break
;;
*)
echo
echo "无效选择,请重新输入!"
;;
esac
done
}
echo "导入(更新)mihomo 配置文件"
cd "$PROGRAMFILES"
if [[ -f "./mihomo/mihomo.exe" && -f "./mihomo/config.yaml" ]]; then
echo "检测到 mihomo 配置文件,是否更新?(Y/n"
while true; do
read -n1 -r choice
case $choice in
[Yy])
echo
echo "正在下载 mihomo 配置文件..."
curl -sS -o "$USERPROFILE/Downloads/config.yaml" -L https://ghfast.top/{.yaml 配置文件直链}
echo "下载 mihomo 配置文件成功"
echo "正在结束 mihomo 相关进程..."
taskkill //f //t //im "mihomo*"
echo "结束 mihomo 相关进程成功"
echo "正在更新 mihomo 配置文件..."
mv -f "$USERPROFILE/Downloads/config.yaml" ./mihomo
echo "更新 mihomo 配置文件成功,是否启动服务?(Y/n)"
ask_run
break
;;
[Nn])
break
;;
*)
echo
echo "无效选择,请重新输入!"
;;
esac
done
elif [ ! -f "./mihomo/config.yaml" ]; then
echo "未检测到 mihomo 配置文件,导入配置文件..."
mkdir -p ./mihomo
curl -sS -o "$USERPROFILE/Downloads/config.yaml" -L https://ghfast.top/{.yaml 配置文件直链}
mv -f "$USERPROFILE/Downloads/config.yaml" ./mihomo
echo "导入 mihomo 配置文件成功,是否启动服务?(Y/n)"
ask_run
else
read -n1 -r -p "未检测到 mihomo 内核,请先返回菜单安装内核!按任意键返回菜单..."
fi
;;
3)
echo "正在启动 mihomo 服务..."
cd "$PROGRAMFILES"
if [[ -f "./mihomo/mihomo.exe" && -f "./mihomo/config.yaml" ]]; then
cd "./mihomo"
start //min mihomo -d .
read -n1 -r -p "启动 mihomo 服务成功,按任意键返回菜单..."
else
read -n1 -r -p "未检测到 mihomo 内核和配置文件,请返回菜单安装内核并导入配置文件!按任意键返回菜单..."
fi
;;
4)
echo "正在停止 mihomo 服务..."
taskkill //f //t //im "mihomo*"
read -n1 -r -p "停止 mihomo 服务成功,按任意键返回菜单..."
;;
0)
echo "退出程序"
exit 0
;;
*)
echo "无效选择,请重新输入!"
read -n1 -r -p "按任意键返回菜单..."
;;
esac
done
```
- ② 另存为 .sh 文件,右击并选择“以管理员身份运行”
### 2. 启动 mihomo
- ① 编辑本文文档,粘贴如下内容:
```shell
cd "%PROGRAMFILES%\mihomo"
start /min mihomo -d .
```
- ② 另存为 run.bat 文件并复制到 `%PROGRAMFILES%\mihomo`{: .filepath} 文件夹中
- ③ 右击 run.bat 文件并选择“以管理员身份运行”即可
小窍门:
- ➊ 右击 run.bat 文件并选择“发送到桌面快捷方式”
- ➋ 右击快捷方式并点击“属性” → “高级”,勾选“以管理员身份运行”并“确定”
- ➌ 若想开机启动 mihomo,可搜索“Windows 添加任务计划”教程自行添加
## 四、 访问 Dashboard 面板
打开 [zashboard](https://github.com/Zephyruso/zashboard) 在线面板地址 <http://board.zash.run.place> 可直接访问 Dashboard 面板
> 推荐设置
{: .prompt-tip }
进入 zashboard → 设置 → 后端设置 → 修改后端配置,可设置“标签 (可选)”来快速识别不同设备
+15
View File
@@ -0,0 +1,15 @@
---
title: 打赏和赞助
description: 制作教程不易,给作者加个鸡腿吧~
date: 2025-04-26 13:49:12 +0800
categories: [置顶]
tags: [打赏]
pin: true
---
# 给作者加鸡腿
<img src="/assets/img/pin/alipay.jpg" alt="支付宝" width="30%" />
<img src="/assets/img/pin/wechat.png" alt="微信" width="30%" />
# 机场推荐
[Bitz Net](https://red.bnaffred.com/#/register?code=HT0ALWZq)(仅次于一线机场,推荐打折时购买)