小白也能轻松手搓的 mihomo 分流规则(2025 年)
- 内容介绍
- 文章标签
- 相关推荐
对于小白来说,从零开始手搓配置文件要跨越不低的门槛,此时不妨以 mihomo 官方文档里给出的可以立刻使用的快捷配置为基础进行修改。官方示例里涉及分流的总共有这么三个字段:proxy-groups代理组,rules路由规则,rule-providers规则集合。至于rule-anchor,其实是 yaml 配置文件的特性,用来节省重复填写rule-providers里相同内容的工夫,并缩短配置文件长度。
官方示例里的相关段落
proxies:
- name: "直连"
type: direct
udp: true
proxy-groups:
- name: 默认
type: select
proxies: [自动选择,直连,香港,台湾,日本,新加坡,美国,其它地区,全部节点]
- name: Google
type: select
proxies: [默认,香港,台湾,日本,新加坡,美国,其它地区,全部节点,自动选择,直连]
- name: Telegram
type: select
proxies: [默认,香港,台湾,日本,新加坡,美国,其它地区,全部节点,自动选择,直连]
- name: Twitter
type: select
proxies: [默认,香港,台湾,日本,新加坡,美国,其它地区,全部节点,自动选择,直连]
- name: 哔哩哔哩
type: select
proxies: [默认,香港,台湾,日本,新加坡,美国,其它地区,全部节点,自动选择,直连]
- name: 巴哈姆特
type: select
proxies: [默认,香港,台湾,日本,新加坡,美国,其它地区,全部节点,自动选择,直连]
- name: YouTube
type: select
proxies: [默认,香港,台湾,日本,新加坡,美国,其它地区,全部节点,自动选择,直连]
- name: NETFLIX
type: select
proxies: [默认,香港,台湾,日本,新加坡,美国,其它地区,全部节点,自动选择,直连]
- name: Spotify
type: select
proxies: [默认,香港,台湾,日本,新加坡,美国,其它地区,全部节点,自动选择,直连]
- name: Github
type: select
proxies: [默认,香港,台湾,日本,新加坡,美国,其它地区,全部节点,自动选择,直连]
- name: 国内
type: select
proxies: [直连,默认,香港,台湾,日本,新加坡,美国,其它地区,全部节点,自动选择]
- name: 其他
type: select
proxies: [默认,香港,台湾,日本,新加坡,美国,其它地区,全部节点,自动选择,直连]
#分隔,下面是地区分组
- name: 香港
type: select
include-all: true
exclude-type: direct
filter: "(?i)港|hk|hongkong|hong kong"
- name: 台湾
type: select
include-all: true
exclude-type: direct
filter: "(?i)台|tw|taiwan"
- name: 日本
type: select
include-all: true
exclude-type: direct
filter: "(?i)日|jp|japan"
- name: 美国
type: select
include-all: true
exclude-type: direct
filter: "(?i)美|us|unitedstates|united states"
- name: 新加坡
type: select
include-all: true
exclude-type: direct
filter: "(?i)(新|sg|singapore)"
- name: 其它地区
type: select
include-all: true
exclude-type: direct
filter: "(?i)^(?!.*(?:🇭🇰|🇯🇵|🇺🇸|🇸🇬|🇨🇳|港|hk|hongkong|台|tw|taiwan|日|jp|japan|新|sg|singapore|美|us|unitedstates)).*"
- name: 全部节点
type: select
include-all: true
exclude-type: direct
- name: 自动选择
type: url-test
include-all: true
exclude-type: direct
tolerance: 10
rules:
- RULE-SET,private_ip,直连,no-resolve
- RULE-SET,github_domain,Github
- RULE-SET,twitter_domain,Twitter
- RULE-SET,youtube_domain,YouTube
- RULE-SET,google_domain,Google
- RULE-SET,telegram_domain,Telegram
- RULE-SET,netflix_domain,NETFLIX
- RULE-SET,bilibili_domain,哔哩哔哩
- RULE-SET,bahamut_domain,巴哈姆特
- RULE-SET,spotify_domain,Spotify
- RULE-SET,cn_domain,国内
- RULE-SET,geolocation-!cn,其他
- RULE-SET,google_ip,Google
- RULE-SET,netflix_ip,NETFLIX
- RULE-SET,telegram_ip,Telegram
- RULE-SET,twitter_ip,Twitter
- RULE-SET,cn_ip,国内
- MATCH,其他
rule-anchor:
ip: &ip {type: http, interval: 86400, behavior: ipcidr, format: mrs}
domain: &domain {type: http, interval: 86400, behavior: domain, format: mrs}
rule-providers:
private_domain:
<<: *domain
url: "https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/private.mrs"
cn_domain:
<<: *domain
url: "https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/cn.mrs"
biliintl_domain:
<<: *domain
url: "https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/biliintl.mrs"
ehentai_domain:
<<: *domain
url: "https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/ehentai.mrs"
github_domain:
<<: *domain
url: "https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/github.mrs"
twitter_domain:
<<: *domain
url: "https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/twitter.mrs"
youtube_domain:
<<: *domain
url: "https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/youtube.mrs"
google_domain:
<<: *domain
url: "https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/google.mrs"
telegram_domain:
<<: *domain
url: "https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/telegram.mrs"
netflix_domain:
<<: *domain
url: "https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/netflix.mrs"
bilibili_domain:
<<: *domain
url: "https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/bilibili.mrs"
bahamut_domain:
<<: *domain
url: "https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/bahamut.mrs"
spotify_domain:
<<: *domain
url: "https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/spotify.mrs"
pixiv_domain:
<<: *domain
url: "https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/pixiv.mrs"
geolocation-!cn:
<<: *domain
url: "https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/geolocation-!cn.mrs"
private_ip:
<<: *ip
url: "https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geoip/private.mrs"
cn_ip:
<<: *ip
url: "https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geoip/cn.mrs"
google_ip:
<<: *ip
url: "https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geoip/google.mrs"
netflix_ip:
<<: *ip
url: "https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geoip/netflix.mrs"
twitter_ip:
<<: *ip
url: "https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geoip/twitter.mrs"
telegram_ip:
<<: *ip
url: "https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geoip/telegram.mrs"
多说一句
之所以选取官方的示例,而不是网上其他地方给出的现成分流配置,是因为那些流传数(≥3)年之久的配置,针对的往往是已经删库的旧 Clash 内核,他们的分流实现方式动辄是在配置文件里写出几千上万条分流规则,或是引用一些陈旧的规则集,这种配置文件虽然也能在 mihomo 上跑(因为有向后兼容),但并不是 mihomo 上分流的最优实践。
不要被配置文件里密密麻麻的字吓到,实际上这三个字段的关系很简单:proxy-groups代理组是实现走特定的代理节点去访问特定的某一类网站这个功能(也就是分流)的基础,不同的代理组可选定不同的代理节点;rules路由规则用来定义特定的某一类网站属于哪个代理组;rule-providers规则集合囊括了特定的某一类网站,不同的规则集合代表不同的网站,路由规则通过引用规则集合的内容来发挥作用。
这样听起来还是很抽象,不如直接看官方示例:
proxy-groups:
- name: Google
type: select
proxies: [默认,香港,台湾,日本,新加坡,美国,其它地区,全部节点,自动选择,直连]
- name: 香港
type: select
include-all: true
exclude-type: direct
filter: "(?i)港|hk|hongkong|hong kong"
rules:
- RULE-SET,google_domain,Google
rule-providers:
google_domain:
<<: *domain
url: "https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/google.mrs"
此处proxy-groups代理组里的Google是为了选取特定的代理节点访问谷歌而设置的,它下面列举了proxies: [默认,香港,台湾,日本,新加坡,美国,其它地区,全部节点,自动选择,直连]这些分项,这些分项又对应着其他代理组,如香港这个代理组的用途就是在机场订阅中包含的节点里筛选出香港的节点用来选择。
但是它怎么实现让这个节点去访问谷歌?靠的是rules路由规则里的这条RULE-SET,google_domain,Google,其中RULE-SET代表这条路由规则引用了规则集(ruleset),google_domain是这个规则集的名字,Google是它对应的代理组的名字。
那google_domain规则集从何而来?它是在rule-providers规则集合里定义的,包括名字、锚点<<: *domain(因为这是一个域名规则集,所以使用rule-anchor里对应域名规则集的参数),网址。
只要看到这里明白了,那么不管是一条规则还是十条规则,都照猫画虎去写即可,接下来就说分流规则的推荐写法。
再多说一句
官方文档里列举了多种路由规则,其中也有GEOSITE、GEOIP规则,可以直接用geosite和geoip文件(需要在配置文件里引入)里的类别来写分流规则,但此处为什么不采用,是因为加载完整 Geosite 和 GeoIP 文件占用的内存更大,且匹配效率不如mrs二进制规则集文件,这是 mihomo 区别于 Clash 内核的新特性。在更激进的代理工具 sing-box 那里,GeoX 路由规则已经被移除了。
路由规则的优先级是从上到下顺序匹配(这点很重要!),一个良好的rules路由规则应该长这样:
rules:
私有域名和IP(如在本地访问路由器后台)必须放在最上面
- RULE-SET,private,直连
- RULE-SET,private_ip,直连,no-resolve
私有域名和IP部分结束
需要分流的域名(以下为举例)
- RULE-SET,youtube,YouTube
- RULE-SET,google,Google
- RULE-SET,microsoft@cn,国内
- RULE-SET,github,Github
- RULE-SET,microsoft,Microsoft
- RULE-SET,telegram,Telegram
- RULE-SET,twitter,Twitter
- RULE-SET,ai-!cn,国外AI
- RULE-SET,netflix,NETFLIX
- RULE-SET,game-platforms-download@cn,国内
- RULE-SET,games-!cn@cn,国内
需要分流的域名部分结束
国内域名直连
- RULE-SET,cn,国内
国内域名直连部分结束
国外域名兜底分流
- RULE-SET,geolocation-!cn,其他
国外域名兜底分流部分结束
IP地址分流规则放在域名分流规则之后(以下为举例)
- RULE-SET,telegram_ip,Telegram
- RULE-SET,twitter_ip,Twitter
- RULE-SET,netflix_ip,NETFLIX
- RULE-SET,google_ip,Google
IP地址分流规则部分结束
国内IP直连
- RULE-SET,cn_ip,国内
国内IP直连部分结束
未命中上面任何分流规则的真·兜底规则
- MATCH,其他
分流规则彻底结束
与这个分流规则相匹配的代理组和规则集合部分应该长这样:
proxy-groups:
- name: 默认
type: select
proxies: [自动选择,直连,香港,台湾,日本,新加坡,美国,其它地区,全部节点]
- name: YouTube
type: select
proxies: [默认,香港,台湾,日本,新加坡,美国,其它地区,全部节点,自动选择,直连]
- name: Google
type: select
proxies: [默认,香港,台湾,日本,新加坡,美国,其它地区,全部节点,自动选择,直连]
- name: Github
type: select
proxies: [默认,香港,台湾,日本,新加坡,美国,其它地区,全部节点,自动选择,直连]
- name: Microsoft
type: select
proxies: [默认,香港,台湾,日本,新加坡,美国,其它地区,全部节点,自动选择,直连]
- name: Telegram
type: select
proxies: [默认,香港,台湾,日本,新加坡,美国,其它地区,全部节点,自动选择,直连]
- name: Twitter
type: select
proxies: [默认,香港,台湾,日本,新加坡,美国,其它地区,全部节点,自动选择,直连]
- name: 国外AI
type: select
proxies: [默认,香港,台湾,日本,新加坡,美国,其它地区,全部节点,自动选择,直连]
- name: NETFLIX
type: select
proxies: [默认,香港,台湾,日本,新加坡,美国,其它地区,全部节点,自动选择,直连]
- name: 国内
type: select
proxies: [直连,默认,香港,台湾,日本,新加坡,美国,其它地区,全部节点,自动选择]
- name: 其他
type: select
proxies: [默认,香港,台湾,日本,新加坡,美国,其它地区,全部节点,自动选择,直连]
下面这些可以直接照搬官方示例
- name: 香港
type: select
include-all: true
exclude-type: direct
filter: (?i)港|hk|hongkong|hong kong
- name: 台湾
type: select
include-all: true
exclude-type: direct
filter: (?i)台|tw|taiwan
- name: 日本
type: select
include-all: true
exclude-type: direct
filter: (?i)日|jp|japan
- name: 美国
type: select
include-all: true
exclude-type: direct
filter: (?i)美|us|unitedstates|united states
- name: 新加坡
type: select
include-all: true
exclude-type: direct
filter: (?i)(新|sg|singapore)
- name: 其它地区
type: select
include-all: true
exclude-type: direct
filter: (?i)^(?!.*(?:🇭🇰|🇯🇵|🇺🇸|🇸🇬|🇨🇳|港|hk|hongkong|hong kong|台|tw|taiwan|日|jp|japan|新|sg|singapore|美|us|unitedstates)).*
- name: 全部节点
type: select
include-all: true
exclude-type: direct
- name: 自动选择
type: url-test
include-all: true
exclude-type: direct
tolerance: 10
rule-anchor:
ip: &ip {type: http, interval: 86400, behavior: ipcidr, format: mrs}
domain: &domain {type: http, interval: 86400, behavior: domain, format: mrs}
rule-providers:
private:
<<: *domain
url: https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/private.mrs
youtube:
<<: *domain
url: https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/youtube.mrs
google:
<<: *domain
url: https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/google.mrs
microsoft@cn:
<<: *domain
url: https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/microsoft@cn.mrs
github:
<<: *domain
url: https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/github.mrs
microsoft:
<<: *domain
url: https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/microsoft.mrs
telegram:
<<: *domain
url: https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/telegram.mrs
twitter:
<<: *domain
url: https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/twitter.mrs
ai-!cn:
<<: *domain
url: https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/category-ai-!cn.mrs
netflix:
<<: *domain
url: https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/netflix.mrs
game-platforms-download@cn:
<<: *domain
url: https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/category-game-platforms-download@cn.mrs
games-!cn@cn:
<<: *domain
url: https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/category-games-!cn@cn.mrs
cn:
<<: *domain
url: https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/cn.mrs
geolocation-!cn:
<<: *domain
url: https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/geolocation-!cn.mrs
private_ip:
<<: *ip
url: https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geoip/private.mrs
telegram_ip:
<<: *ip
url: https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geoip/telegram.mrs
twitter_ip:
<<: *ip
url: https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geoip/twitter.mrs
netflix_ip:
<<: *ip
url: https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geoip/netflix.mrs
google_ip:
<<: *ip
url: https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geoip/google.mrs
cn_ip:
<<: *ip
url: https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geoip/cn.mrs
以我随手手搓的这个例子来说明写分流规则时的几个提示:
- 私有域名放最上面是为了最优先匹配,
private_ip加上no-resolve确保非私有域名不会在这一步被解析成 IP 地址去进行毫无意义的匹配。 - mihomo 官方提供的规则集合有 yaml、list、mrs 三种文件格式。其中 mrs 是匹配速度最快的二进制文件,被用在配置文件里;list 是文本文件,可以点开这个文本文件看到那个规则集里包含哪些内容。正因为规则集里都是前人已经整理好的规则,所以直接引用规则集就可以省去自己重复发明轮子的痛苦。
- mihomo 官方规则集是在 Loyalsoldier 的 V2Ray 路由规则文件加强版基础上转换而来,而后者又是从 v2fly 官方的 Domain list community 基础上构建,因此 mihomo 的 geosite 规则集里包含的类别和网站基本与原始的 Domain list community 一样。这样一来,如果想查找某个网站属于哪个规则集,可以直接在 Domain list community 仓库里搜索。如果会用 Visual Studio Code,可以把这个仓库下载到本地去搜索,速度会更快。
- 由于路由规则的优先级是从上到下顺序匹配,所以当你想分流的某一类网站包含在一个更大的规则集里时,一定要注意规则先后顺序,如上面
RULE-SET,youtube,YouTube在RULE-SET,google,Google之前,因为google规则集里包含了youtube规则集里的域名(访问 domain-list-community/data/google at master · v2fly/domain-list-community · GitHub 会看到里面写着include:youtube),如果将RULE-SET,google,Google放在RULE-SET,youtube,YouTube之前,就会导致访问油管时走Google代理组设置的节点,而不是YouTube代理组设置的节点。同理,RULE-SET,github,Github放在了RULE-SET,microsoft,Microsoft之前。 - 域名规则集合里名字带
@cn的规则集,如microsoft@cn,代表它是从一个更大的集合(此处是microsoft)里筛选出的在中国有接入点、可以从中国直连的网站(意味着这些网站有直连加速或没被墙),因此RULE-SET,microsoft@cn,国内这条规则放在RULE-SET,microsoft,Microsoft之前,就可以让这部分从中国能直连的微软网站走直连,而不必消耗代理流量。同理,category-game-platforms-download@cn代表这些游戏平台的下载网址可以从中国直连。 - 名字带
!cn的规则集,如category-ai-!cn,代表它是从一个更大的集合(此处是category-ai)里筛选出的不在中国的网站。因此,使用RULE-SET,ai-!cn,国外AI这条规则就可以只让国外的 AI 网站走代理,不会影响国内的 AI 网站。 - 名字带
-!cn@cn的规则集,如category-games-!cn@cn,代表它是既不在中国又有中国接入点、可以从中国直连的网站,当然也要让它走直连。 - IP 地址分流规则之所以要放在域名分流规则之后,是因为如果顺序反过来,那么 mihomo 为了查看一个网址是否符合 IP 地址分流规则,就需要先在本地解析出这个网址的 IP,白白浪费时间。反之,域名规则在 IP 规则之前,只要 mihomo 一看到这个域名需要走代理,根本不会在本地解析它,直接就用代理连接了。
总之,以上已经给出了一个例子,只要根据自己的需要增减条目,就可以打造出适合自己的个性化分流规则文件,别人预制的分流规则里密密麻麻的分组并不见得符合你的需求。
另一篇帖子:
mihomo 内核极简防 DNS 泄漏配置(2025 年)2.0 版 开发调优经过上个帖子的讨论,对初始版本进行了优化,这次给出完整的dns配置,可直接用于覆写。 版本 1(适用于最新版 mihomo 内核) dns: enable: true ipv6: true #如网络环境不支持IPv6请设为false enhanced-mode: fake-ip fake-ip-range: 198.18.0.1/16 fake-ip-filter:…网友解答:
--【壹】--: - name: 香港 type: select include-all: true exclude-type: direct filter: (?i)港|hk|hongkong|hong kong - name: 台湾 type: select include-all: true exclude-type: direct filter: (?i)台|tw|taiwan - name: 日本 type: select include-all: true exclude-type: direct filter: (?i)日|jp|japan - name: 美国 type: select include-all: true exclude-type: direct filter: (?i)美|us|unitedstates|united states - name: 新加坡 type: select include-all: true exclude-type: direct filter: (?i)(新|sg|singapore) - name: 其它地区 type: select include-all: true exclude-type: direct filter: (?i)^(?!.*(?:🇭🇰|🇯🇵|🇺🇸|🇸🇬|🇨🇳|港|hk|hongkong|hong kong|台|tw|taiwan|日|jp|japan|新|sg|singapore|美|us|unitedstates)).* - name: 全部节点 type: select include-all: true exclude-type: direct - name: 自动选择 type: url-test include-all: true exclude-type: direct tolerance: 10 rule-anchor: ip: &ip {type: http, interval: 86400, behavior: ipcidr, format: mrs} domain: &domain {type: http, interval: 86400, behavior: domain, format: mrs} rule-providers: private: <<: *domain url: https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/private.mrs youtube: <<: *domain url: https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/youtube.mrs google: <<: *domain url: https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/google.mrs microsoft@cn: <<: *domain url: https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/microsoft@cn.mrs github: <<: *domain url: https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/github.mrs microsoft: <<: *domain url: https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/microsoft.mrs telegram: <<: *domain url: https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/telegram.mrs twitter: <<: *domain url: https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/twitter.mrs ai-!cn: <<: *domain url: https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/category-ai-!cn.mrs netflix: <<: *domain url: https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/netflix.mrs game-platforms-download@cn: <<: *domain url: https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/category-game-platforms-download@cn.mrs games-!cn@cn: <<: *domain url: https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/category-games-!cn@cn.mrs cn: <<: *domain url: https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/cn.mrs geolocation-!cn: <<: *domain url: https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/geolocation-!cn.mrs private_ip: <<: *ip url: https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geoip/private.mrs telegram_ip: <<: *ip url: https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geoip/telegram.mrs twitter_ip: <<: *ip url: https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geoip/twitter.mrs netflix_ip: <<: *ip url: https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geoip/netflix.mrs google_ip: <<: *ip url: https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geoip/google.mrs cn_ip: <<: *ip url: https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geoip/cn.mrs
以我随手手搓的这个例子来说明写分流规则时的几个提示:
- 私有域名放最上面是为了最优先匹配,
private_ip加上no-resolve确保非私有域名不会在这一步被解析成 IP 地址去进行毫无意义的匹配。 - mihomo 官方提供的规则集合有 yaml、list、mrs 三种文件格式。其中 mrs 是匹配速度最快的二进制文件,被用在配置文件里;list 是文本文件,可以点开这个文本文件看到那个规则集里包含哪些内容。正因为规则集里都是前人已经整理好的规则,所以直接引用规则集就可以省去自己重复发明轮子的痛苦。
- mihomo 官方规则集是在 Loyalsoldier 的 V2Ray 路由规则文件加强版基础上转换而来,而后者又是从 v2fly 官方的 Domain list community 基础上构建,因此 mihomo 的 geosite 规则集里包含的类别和网站基本与原始的 Domain list community 一样。这样一来,如果想查找某个网站属于哪个规则集,可以直接在 Domain list community 仓库里搜索。如果会用 Visual Studio Code,可以把这个仓库下载到本地去搜索,速度会更快。
- 由于路由规则的优先级是从上到下顺序匹配,所以当你想分流的某一类网站包含在一个更大的规则集里时,一定要注意规则先后顺序,如上面
RULE-SET,youtube,YouTube在RULE-SET,google,Google之前,因为google规则集里包含了youtube规则集里的域名(访问 domain-list-community/data/google at master · v2fly/domain-list-community · GitHub 会看到里面写着include:youtube),如果将RULE-SET,google,Google放在RULE-SET,youtube,YouTube之前,就会导致访问油管时走Google代理组设置的节点,而不是YouTube代理组设置的节点。同理,RULE-SET,github,Github放在了RULE-SET,microsoft,Microsoft之前。 - 域名规则集合里名字带
@cn的规则集,如microsoft@cn,代表它是从一个更大的集合(此处是microsoft)里筛选出的在中国有接入点、可以从中国直连的网站(意味着这些网站有直连加速或没被墙),因此RULE-SET,microsoft@cn,国内这条规则放在RULE-SET,microsoft,Microsoft之前,就可以让这部分从中国能直连的微软网站走直连,而不必消耗代理流量。同理,category-game-platforms-download@cn代表这些游戏平台的下载网址可以从中国直连。 - 名字带
!cn的规则集,如category-ai-!cn,代表它是从一个更大的集合(此处是category-ai)里筛选出的不在中国的网站。因此,使用RULE-SET,ai-!cn,国外AI这条规则就可以只让国外的 AI 网站走代理,不会影响国内的 AI 网站。 - 名字带
-!cn@cn的规则集,如category-games-!cn@cn,代表它是既不在中国又有中国接入点、可以从中国直连的网站,当然也要让它走直连。 - IP 地址分流规则之所以要放在域名分流规则之后,是因为如果顺序反过来,那么 mihomo 为了查看一个网址是否符合 IP 地址分流规则,就需要先在本地解析出这个网址的 IP,白白浪费时间。反之,域名规则在 IP 规则之前,只要 mihomo 一看到这个域名需要走代理,根本不会在本地解析它,直接就用代理连接了。
总之,以上已经给出了一个例子,只要根据自己的需要增减条目,就可以打造出适合自己的个性化分流规则文件,别人预制的分流规则里密密麻麻的分组并不见得符合你的需求。
另一篇帖子:
mihomo 内核极简防 DNS 泄漏配置(2025 年)2.0 版 开发调优经过上个帖子的讨论,对初始版本进行了优化,这次给出完整的dns配置,可直接用于覆写。 版本 1(适用于最新版 mihomo 内核) dns: enable: true ipv6: true #如网络环境不支持IPv6请设为false enhanced-mode: fake-ip fake-ip-range: 198.18.0.1/16 fake-ip-filter:…
--【贰】--: 需要分流的域名部分结束
--【叁】--:
感谢分享
--【肆】--: 分流规则彻底结束
--【伍】--:
感谢大佬
--【陆】--: - RULE-SET,cn_ip,国内
--【柒】--: IP地址分流规则放在域名分流规则之后(以下为举例)
--【捌】--: 国外域名兜底分流部分结束
--【玖】--:
[!note] 马
--【拾】--:
自己有份用了一段时间的配置,最近也是着手修改,才发现原来那份配置细究起来简直不忍直视 一大堆小bug,最后也是在GPT大人的指导下改的比较完善了
--【拾壹】--:
优秀!学习了,佬友
--【拾贰】--: - RULE-SET,geolocation-!cn,其他
--【拾叁】--: - MATCH,其他
--【拾肆】--: 国内域名直连部分结束
--【拾伍】--:
能用GEOIP和GEOSITE就不要用RULE-SET了,匹配速度要快一些;未必非要改成mrs格式,如果geodata有的话直接在规则里写就可以了,不需要额外下载
qddlw2bi.gs31433×227 18.9 KB
--【拾陆】--: - RULE-SET,cn,国内
--【拾柒】--:
二进制文件匹配速度快于文本,不怕麻烦可以更换。
--【拾捌】--: - RULE-SET,private,直连 - RULE-SET,private_ip,直连,no-resolve
--【拾玖】--:
感觉这更像是一种物理内存和实时内存上的取舍吧,geox主流的客户端本身就会下载,在现代CPU下geo和mrs差距微乎其微,二者都是二进制的。使用geo的话整个配置看起来清爽太多了,我之前一个个配的时候整个文件有1.5K行,现在精简到了1K行,这对于不需要深入研究的人来说无疑是更便利的,需要什么规则只需要加一行- GEOSITE,类别名,策略即可
--【贰拾】--:
感谢分享,说的很详细呃
【21】 IP地址分流规则部分结束
【22】
感谢分享!!!!!!更新了!
【23】 需要分流的域名(以下为举例)
【24】 未命中上面任何分流规则的真·兜底规则
【25】
与这个分流规则相匹配的代理组和规则集合部分应该长这样:
感谢分享 谢谢分享 不是这样。GeoIP 和 Geosite 的问题是一旦要使用他们就需要加载整个文件(即使 mihomo 内核默认开启低内存加载器 另外 GeoX 文件确实需要在配置文件里引入(如官方示例的另一个版本所示,配置文件里包含 感谢分享 个人还是不太习惯用这两个,我尝试两种方式都用一段时间 我只想分跟国内和国外,不管分流,然后能添加白名单或者黑名单这种应该怎样设置? 规则顺序真的很重要,我之前把yaml格式的cn域名和ip规则放在最前面,体感上访问某宝等国内网站慢了不少,之后对比官方示例修改排序,不知道是否是心理作用,感觉快了不少。现在用老版本内核,请问佬友有必要换成mrs格式吗 相当详细 好的,我查查现在用的版本是否支持proxy-groups:
- name: 默认
type: select
proxies: [自动选择,直连,香港,台湾,日本,新加坡,美国,其它地区,全部节点]
- name: YouTube
type: select
proxies: [默认,香港,台湾,日本,新加坡,美国,其它地区,全部节点,自动选择,直连]
- name: Google
type: select
proxies: [默认,香港,台湾,日本,新加坡,美国,其它地区,全部节点,自动选择,直连]
- name: Github
type: select
proxies: [默认,香港,台湾,日本,新加坡,美国,其它地区,全部节点,自动选择,直连]
- name: Microsoft
type: select
proxies: [默认,香港,台湾,日本,新加坡,美国,其它地区,全部节点,自动选择,直连]
- name: Telegram
type: select
proxies: [默认,香港,台湾,日本,新加坡,美国,其它地区,全部节点,自动选择,直连]
- name: Twitter
type: select
proxies: [默认,香港,台湾,日本,新加坡,美国,其它地区,全部节点,自动选择,直连]
- name: 国外AI
type: select
proxies: [默认,香港,台湾,日本,新加坡,美国,其它地区,全部节点,自动选择,直连]
- name: NETFLIX
type: select
proxies: [默认,香港,台湾,日本,新加坡,美国,其它地区,全部节点,自动选择,直连]
- name: 国内
type: select
proxies: [直连,默认,香港,台湾,日本,新加坡,美国,其它地区,全部节点,自动选择]
- name: 其他
type: select
proxies: [默认,香港,台湾,日本,新加坡,美国,其它地区,全部节点,自动选择,直连]
【26】
下面这些可以直接照搬官方示例
【27】
- RULE-SET,telegram_ip,Telegram
- RULE-SET,twitter_ip,Twitter
- RULE-SET,netflix_ip,NETFLIX
- RULE-SET,google_ip,Google
【28】
【29】
【30】
geodata-loader: memconservative),而截至目前 Loyalsoldier 的 geoip.dat 文件已经膨胀到了 20 MB,geosite.dat 文件膨胀到了 9 MB,长期来看使用这种文件的效率会越来越低。虽然 mihomo 官方推出了优化版的 geoip-lite.dat 和 geosite-lite.dat,但在匹配效率上依然不及 mrs 二进制文件。geox-url字段),只不过很多图形客户端(包括 Sparkle)都默认加载这种必要的外部资源,所以用户才显得不需要额外下载。
【31】
【32】
私有域名和IP部分结束
【33】
私有域名和IP(如在本地访问路由器后台)必须放在最上面
【34】
【35】
【36】
【37】
国内IP直连部分结束
【38】
【39】
国外域名兜底分流
【40】
国内IP直连
【41】
【42】
- RULE-SET,youtube,YouTube
- RULE-SET,google,Google
- RULE-SET,microsoft@cn,国内
- RULE-SET,github,Github
- RULE-SET,microsoft,Microsoft
- RULE-SET,telegram,Telegram
- RULE-SET,twitter,Twitter
- RULE-SET,ai-!cn,国外AI
- RULE-SET,netflix,NETFLIX
- RULE-SET,game-platforms-download@cn,国内
- RULE-SET,games-!cn@cn,国内
【43】
国内域名直连
对于小白来说,从零开始手搓配置文件要跨越不低的门槛,此时不妨以 mihomo 官方文档里给出的可以立刻使用的快捷配置为基础进行修改。官方示例里涉及分流的总共有这么三个字段:proxy-groups代理组,rules路由规则,rule-providers规则集合。至于rule-anchor,其实是 yaml 配置文件的特性,用来节省重复填写rule-providers里相同内容的工夫,并缩短配置文件长度。
官方示例里的相关段落
proxies:
- name: "直连"
type: direct
udp: true
proxy-groups:
- name: 默认
type: select
proxies: [自动选择,直连,香港,台湾,日本,新加坡,美国,其它地区,全部节点]
- name: Google
type: select
proxies: [默认,香港,台湾,日本,新加坡,美国,其它地区,全部节点,自动选择,直连]
- name: Telegram
type: select
proxies: [默认,香港,台湾,日本,新加坡,美国,其它地区,全部节点,自动选择,直连]
- name: Twitter
type: select
proxies: [默认,香港,台湾,日本,新加坡,美国,其它地区,全部节点,自动选择,直连]
- name: 哔哩哔哩
type: select
proxies: [默认,香港,台湾,日本,新加坡,美国,其它地区,全部节点,自动选择,直连]
- name: 巴哈姆特
type: select
proxies: [默认,香港,台湾,日本,新加坡,美国,其它地区,全部节点,自动选择,直连]
- name: YouTube
type: select
proxies: [默认,香港,台湾,日本,新加坡,美国,其它地区,全部节点,自动选择,直连]
- name: NETFLIX
type: select
proxies: [默认,香港,台湾,日本,新加坡,美国,其它地区,全部节点,自动选择,直连]
- name: Spotify
type: select
proxies: [默认,香港,台湾,日本,新加坡,美国,其它地区,全部节点,自动选择,直连]
- name: Github
type: select
proxies: [默认,香港,台湾,日本,新加坡,美国,其它地区,全部节点,自动选择,直连]
- name: 国内
type: select
proxies: [直连,默认,香港,台湾,日本,新加坡,美国,其它地区,全部节点,自动选择]
- name: 其他
type: select
proxies: [默认,香港,台湾,日本,新加坡,美国,其它地区,全部节点,自动选择,直连]
#分隔,下面是地区分组
- name: 香港
type: select
include-all: true
exclude-type: direct
filter: "(?i)港|hk|hongkong|hong kong"
- name: 台湾
type: select
include-all: true
exclude-type: direct
filter: "(?i)台|tw|taiwan"
- name: 日本
type: select
include-all: true
exclude-type: direct
filter: "(?i)日|jp|japan"
- name: 美国
type: select
include-all: true
exclude-type: direct
filter: "(?i)美|us|unitedstates|united states"
- name: 新加坡
type: select
include-all: true
exclude-type: direct
filter: "(?i)(新|sg|singapore)"
- name: 其它地区
type: select
include-all: true
exclude-type: direct
filter: "(?i)^(?!.*(?:🇭🇰|🇯🇵|🇺🇸|🇸🇬|🇨🇳|港|hk|hongkong|台|tw|taiwan|日|jp|japan|新|sg|singapore|美|us|unitedstates)).*"
- name: 全部节点
type: select
include-all: true
exclude-type: direct
- name: 自动选择
type: url-test
include-all: true
exclude-type: direct
tolerance: 10
rules:
- RULE-SET,private_ip,直连,no-resolve
- RULE-SET,github_domain,Github
- RULE-SET,twitter_domain,Twitter
- RULE-SET,youtube_domain,YouTube
- RULE-SET,google_domain,Google
- RULE-SET,telegram_domain,Telegram
- RULE-SET,netflix_domain,NETFLIX
- RULE-SET,bilibili_domain,哔哩哔哩
- RULE-SET,bahamut_domain,巴哈姆特
- RULE-SET,spotify_domain,Spotify
- RULE-SET,cn_domain,国内
- RULE-SET,geolocation-!cn,其他
- RULE-SET,google_ip,Google
- RULE-SET,netflix_ip,NETFLIX
- RULE-SET,telegram_ip,Telegram
- RULE-SET,twitter_ip,Twitter
- RULE-SET,cn_ip,国内
- MATCH,其他
rule-anchor:
ip: &ip {type: http, interval: 86400, behavior: ipcidr, format: mrs}
domain: &domain {type: http, interval: 86400, behavior: domain, format: mrs}
rule-providers:
private_domain:
<<: *domain
url: "https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/private.mrs"
cn_domain:
<<: *domain
url: "https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/cn.mrs"
biliintl_domain:
<<: *domain
url: "https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/biliintl.mrs"
ehentai_domain:
<<: *domain
url: "https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/ehentai.mrs"
github_domain:
<<: *domain
url: "https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/github.mrs"
twitter_domain:
<<: *domain
url: "https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/twitter.mrs"
youtube_domain:
<<: *domain
url: "https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/youtube.mrs"
google_domain:
<<: *domain
url: "https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/google.mrs"
telegram_domain:
<<: *domain
url: "https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/telegram.mrs"
netflix_domain:
<<: *domain
url: "https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/netflix.mrs"
bilibili_domain:
<<: *domain
url: "https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/bilibili.mrs"
bahamut_domain:
<<: *domain
url: "https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/bahamut.mrs"
spotify_domain:
<<: *domain
url: "https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/spotify.mrs"
pixiv_domain:
<<: *domain
url: "https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/pixiv.mrs"
geolocation-!cn:
<<: *domain
url: "https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/geolocation-!cn.mrs"
private_ip:
<<: *ip
url: "https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geoip/private.mrs"
cn_ip:
<<: *ip
url: "https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geoip/cn.mrs"
google_ip:
<<: *ip
url: "https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geoip/google.mrs"
netflix_ip:
<<: *ip
url: "https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geoip/netflix.mrs"
twitter_ip:
<<: *ip
url: "https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geoip/twitter.mrs"
telegram_ip:
<<: *ip
url: "https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geoip/telegram.mrs"
多说一句
之所以选取官方的示例,而不是网上其他地方给出的现成分流配置,是因为那些流传数(≥3)年之久的配置,针对的往往是已经删库的旧 Clash 内核,他们的分流实现方式动辄是在配置文件里写出几千上万条分流规则,或是引用一些陈旧的规则集,这种配置文件虽然也能在 mihomo 上跑(因为有向后兼容),但并不是 mihomo 上分流的最优实践。
不要被配置文件里密密麻麻的字吓到,实际上这三个字段的关系很简单:proxy-groups代理组是实现走特定的代理节点去访问特定的某一类网站这个功能(也就是分流)的基础,不同的代理组可选定不同的代理节点;rules路由规则用来定义特定的某一类网站属于哪个代理组;rule-providers规则集合囊括了特定的某一类网站,不同的规则集合代表不同的网站,路由规则通过引用规则集合的内容来发挥作用。
这样听起来还是很抽象,不如直接看官方示例:
proxy-groups:
- name: Google
type: select
proxies: [默认,香港,台湾,日本,新加坡,美国,其它地区,全部节点,自动选择,直连]
- name: 香港
type: select
include-all: true
exclude-type: direct
filter: "(?i)港|hk|hongkong|hong kong"
rules:
- RULE-SET,google_domain,Google
rule-providers:
google_domain:
<<: *domain
url: "https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/google.mrs"
此处proxy-groups代理组里的Google是为了选取特定的代理节点访问谷歌而设置的,它下面列举了proxies: [默认,香港,台湾,日本,新加坡,美国,其它地区,全部节点,自动选择,直连]这些分项,这些分项又对应着其他代理组,如香港这个代理组的用途就是在机场订阅中包含的节点里筛选出香港的节点用来选择。
但是它怎么实现让这个节点去访问谷歌?靠的是rules路由规则里的这条RULE-SET,google_domain,Google,其中RULE-SET代表这条路由规则引用了规则集(ruleset),google_domain是这个规则集的名字,Google是它对应的代理组的名字。
那google_domain规则集从何而来?它是在rule-providers规则集合里定义的,包括名字、锚点<<: *domain(因为这是一个域名规则集,所以使用rule-anchor里对应域名规则集的参数),网址。
只要看到这里明白了,那么不管是一条规则还是十条规则,都照猫画虎去写即可,接下来就说分流规则的推荐写法。
再多说一句
官方文档里列举了多种路由规则,其中也有GEOSITE、GEOIP规则,可以直接用geosite和geoip文件(需要在配置文件里引入)里的类别来写分流规则,但此处为什么不采用,是因为加载完整 Geosite 和 GeoIP 文件占用的内存更大,且匹配效率不如mrs二进制规则集文件,这是 mihomo 区别于 Clash 内核的新特性。在更激进的代理工具 sing-box 那里,GeoX 路由规则已经被移除了。
路由规则的优先级是从上到下顺序匹配(这点很重要!),一个良好的rules路由规则应该长这样:
rules:
私有域名和IP(如在本地访问路由器后台)必须放在最上面
- RULE-SET,private,直连
- RULE-SET,private_ip,直连,no-resolve
私有域名和IP部分结束
需要分流的域名(以下为举例)
- RULE-SET,youtube,YouTube
- RULE-SET,google,Google
- RULE-SET,microsoft@cn,国内
- RULE-SET,github,Github
- RULE-SET,microsoft,Microsoft
- RULE-SET,telegram,Telegram
- RULE-SET,twitter,Twitter
- RULE-SET,ai-!cn,国外AI
- RULE-SET,netflix,NETFLIX
- RULE-SET,game-platforms-download@cn,国内
- RULE-SET,games-!cn@cn,国内
需要分流的域名部分结束
国内域名直连
- RULE-SET,cn,国内
国内域名直连部分结束
国外域名兜底分流
- RULE-SET,geolocation-!cn,其他
国外域名兜底分流部分结束
IP地址分流规则放在域名分流规则之后(以下为举例)
- RULE-SET,telegram_ip,Telegram
- RULE-SET,twitter_ip,Twitter
- RULE-SET,netflix_ip,NETFLIX
- RULE-SET,google_ip,Google
IP地址分流规则部分结束
国内IP直连
- RULE-SET,cn_ip,国内
国内IP直连部分结束
未命中上面任何分流规则的真·兜底规则
- MATCH,其他
分流规则彻底结束
与这个分流规则相匹配的代理组和规则集合部分应该长这样:
proxy-groups:
- name: 默认
type: select
proxies: [自动选择,直连,香港,台湾,日本,新加坡,美国,其它地区,全部节点]
- name: YouTube
type: select
proxies: [默认,香港,台湾,日本,新加坡,美国,其它地区,全部节点,自动选择,直连]
- name: Google
type: select
proxies: [默认,香港,台湾,日本,新加坡,美国,其它地区,全部节点,自动选择,直连]
- name: Github
type: select
proxies: [默认,香港,台湾,日本,新加坡,美国,其它地区,全部节点,自动选择,直连]
- name: Microsoft
type: select
proxies: [默认,香港,台湾,日本,新加坡,美国,其它地区,全部节点,自动选择,直连]
- name: Telegram
type: select
proxies: [默认,香港,台湾,日本,新加坡,美国,其它地区,全部节点,自动选择,直连]
- name: Twitter
type: select
proxies: [默认,香港,台湾,日本,新加坡,美国,其它地区,全部节点,自动选择,直连]
- name: 国外AI
type: select
proxies: [默认,香港,台湾,日本,新加坡,美国,其它地区,全部节点,自动选择,直连]
- name: NETFLIX
type: select
proxies: [默认,香港,台湾,日本,新加坡,美国,其它地区,全部节点,自动选择,直连]
- name: 国内
type: select
proxies: [直连,默认,香港,台湾,日本,新加坡,美国,其它地区,全部节点,自动选择]
- name: 其他
type: select
proxies: [默认,香港,台湾,日本,新加坡,美国,其它地区,全部节点,自动选择,直连]
下面这些可以直接照搬官方示例
- name: 香港
type: select
include-all: true
exclude-type: direct
filter: (?i)港|hk|hongkong|hong kong
- name: 台湾
type: select
include-all: true
exclude-type: direct
filter: (?i)台|tw|taiwan
- name: 日本
type: select
include-all: true
exclude-type: direct
filter: (?i)日|jp|japan
- name: 美国
type: select
include-all: true
exclude-type: direct
filter: (?i)美|us|unitedstates|united states
- name: 新加坡
type: select
include-all: true
exclude-type: direct
filter: (?i)(新|sg|singapore)
- name: 其它地区
type: select
include-all: true
exclude-type: direct
filter: (?i)^(?!.*(?:🇭🇰|🇯🇵|🇺🇸|🇸🇬|🇨🇳|港|hk|hongkong|hong kong|台|tw|taiwan|日|jp|japan|新|sg|singapore|美|us|unitedstates)).*
- name: 全部节点
type: select
include-all: true
exclude-type: direct
- name: 自动选择
type: url-test
include-all: true
exclude-type: direct
tolerance: 10
rule-anchor:
ip: &ip {type: http, interval: 86400, behavior: ipcidr, format: mrs}
domain: &domain {type: http, interval: 86400, behavior: domain, format: mrs}
rule-providers:
private:
<<: *domain
url: https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/private.mrs
youtube:
<<: *domain
url: https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/youtube.mrs
google:
<<: *domain
url: https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/google.mrs
microsoft@cn:
<<: *domain
url: https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/microsoft@cn.mrs
github:
<<: *domain
url: https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/github.mrs
microsoft:
<<: *domain
url: https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/microsoft.mrs
telegram:
<<: *domain
url: https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/telegram.mrs
twitter:
<<: *domain
url: https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/twitter.mrs
ai-!cn:
<<: *domain
url: https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/category-ai-!cn.mrs
netflix:
<<: *domain
url: https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/netflix.mrs
game-platforms-download@cn:
<<: *domain
url: https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/category-game-platforms-download@cn.mrs
games-!cn@cn:
<<: *domain
url: https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/category-games-!cn@cn.mrs
cn:
<<: *domain
url: https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/cn.mrs
geolocation-!cn:
<<: *domain
url: https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/geolocation-!cn.mrs
private_ip:
<<: *ip
url: https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geoip/private.mrs
telegram_ip:
<<: *ip
url: https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geoip/telegram.mrs
twitter_ip:
<<: *ip
url: https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geoip/twitter.mrs
netflix_ip:
<<: *ip
url: https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geoip/netflix.mrs
google_ip:
<<: *ip
url: https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geoip/google.mrs
cn_ip:
<<: *ip
url: https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geoip/cn.mrs
以我随手手搓的这个例子来说明写分流规则时的几个提示:
- 私有域名放最上面是为了最优先匹配,
private_ip加上no-resolve确保非私有域名不会在这一步被解析成 IP 地址去进行毫无意义的匹配。 - mihomo 官方提供的规则集合有 yaml、list、mrs 三种文件格式。其中 mrs 是匹配速度最快的二进制文件,被用在配置文件里;list 是文本文件,可以点开这个文本文件看到那个规则集里包含哪些内容。正因为规则集里都是前人已经整理好的规则,所以直接引用规则集就可以省去自己重复发明轮子的痛苦。
- mihomo 官方规则集是在 Loyalsoldier 的 V2Ray 路由规则文件加强版基础上转换而来,而后者又是从 v2fly 官方的 Domain list community 基础上构建,因此 mihomo 的 geosite 规则集里包含的类别和网站基本与原始的 Domain list community 一样。这样一来,如果想查找某个网站属于哪个规则集,可以直接在 Domain list community 仓库里搜索。如果会用 Visual Studio Code,可以把这个仓库下载到本地去搜索,速度会更快。
- 由于路由规则的优先级是从上到下顺序匹配,所以当你想分流的某一类网站包含在一个更大的规则集里时,一定要注意规则先后顺序,如上面
RULE-SET,youtube,YouTube在RULE-SET,google,Google之前,因为google规则集里包含了youtube规则集里的域名(访问 domain-list-community/data/google at master · v2fly/domain-list-community · GitHub 会看到里面写着include:youtube),如果将RULE-SET,google,Google放在RULE-SET,youtube,YouTube之前,就会导致访问油管时走Google代理组设置的节点,而不是YouTube代理组设置的节点。同理,RULE-SET,github,Github放在了RULE-SET,microsoft,Microsoft之前。 - 域名规则集合里名字带
@cn的规则集,如microsoft@cn,代表它是从一个更大的集合(此处是microsoft)里筛选出的在中国有接入点、可以从中国直连的网站(意味着这些网站有直连加速或没被墙),因此RULE-SET,microsoft@cn,国内这条规则放在RULE-SET,microsoft,Microsoft之前,就可以让这部分从中国能直连的微软网站走直连,而不必消耗代理流量。同理,category-game-platforms-download@cn代表这些游戏平台的下载网址可以从中国直连。 - 名字带
!cn的规则集,如category-ai-!cn,代表它是从一个更大的集合(此处是category-ai)里筛选出的不在中国的网站。因此,使用RULE-SET,ai-!cn,国外AI这条规则就可以只让国外的 AI 网站走代理,不会影响国内的 AI 网站。 - 名字带
-!cn@cn的规则集,如category-games-!cn@cn,代表它是既不在中国又有中国接入点、可以从中国直连的网站,当然也要让它走直连。 - IP 地址分流规则之所以要放在域名分流规则之后,是因为如果顺序反过来,那么 mihomo 为了查看一个网址是否符合 IP 地址分流规则,就需要先在本地解析出这个网址的 IP,白白浪费时间。反之,域名规则在 IP 规则之前,只要 mihomo 一看到这个域名需要走代理,根本不会在本地解析它,直接就用代理连接了。
总之,以上已经给出了一个例子,只要根据自己的需要增减条目,就可以打造出适合自己的个性化分流规则文件,别人预制的分流规则里密密麻麻的分组并不见得符合你的需求。
另一篇帖子:
mihomo 内核极简防 DNS 泄漏配置(2025 年)2.0 版 开发调优经过上个帖子的讨论,对初始版本进行了优化,这次给出完整的dns配置,可直接用于覆写。 版本 1(适用于最新版 mihomo 内核) dns: enable: true ipv6: true #如网络环境不支持IPv6请设为false enhanced-mode: fake-ip fake-ip-range: 198.18.0.1/16 fake-ip-filter:…网友解答:
--【壹】--: - name: 香港 type: select include-all: true exclude-type: direct filter: (?i)港|hk|hongkong|hong kong - name: 台湾 type: select include-all: true exclude-type: direct filter: (?i)台|tw|taiwan - name: 日本 type: select include-all: true exclude-type: direct filter: (?i)日|jp|japan - name: 美国 type: select include-all: true exclude-type: direct filter: (?i)美|us|unitedstates|united states - name: 新加坡 type: select include-all: true exclude-type: direct filter: (?i)(新|sg|singapore) - name: 其它地区 type: select include-all: true exclude-type: direct filter: (?i)^(?!.*(?:🇭🇰|🇯🇵|🇺🇸|🇸🇬|🇨🇳|港|hk|hongkong|hong kong|台|tw|taiwan|日|jp|japan|新|sg|singapore|美|us|unitedstates)).* - name: 全部节点 type: select include-all: true exclude-type: direct - name: 自动选择 type: url-test include-all: true exclude-type: direct tolerance: 10 rule-anchor: ip: &ip {type: http, interval: 86400, behavior: ipcidr, format: mrs} domain: &domain {type: http, interval: 86400, behavior: domain, format: mrs} rule-providers: private: <<: *domain url: https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/private.mrs youtube: <<: *domain url: https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/youtube.mrs google: <<: *domain url: https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/google.mrs microsoft@cn: <<: *domain url: https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/microsoft@cn.mrs github: <<: *domain url: https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/github.mrs microsoft: <<: *domain url: https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/microsoft.mrs telegram: <<: *domain url: https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/telegram.mrs twitter: <<: *domain url: https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/twitter.mrs ai-!cn: <<: *domain url: https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/category-ai-!cn.mrs netflix: <<: *domain url: https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/netflix.mrs game-platforms-download@cn: <<: *domain url: https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/category-game-platforms-download@cn.mrs games-!cn@cn: <<: *domain url: https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/category-games-!cn@cn.mrs cn: <<: *domain url: https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/cn.mrs geolocation-!cn: <<: *domain url: https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/geolocation-!cn.mrs private_ip: <<: *ip url: https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geoip/private.mrs telegram_ip: <<: *ip url: https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geoip/telegram.mrs twitter_ip: <<: *ip url: https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geoip/twitter.mrs netflix_ip: <<: *ip url: https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geoip/netflix.mrs google_ip: <<: *ip url: https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geoip/google.mrs cn_ip: <<: *ip url: https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geoip/cn.mrs
以我随手手搓的这个例子来说明写分流规则时的几个提示:
- 私有域名放最上面是为了最优先匹配,
private_ip加上no-resolve确保非私有域名不会在这一步被解析成 IP 地址去进行毫无意义的匹配。 - mihomo 官方提供的规则集合有 yaml、list、mrs 三种文件格式。其中 mrs 是匹配速度最快的二进制文件,被用在配置文件里;list 是文本文件,可以点开这个文本文件看到那个规则集里包含哪些内容。正因为规则集里都是前人已经整理好的规则,所以直接引用规则集就可以省去自己重复发明轮子的痛苦。
- mihomo 官方规则集是在 Loyalsoldier 的 V2Ray 路由规则文件加强版基础上转换而来,而后者又是从 v2fly 官方的 Domain list community 基础上构建,因此 mihomo 的 geosite 规则集里包含的类别和网站基本与原始的 Domain list community 一样。这样一来,如果想查找某个网站属于哪个规则集,可以直接在 Domain list community 仓库里搜索。如果会用 Visual Studio Code,可以把这个仓库下载到本地去搜索,速度会更快。
- 由于路由规则的优先级是从上到下顺序匹配,所以当你想分流的某一类网站包含在一个更大的规则集里时,一定要注意规则先后顺序,如上面
RULE-SET,youtube,YouTube在RULE-SET,google,Google之前,因为google规则集里包含了youtube规则集里的域名(访问 domain-list-community/data/google at master · v2fly/domain-list-community · GitHub 会看到里面写着include:youtube),如果将RULE-SET,google,Google放在RULE-SET,youtube,YouTube之前,就会导致访问油管时走Google代理组设置的节点,而不是YouTube代理组设置的节点。同理,RULE-SET,github,Github放在了RULE-SET,microsoft,Microsoft之前。 - 域名规则集合里名字带
@cn的规则集,如microsoft@cn,代表它是从一个更大的集合(此处是microsoft)里筛选出的在中国有接入点、可以从中国直连的网站(意味着这些网站有直连加速或没被墙),因此RULE-SET,microsoft@cn,国内这条规则放在RULE-SET,microsoft,Microsoft之前,就可以让这部分从中国能直连的微软网站走直连,而不必消耗代理流量。同理,category-game-platforms-download@cn代表这些游戏平台的下载网址可以从中国直连。 - 名字带
!cn的规则集,如category-ai-!cn,代表它是从一个更大的集合(此处是category-ai)里筛选出的不在中国的网站。因此,使用RULE-SET,ai-!cn,国外AI这条规则就可以只让国外的 AI 网站走代理,不会影响国内的 AI 网站。 - 名字带
-!cn@cn的规则集,如category-games-!cn@cn,代表它是既不在中国又有中国接入点、可以从中国直连的网站,当然也要让它走直连。 - IP 地址分流规则之所以要放在域名分流规则之后,是因为如果顺序反过来,那么 mihomo 为了查看一个网址是否符合 IP 地址分流规则,就需要先在本地解析出这个网址的 IP,白白浪费时间。反之,域名规则在 IP 规则之前,只要 mihomo 一看到这个域名需要走代理,根本不会在本地解析它,直接就用代理连接了。
总之,以上已经给出了一个例子,只要根据自己的需要增减条目,就可以打造出适合自己的个性化分流规则文件,别人预制的分流规则里密密麻麻的分组并不见得符合你的需求。
另一篇帖子:
mihomo 内核极简防 DNS 泄漏配置(2025 年)2.0 版 开发调优经过上个帖子的讨论,对初始版本进行了优化,这次给出完整的dns配置,可直接用于覆写。 版本 1(适用于最新版 mihomo 内核) dns: enable: true ipv6: true #如网络环境不支持IPv6请设为false enhanced-mode: fake-ip fake-ip-range: 198.18.0.1/16 fake-ip-filter:…
--【贰】--: 需要分流的域名部分结束
--【叁】--:
感谢分享
--【肆】--: 分流规则彻底结束
--【伍】--:
感谢大佬
--【陆】--: - RULE-SET,cn_ip,国内
--【柒】--: IP地址分流规则放在域名分流规则之后(以下为举例)
--【捌】--: 国外域名兜底分流部分结束
--【玖】--:
[!note] 马
--【拾】--:
自己有份用了一段时间的配置,最近也是着手修改,才发现原来那份配置细究起来简直不忍直视 一大堆小bug,最后也是在GPT大人的指导下改的比较完善了
--【拾壹】--:
优秀!学习了,佬友
--【拾贰】--: - RULE-SET,geolocation-!cn,其他
--【拾叁】--: - MATCH,其他
--【拾肆】--: 国内域名直连部分结束
--【拾伍】--:
能用GEOIP和GEOSITE就不要用RULE-SET了,匹配速度要快一些;未必非要改成mrs格式,如果geodata有的话直接在规则里写就可以了,不需要额外下载
qddlw2bi.gs31433×227 18.9 KB
--【拾陆】--: - RULE-SET,cn,国内
--【拾柒】--:
二进制文件匹配速度快于文本,不怕麻烦可以更换。
--【拾捌】--: - RULE-SET,private,直连 - RULE-SET,private_ip,直连,no-resolve
--【拾玖】--:
感觉这更像是一种物理内存和实时内存上的取舍吧,geox主流的客户端本身就会下载,在现代CPU下geo和mrs差距微乎其微,二者都是二进制的。使用geo的话整个配置看起来清爽太多了,我之前一个个配的时候整个文件有1.5K行,现在精简到了1K行,这对于不需要深入研究的人来说无疑是更便利的,需要什么规则只需要加一行- GEOSITE,类别名,策略即可
--【贰拾】--:
感谢分享,说的很详细呃
【21】 IP地址分流规则部分结束
【22】
感谢分享!!!!!!更新了!
【23】 需要分流的域名(以下为举例)
【24】 未命中上面任何分流规则的真·兜底规则
【25】
与这个分流规则相匹配的代理组和规则集合部分应该长这样:
感谢分享 谢谢分享 不是这样。GeoIP 和 Geosite 的问题是一旦要使用他们就需要加载整个文件(即使 mihomo 内核默认开启低内存加载器 另外 GeoX 文件确实需要在配置文件里引入(如官方示例的另一个版本所示,配置文件里包含 感谢分享 个人还是不太习惯用这两个,我尝试两种方式都用一段时间 我只想分跟国内和国外,不管分流,然后能添加白名单或者黑名单这种应该怎样设置? 规则顺序真的很重要,我之前把yaml格式的cn域名和ip规则放在最前面,体感上访问某宝等国内网站慢了不少,之后对比官方示例修改排序,不知道是否是心理作用,感觉快了不少。现在用老版本内核,请问佬友有必要换成mrs格式吗 相当详细 好的,我查查现在用的版本是否支持proxy-groups:
- name: 默认
type: select
proxies: [自动选择,直连,香港,台湾,日本,新加坡,美国,其它地区,全部节点]
- name: YouTube
type: select
proxies: [默认,香港,台湾,日本,新加坡,美国,其它地区,全部节点,自动选择,直连]
- name: Google
type: select
proxies: [默认,香港,台湾,日本,新加坡,美国,其它地区,全部节点,自动选择,直连]
- name: Github
type: select
proxies: [默认,香港,台湾,日本,新加坡,美国,其它地区,全部节点,自动选择,直连]
- name: Microsoft
type: select
proxies: [默认,香港,台湾,日本,新加坡,美国,其它地区,全部节点,自动选择,直连]
- name: Telegram
type: select
proxies: [默认,香港,台湾,日本,新加坡,美国,其它地区,全部节点,自动选择,直连]
- name: Twitter
type: select
proxies: [默认,香港,台湾,日本,新加坡,美国,其它地区,全部节点,自动选择,直连]
- name: 国外AI
type: select
proxies: [默认,香港,台湾,日本,新加坡,美国,其它地区,全部节点,自动选择,直连]
- name: NETFLIX
type: select
proxies: [默认,香港,台湾,日本,新加坡,美国,其它地区,全部节点,自动选择,直连]
- name: 国内
type: select
proxies: [直连,默认,香港,台湾,日本,新加坡,美国,其它地区,全部节点,自动选择]
- name: 其他
type: select
proxies: [默认,香港,台湾,日本,新加坡,美国,其它地区,全部节点,自动选择,直连]
【26】
下面这些可以直接照搬官方示例
【27】
- RULE-SET,telegram_ip,Telegram
- RULE-SET,twitter_ip,Twitter
- RULE-SET,netflix_ip,NETFLIX
- RULE-SET,google_ip,Google
【28】
【29】
【30】
geodata-loader: memconservative),而截至目前 Loyalsoldier 的 geoip.dat 文件已经膨胀到了 20 MB,geosite.dat 文件膨胀到了 9 MB,长期来看使用这种文件的效率会越来越低。虽然 mihomo 官方推出了优化版的 geoip-lite.dat 和 geosite-lite.dat,但在匹配效率上依然不及 mrs 二进制文件。geox-url字段),只不过很多图形客户端(包括 Sparkle)都默认加载这种必要的外部资源,所以用户才显得不需要额外下载。
【31】
【32】
私有域名和IP部分结束
【33】
私有域名和IP(如在本地访问路由器后台)必须放在最上面
【34】
【35】
【36】
【37】
国内IP直连部分结束
【38】
【39】
国外域名兜底分流
【40】
国内IP直连
【41】
【42】
- RULE-SET,youtube,YouTube
- RULE-SET,google,Google
- RULE-SET,microsoft@cn,国内
- RULE-SET,github,Github
- RULE-SET,microsoft,Microsoft
- RULE-SET,telegram,Telegram
- RULE-SET,twitter,Twitter
- RULE-SET,ai-!cn,国外AI
- RULE-SET,netflix,NETFLIX
- RULE-SET,game-platforms-download@cn,国内
- RULE-SET,games-!cn@cn,国内
【43】
国内域名直连

