Files
tvbox_collect/_posts/2024-08-21-share-android-mihomo-ruleset.md
2026-07-28 00:58:55 +00:00

368 lines
19 KiB
Markdown

---
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.cc.cd/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: 198.18.0.0/15
fake-ip-range6: fc00::/16
fake-ip-filter-mode: rule
fake-ip-filter:
- RULE-SET,private,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,real-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:
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`,未知域名在匹配 `RULE-SET:cnip` 规则时会由国外 DNS 解析且配置 `ecs`,解析出 IP 在国内则走 `国内 IP` 规则,否则走 `漏网之鱼` 规则(有效解决了“心理 DNS 泄露问题”,详见《[搭载 mihomo 内核配置 DNS 不泄露教程-ruleset 方案](https://proxy-tutorials.dustinwin.cc.cd/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: 198.18.0.0/15
fake-ip-range6: fc00::/16
fake-ip-filter-mode: rule
fake-ip-filter:
- RULE-SET,private,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,real-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: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.cc.cd/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)