什么是 rule provider、proxy provider?

rule-provider:俗称规则集合,通过它,可以引用不同类型的在线规则集 (URL),clash 就能自动根据访问目标是否在规则集中,然后匹配到对应的规则,从而选择代理/节点或者本地网络进行访问简单地说,rule-provider 能让在线的规则集,下载到本地供我们使用。

proxy-provider:俗称代理集合,通过它,可以提取指定 Clash订阅链接或者本地配置文件中的proxies字段中的所有内容。简单地说,proxy-provider 帮助我们提取订阅链接或者配置文件中所包含的节点信息,到当前配置文件中供我们使用。

特别注意:rule-provider、proxy-provider 适用于 Clash Premium 内核的规则集(RULE-SET),同时适用于所有使用 Clash Premium 内核的 Clash 图形用户界面(GUI)客户端。

 rule-provider、proxy-provider 大致原理

  • proxy-provider:提供节点
  • rule-provider:提供规则集,不同的在线规则集,以 url 链接形式提供,包含常见的域名和IP 地址列表,由项目大佬们实时维护的
  • proxy-groups:以“策略组”为单位,对 proxy-provider 提供的节点或者手动添加的节点进行分组管理
  • rule:引用规则集、策略组,以访问目标是否在规则集中为条件,设定本地网络或者节点对其进行访问

比如:  RULE-SET,telegramcidr,PROXY

  • “RULE-SET”是规则集的意思
  • “telegramcidr” 为规则集的名称
  • “PROXY” 为代理策略组名称

意思就是当访问目标是 telegramcidr 中的IP地址时,就通过 PROXY 策略组中的节点去访问。

示例

proxy-providers:

# 配置规则参考文档: https://github.com/Dreamacro/clash/wiki/configuration
# 设置代理提供者(远程订阅地址+本地订阅文件)
proxy-providers:
foo:
  type: http
  path: ./profiles/proxies/foo.yaml
  url: https://example-url
  interval: 3600
  health-check:
    enable: true
    url: http://www.gstatic.com/generate_204
    interval: 300
bar:
  type: file
  path: ./profiles/proxies/bar.yaml
  health-check:
    enable: true
    url: http://www.gstatic.com/generate_204
    interval: 300

proxy-groups:
- name: PROXY
  type: select
  url: http://www.gstatic.com/generate_204
  interval: 3600
  use:
    - foo
    - bar
  proxies:
    - DIRECT

proxy-providers:俗称代理集合,通过它,可以提取指定 Clash订阅链接或者本地配置文件中的节点信息,到当前配置文件中供我们使用。

简单地说,proxy-providers 帮助我们提取 clash订阅链接或者配置文件中所包含的节点信息

HTTP类型

  • foo 代理集的名称
  • type 为该代理集的类型,简单地说,http 为 clash 订阅链接 ; file 为 本地配置文件
  • path 则是代理集所在的文件路径,“foo” 为保存在本地文件的名字
  • 如果 type 为 http, url 则需要填写 clash 订阅链接、设置自动更新的间隔;然后,可以通过 filter 去筛选出链接中包含“某一个关键词”的所有节点,比如, 我需要 Blinkload 机场的香港节点, 这里输入 “Hong Kong”, 就能实现。多个关键词用英文输入法下 ”|“连接
  • health-check 对代理集所包含的节点,设置自动延迟测试、测试间隔以及目标网站

File 类型

  • 名称为” bar” 的代理集,类型为 file, 即本地配置文件
  • 需要注意的是,需要引用本地配置文件时,文件存放的位置、文件名,一定和“Path”这里保持一致。
  • 本地配置文件在哪里呢?点击”General“回到 CFW 主页,再点“Open Folder”跳转到配置文件所在目录—-“Profiles”。这个时候,你可以主动把 path 的参数都改为与本地配置文件实际的位置和名字一致;或者新建一个Proxies 文件夹,再把配置文件拖动这里并重命名为“ bar”,和默认的 path 设置全部保持一致。
” proxy-groups “ ,可以由一个或者多个策略组组成,不同的策略组可以引用不同代理集
  • name 为策略组的名称,因为PROXY 为默认的策略组,切记,不要去修改这个名称!!不要去修改、不要去修改!!
  • type 策略组的类型,建议使用 url-test,这样子,策略组就会自动选用延迟最低的节点 ,规避掉不能正常使用的节点。
  • url 是节点延迟测试的目标网站,建议保持默认
  • interval 为自动执行“节点延迟测试”的间隔
  • use 为引用 proxy-provider 的指令,填写对应的代理集名称就可以了,这里的“ foo”、“bar”,就是引用 foo,bar 代理集所包含的节点
  • proxies 这里,你可以在这个策略组中的引用单个节点配置;如果使用 openclash 的小伙伴,切记,一定不能删除这里的“DIRECT”,否则,有可能 openclash 就无法正常下载订阅链接中的配置文件,导致无法使用!

此时的 PROXY 策略组,就包含了“ foo和 bar ”代理集中的所有节点,策略组类型为 url-test;当规则使用这个策略组时,就会自动选用延迟最低的节点。

Rule Providers 示例

Rule Providers 可以看到它是由多个在线规则集组成
以 “reject” 规则集为例
–“reject” 为规则集的名称
–它的类型是 http
–规则集类型是 domian 域名
–url 链接是规则集的在线地址,我们可以打开它,它包含很多域名
–path 指定了从URL链接下载后的规则集文件的储存路径、文件名称
–interval 设置自动下载规则集的间隔,86400 秒,即每隔10天会自动下载 URL 包含的规则集文件到本地
# clash-rules项目提供的规则集
rule-providers:
  reject:
    type: http
    behavior: domain
    url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/reject.txt"
    path: ./ruleset/reject.yaml
    interval: 86400
  icloud:
    type: http
    behavior: domain
    url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/icloud.txt"
    path: ./ruleset/icloud.yaml
    interval: 86400
  apple:
    type: http
    behavior: domain
    url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/apple.txt"
    path: ./ruleset/apple.yaml
    interval: 86400
  google:
    type: http
    behavior: domain
    url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/google.txt"
    path: ./ruleset/google.yaml
    interval: 86400
  proxy:
    type: http
    behavior: domain
    url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/proxy.txt"
    path: ./ruleset/proxy.yaml
    interval: 86400
  direct:
    type: http
    behavior: domain
    url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/direct.txt"
    path: ./ruleset/direct.yaml
    interval: 86400
  private:
    type: http
    behavior: domain
    url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/private.txt"
    path: ./ruleset/private.yaml
    interval: 86400
  gfw:
    type: http
    behavior: domain
    url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/gfw.txt"
    path: ./ruleset/gfw.yaml
    interval: 86400
  greatfire:
    type: http
    behavior: domain
    url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/greatfire.txt"
    path: ./ruleset/greatfire.yaml
    interval: 86400
  tld-not-cn:
    type: http
    behavior: domain
    url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/tld-not-cn.txt"
    path: ./ruleset/tld-not-cn.yaml
    interval: 86400
  telegramcidr:
    type: http
    behavior: ipcidr
    url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/telegramcidr.txt"
    path: ./ruleset/telegramcidr.yaml
    interval: 86400
  cncidr:
    type: http
    behavior: ipcidr
    url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/cncidr.txt"
    path: ./ruleset/cncidr.yaml
    interval: 86400
  lancidr:
     type: http
     behavior: ipcidr
     url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/lancidr.txt"
     path: ./ruleset/lancidr.yaml
     interval: 86400

白名单模式 Rules 配置方式(推荐)

  • 白名单模式,意为「没有命中规则的网络流量,统统使用代理」,适用于服务器线路网络质量稳定、快速,不缺服务器流量的用户。
  • 以下配置中,除了 DIRECT 和 REJECT 是默认存在于 Clash 中的 policy(路由策略/流量处理策略),其余均为自定义 policy,对应配置文件中 proxies 或 proxy-groups 中的 name。如你直接使用下面的 rules 规则,则需要在 proxies 或 proxy-groups 中手动配置一个 name 为 PROXY 的 policy。
  • 如你希望 Apple、iCloud 和 Google 列表中的域名使用代理,则把 policy 由 DIRECT 改为 PROXY,以此类推,举一反三。
  • 如你不希望进行 DNS 解析,可在 GEOIP 规则的最后加上 ,no-resolve,如 GEOIP,CN,DIRECT,no-resolve
# “白名单模式”常见模板
rules:
  - RULE-SET,applications,DIRECT
  - DOMAIN,clash.razord.top,DIRECT
  - DOMAIN,yacd.haishan.me,DIRECT
  - RULE-SET,private,DIRECT
  - RULE-SET,reject,REJECT
  - RULE-SET,icloud,DIRECT
  - RULE-SET,apple,DIRECT
  - RULE-SET,google,DIRECT
  - RULE-SET,proxy,PROXY
  - RULE-SET,direct,DIRECT
  - RULE-SET,lancidr,DIRECT
  - RULE-SET,cncidr,DIRECT
  - RULE-SET,telegramcidr,PROXY
  - GEOIP,LAN,DIRECT
  - GEOIP,CN,DIRECT
  - MATCH,PROXY

黑名单模式 Rules 配置方式

  • 黑名单模式,意为「只有命中规则的网络流量,才使用代理」,适用于服务器线路网络质量不稳定或不够快,或服务器流量紧缺的用户。通常也是软路由用户、家庭网关用户的常用模式。
  • 以下配置中,除了 DIRECT 和 REJECT 是默认存在于 Clash 中的 policy(路由策略/流量处理策略),其余均为自定义 policy,对应配置文件中 proxies 或 proxy-groups 中的 name。如你直接使用下面的 rules 规则,则需要在 proxies 或 proxy-groups 中手动配置一个 name 为 PROXY 的 policy。
# “黑名单模式”常见模板
rules:
  - RULE-SET,applications,DIRECT
  - DOMAIN,clash.razord.top,DIRECT
  - DOMAIN,yacd.haishan.me,DIRECT
  - RULE-SET,private,DIRECT
  - RULE-SET,reject,REJECT
  - RULE-SET,tld-not-cn,PROXY
  - RULE-SET,gfw,PROXY
  - RULE-SET,greatfire,PROXY
  - RULE-SET,telegramcidr,PROXY
  - MATCH,DIRECT

配置文件范本基础版(建议新手使用): 点击跳转(备用)

mixed-port: 7890
#---------------------------------------------------#
allow-lan: false
mode: Rule
log-level: silent
external-controller: 127.0.0.1:60000

# 节点配置文件统一存放在 ./profiles/proxies/ 目录中

proxy-providers:
# 从链接导入的配置文件(支持多个Clash 订阅链接)
 foo:
   type: http
   path: ./profiles/proxies/foo.yaml
   url: https://example-url (clash 订阅链接)
   interval: 3600 
   health-check:
     enable: true
     url: http://www.gstatic.com/generate_204
     interval: 300

proxy-groups:
- name: PROXY
  type: url-test
  url: http://www.gstatic.com/generate_204
  interval: 3600
  use: # 引入proxy-provider 使用 use 关键字
   - foo

# clash-rules项目提供的规则集
rule-providers:
  reject:
    type: http
    behavior: domain
    url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/reject.txt"
    path: ./ruleset/reject.yaml
    interval: 86400
  icloud:
    type: http
    behavior: domain
    url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/icloud.txt"
    path: ./ruleset/icloud.yaml
    interval: 86400
  apple:
    type: http
    behavior: domain
    url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/apple.txt"
    path: ./ruleset/apple.yaml
    interval: 86400
  google:
    type: http
    behavior: domain
    url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/google.txt"
    path: ./ruleset/google.yaml
    interval: 86400
  proxy:
    type: http
    behavior: domain
    url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/proxy.txt"
    path: ./ruleset/proxy.yaml
    interval: 86400
  direct:
    type: http
    behavior: domain
    url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/direct.txt"
    path: ./ruleset/direct.yaml
    interval: 86400
  private:
    type: http
    behavior: domain
    url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/private.txt"
    path: ./ruleset/private.yaml
    interval: 86400
  gfw:
    type: http
    behavior: domain
    url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/gfw.txt"
    path: ./ruleset/gfw.yaml
    interval: 86400
  greatfire:
    type: http
    behavior: domain
    url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/greatfire.txt"
    path: ./ruleset/greatfire.yaml
    interval: 86400
  tld-not-cn:
    type: http
    behavior: domain
    url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/tld-not-cn.txt"
    path: ./ruleset/tld-not-cn.yaml
    interval: 86400
  telegramcidr:
    type: http
    behavior: ipcidr
    url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/telegramcidr.txt"
    path: ./ruleset/telegramcidr.yaml
    interval: 86400
  cncidr:
    type: http
    behavior: ipcidr
    url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/cncidr.txt"
    path: ./ruleset/cncidr.yaml
    interval: 86400
  lancidr:
     type: http
     behavior: ipcidr
     url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/lancidr.txt"
     path: ./ruleset/lancidr.yaml
     interval: 86400 
# 分流规则
rules:
- PROCESS-NAME,xray,DIRECT
- PROCESS-NAME,v2ray,DIRECT
- PROCESS-NAME,naive,DIRECT
- PROCESS-NAME,trojan,DIRECT
- PROCESS-NAME,trojan-go,DIRECT
- PROCESS-NAME,ss-local,DIRECT
- PROCESS-NAME,privoxy,DIRECT
- PROCESS-NAME,leaf,DIRECT
- PROCESS-NAME,v2ray.exe,DIRECT
- PROCESS-NAME,xray.exe,DIRECT
- PROCESS-NAME,naive.exe,DIRECT
- PROCESS-NAME,trojan.exe,DIRECT
- PROCESS-NAME,trojan-go.exe,DIRECT
- PROCESS-NAME,ss-local.exe,DIRECT
- PROCESS-NAME,privoxy.exe,DIRECT
- PROCESS-NAME,leaf.exe,DIRECT
- PROCESS-NAME,Surge,DIRECT
- PROCESS-NAME,Surge 2,DIRECT
- PROCESS-NAME,Surge 3,DIRECT
- PROCESS-NAME,Surge 4,DIRECT
- PROCESS-NAME,Surge%202,DIRECT
- PROCESS-NAME,Surge%203,DIRECT
- PROCESS-NAME,Surge%204,DIRECT
- PROCESS-NAME,Thunder,DIRECT
- PROCESS-NAME,DownloadService,DIRECT
- PROCESS-NAME,qBittorrent,DIRECT
- PROCESS-NAME,Transmission,DIRECT
- PROCESS-NAME,fdm,DIRECT
- PROCESS-NAME,aria2c,DIRECT
- PROCESS-NAME,Folx,DIRECT
- PROCESS-NAME,NetTransport,DIRECT
- PROCESS-NAME,uTorrent,DIRECT
- PROCESS-NAME,WebTorrent,DIRECT
- PROCESS-NAME,aria2c.exe,DIRECT
- PROCESS-NAME,BitComet.exe,DIRECT
- PROCESS-NAME,fdm.exe,DIRECT
- PROCESS-NAME,NetTransport.exe,DIRECT
- PROCESS-NAME,qbittorrent.exe,DIRECT
- PROCESS-NAME,Thunder.exe,DIRECT
- PROCESS-NAME,ThunderVIP.exe,DIRECT
- PROCESS-NAME,transmission-daemon.exe,DIRECT
- PROCESS-NAME,transmission-qt.exe,DIRECT
- PROCESS-NAME,uTorrent.exe,DIRECT
- PROCESS-NAME,WebTorrent.exe,DIRECT
- DOMAIN,clash.razord.top,DIRECT
- DOMAIN,yacd.haishan.me,DIRECT
- RULE-SET,private,DIRECT
- RULE-SET,reject,REJECT
- RULE-SET,icloud,DIRECT
- RULE-SET,apple,DIRECT
- RULE-SET,google,DIRECT
- RULE-SET,proxy,PROXY
- RULE-SET,direct,DIRECT
- RULE-SET,telegramcidr,PROXY
- GEOIP,LAN,DIRECT
- GEOIP,CN,DIRECT
  - MATCH,PROXY

配置文件范本进阶版(白名单): 点击跳转(备用)

mixed-port: 7890
#---------------------------------------------------#
allow-lan: false
mode: Rule
log-level: silent
external-controller: 127.0.0.1:60000

# 节点配置文件统一存放在 ./profiles/proxies/ 目录中

proxy-providers:
# 从链接导入的配置文件(支持多个Clash 订阅链接)
 foo:
   type: http
   path: ./profiles/proxies/foo.yaml
   url: https://example-url (clash 订阅链接)
   interval: 3600 
   filter: 'Hong Kong' # 删选出含有该关键词的节点
   health-check:
     enable: true
     url: http://www.gstatic.com/generate_204
     interval: 300

 # 从本地导入的 clash 配置文件
 bar:
   type: file
   path: ./profiles/proxies/bar.yaml
   health-check:
     enable: true
     url: http://www.gstatic.com/generate_204
     interval: 600

proxy-groups:
- name: PROXY
  type: url-test
  url: http://www.gstatic.com/generate_204
  interval: 3600
  use: # 引入proxy-provider 使用 use 关键字
   - foo
   - bar
  proxies:
   - DIRECT

# clash-rules项目提供的规则集
rule-providers:
  reject:
    type: http
    behavior: domain
    url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/reject.txt"
    path: ./ruleset/reject.yaml
    interval: 86400
  icloud:
    type: http
    behavior: domain
    url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/icloud.txt"
    path: ./ruleset/icloud.yaml
    interval: 86400
  apple:
    type: http
    behavior: domain
    url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/apple.txt"
    path: ./ruleset/apple.yaml
    interval: 86400
  google:
    type: http
    behavior: domain
    url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/google.txt"
    path: ./ruleset/google.yaml
    interval: 86400
  proxy:
    type: http
    behavior: domain
    url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/proxy.txt"
    path: ./ruleset/proxy.yaml
    interval: 86400
  direct:
    type: http
    behavior: domain
    url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/direct.txt"
    path: ./ruleset/direct.yaml
    interval: 86400
  private:
    type: http
    behavior: domain
    url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/private.txt"
    path: ./ruleset/private.yaml
    interval: 86400
  gfw:
    type: http
    behavior: domain
    url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/gfw.txt"
    path: ./ruleset/gfw.yaml
    interval: 86400
  greatfire:
    type: http
    behavior: domain
    url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/greatfire.txt"
    path: ./ruleset/greatfire.yaml
    interval: 86400
  tld-not-cn:
    type: http
    behavior: domain
    url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/tld-not-cn.txt"
    path: ./ruleset/tld-not-cn.yaml
    interval: 86400
  telegramcidr:
    type: http
    behavior: ipcidr
    url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/telegramcidr.txt"
    path: ./ruleset/telegramcidr.yaml
    interval: 86400
  cncidr:
    type: http
    behavior: ipcidr
    url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/cncidr.txt"
    path: ./ruleset/cncidr.yaml
    interval: 86400
  lancidr:
     type: http
     behavior: ipcidr
     url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/lancidr.txt"
     path: ./ruleset/lancidr.yaml
     interval: 86400 
# 分流规则
rules:
- PROCESS-NAME,xray,DIRECT
- PROCESS-NAME,v2ray,DIRECT
- PROCESS-NAME,naive,DIRECT
- PROCESS-NAME,trojan,DIRECT
- PROCESS-NAME,trojan-go,DIRECT
- PROCESS-NAME,ss-local,DIRECT
- PROCESS-NAME,privoxy,DIRECT
- PROCESS-NAME,leaf,DIRECT
- PROCESS-NAME,v2ray.exe,DIRECT
- PROCESS-NAME,xray.exe,DIRECT
- PROCESS-NAME,naive.exe,DIRECT
- PROCESS-NAME,trojan.exe,DIRECT
- PROCESS-NAME,trojan-go.exe,DIRECT
- PROCESS-NAME,ss-local.exe,DIRECT
- PROCESS-NAME,privoxy.exe,DIRECT
- PROCESS-NAME,leaf.exe,DIRECT
- PROCESS-NAME,Surge,DIRECT
- PROCESS-NAME,Surge 2,DIRECT
- PROCESS-NAME,Surge 3,DIRECT
- PROCESS-NAME,Surge 4,DIRECT
- PROCESS-NAME,Surge%202,DIRECT
- PROCESS-NAME,Surge%203,DIRECT
- PROCESS-NAME,Surge%204,DIRECT
- PROCESS-NAME,Thunder,DIRECT
- PROCESS-NAME,DownloadService,DIRECT
- PROCESS-NAME,qBittorrent,DIRECT
- PROCESS-NAME,Transmission,DIRECT
- PROCESS-NAME,fdm,DIRECT
- PROCESS-NAME,aria2c,DIRECT
- PROCESS-NAME,Folx,DIRECT
- PROCESS-NAME,NetTransport,DIRECT
- PROCESS-NAME,uTorrent,DIRECT
- PROCESS-NAME,WebTorrent,DIRECT
- PROCESS-NAME,aria2c.exe,DIRECT
- PROCESS-NAME,BitComet.exe,DIRECT
- PROCESS-NAME,fdm.exe,DIRECT
- PROCESS-NAME,NetTransport.exe,DIRECT
- PROCESS-NAME,qbittorrent.exe,DIRECT
- PROCESS-NAME,Thunder.exe,DIRECT
- PROCESS-NAME,ThunderVIP.exe,DIRECT
- PROCESS-NAME,transmission-daemon.exe,DIRECT
- PROCESS-NAME,transmission-qt.exe,DIRECT
- PROCESS-NAME,uTorrent.exe,DIRECT
- PROCESS-NAME,WebTorrent.exe,DIRECT
- DOMAIN,clash.razord.top,DIRECT
- DOMAIN,yacd.haishan.me,DIRECT
- RULE-SET,private,DIRECT
- RULE-SET,reject,REJECT
- RULE-SET,icloud,DIRECT
- RULE-SET,apple,DIRECT
- RULE-SET,google,DIRECT
- RULE-SET,proxy,PROXY
- RULE-SET,direct,DIRECT
- RULE-SET,telegramcidr,PROXY
- GEOIP,LAN,DIRECT
- GEOIP,CN,DIRECT
  - MATCH,PROXY

自用的配置文件进阶版(白名单模式+YouTube+Netflix 分流规则):点击跳转(备用)

mixed-port: 7890
allow-lan: false
mode: Rule
log-level: silent
external-controller: 127.0.0.1:60000
proxy-providers:
BL:
  type: http
  path: ./profiles/proxies/BL.yaml
  url: "https://"
  interval: 3600
  filter: 'Hong Kong'
  health-check:
    enable: true
    url: http://www.gstatic.com/generate_204
    interval: 300
KY:
  type: http
  path: ./profiles/proxies/KY.yaml
  url: "https://"
  interval: 3600
  filter: 'IEPL-香港'
  health-check:
    enable: true
    url: http://www.gstatic.com/generate_204
    interval: 300
BLSG:
  type: http
  path: ./profiles/proxies/BLSG.yaml
  url: "https://"
  interval: 3600
  filter: 'Singapore'
  health-check:
    enable: true
    url: http://www.gstatic.com/generate_204
    interval: 300
proxy-groups:
- name: PROXY
  type: url-test
  url: http://www.gstatic.com/generate_204
  interval: 300
  use:
    - BL
    - KY
  proxies:
    - DIRECT
- name: Netflix
  type: url-test
  url: http://www.gstatic.com/generate_204
    interval: 300
  use:
    - BLSG
- name: Youtube
  type: url-test
  url: http://www.gstatic.com/generate_204
  interval: 300
  use:
      - KY
rule-providers:
  reject:
    type: http
    behavior: domain
    url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/reject.txt"
    path: ./ruleset/reject.yaml
    interval: 86400
  icloud:
    type: http
    behavior: domain
    url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/icloud.txt"
    path: ./ruleset/icloud.yaml
    interval: 86400
  apple:
    type: http
    behavior: domain
    url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/apple.txt"
    path: ./ruleset/apple.yaml
    interval: 86400
  google:
    type: http
    behavior: domain
    url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/google.txt"
    path: ./ruleset/google.yaml
    interval: 86400
  proxy:
    type: http
    behavior: domain
    url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/proxy.txt"
    path: ./ruleset/proxy.yaml
    interval: 86400
  direct:
    type: http
    behavior: domain
    url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/direct.txt"
    path: ./ruleset/direct.yaml
    interval: 86400
  private:
    type: http
    behavior: domain
    url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/private.txt"
    path: ./ruleset/private.yaml
    interval: 86400
  gfw:
    type: http
    behavior: domain
    url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/gfw.txt"
    path: ./ruleset/gfw.yaml
    interval: 86400
  greatfire:
    type: http
    behavior: domain
    url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/greatfire.txt"
    path: ./ruleset/greatfire.yaml
    interval: 86400
  tld-not-cn:
    type: http
    behavior: domain
    url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/tld-not-cn.txt"
    path: ./ruleset/tld-not-cn.yaml
    interval: 86400
  telegramcidr:
    type: http
    behavior: ipcidr
    url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/telegramcidr.txt"
    path: ./ruleset/telegramcidr.yaml
    interval: 86400
  cncidr:
    type: http
    behavior: ipcidr
    url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/cncidr.txt"
    path: ./ruleset/cncidr.yaml
    interval: 86400
  lancidr:
     type: http
     behavior: ipcidr
     url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/lancidr.txt"
     path: ./ruleset/lancidr.yaml
     interval: 86400 
# 分流规则
rules:
- DOMAIN-KEYWORD,youtube,Youtube
- DOMAIN,youtubei.googleapis.com,Youtube
- DOMAIN,yt3.ggpht.com,Youtube
- DOMAIN-SUFFIX,googlevideo.com,Youtube
- DOMAIN-SUFFIX,gvt2.com,Youtube
  - DOMAIN-SUFFIX,withyoutube.com,Youtube
- DOMAIN-SUFFIX,youtu.be,Youtube
- DOMAIN-SUFFIX,youtube-nocookie.com,Youtube
- DOMAIN-SUFFIX,youtube.com,Youtube
- DOMAIN-SUFFIX,youtubeeducation.com,Youtube
- DOMAIN-SUFFIX,youtubegaming.com,Youtube
- DOMAIN-SUFFIX,youtubekids.com,Youtube
- DOMAIN-SUFFIX,yt.be,Youtube
- DOMAIN-SUFFIX,ytimg.com,Youtube
- DOMAIN-KEYWORD,netflixdnstest,Netflix
- DOMAIN,netflix.com.edgesuite.net,Netflix
- DOMAIN-SUFFIX,fast.com,Netflix
- DOMAIN-SUFFIX,netflix.com,Netflix
- DOMAIN-SUFFIX,netflix.net,Netflix
- DOMAIN-SUFFIX,netflixdnstest0.com,Netflix
- DOMAIN-SUFFIX,netflixdnstest1.com,Netflix
- DOMAIN-SUFFIX,netflixdnstest2.com,Netflix
- DOMAIN-SUFFIX,netflixdnstest3.com,Netflix
- DOMAIN-SUFFIX,netflixdnstest4.com,Netflix
- DOMAIN-SUFFIX,netflixdnstest5.com,Netflix
- DOMAIN-SUFFIX,netflixdnstest6.com,Netflix
- DOMAIN-SUFFIX,netflixdnstest7.com,Netflix
- DOMAIN-SUFFIX,netflixdnstest8.com,Netflix
- DOMAIN-SUFFIX,netflixdnstest9.com,Netflix
- DOMAIN-SUFFIX,nflxext.com,Netflix
- DOMAIN-SUFFIX,nflximg.com,Netflix
- DOMAIN-SUFFIX,nflximg.net,Netflix
- DOMAIN-SUFFIX,nflxso.net,Netflix
- DOMAIN-SUFFIX,nflxvideo.net,Netflix
- IP-CIDR,8.41.4.0/24,Netflix,no-resolve
- IP-CIDR,23.246.0.0/18,Netflix,no-resolve
- IP-CIDR,37.77.184.0/21,Netflix,no-resolve
- IP-CIDR,38.72.126.0/24,Netflix,no-resolve
- IP-CIDR,45.57.0.0/17,Netflix,no-resolve
- IP-CIDR,64.120.128.0/17,Netflix,no-resolve
- IP-CIDR,66.197.128.0/17,Netflix,no-resolve
- IP-CIDR,69.53.224.0/19,Netflix,no-resolve
- IP-CIDR,103.87.204.0/22,Netflix,no-resolve
- IP-CIDR,108.175.32.0/20,Netflix,no-resolve
- IP-CIDR,185.2.220.0/22,Netflix,no-resolve
- IP-CIDR,185.9.188.0/22,Netflix,no-resolve
- IP-CIDR,192.173.64.0/18,Netflix,no-resolve
- IP-CIDR,198.38.96.0/19,Netflix,no-resolve
- IP-CIDR,198.45.48.0/20,Netflix,no-resolve
- IP-CIDR,207.45.72.0/22,Netflix,no-resolve
- IP-CIDR,208.75.76.0/22,Netflix,no-resolve
- PROCESS-NAME,v2ray,DIRECT
- PROCESS-NAME,xray,DIRECT
- PROCESS-NAME,naive,DIRECT
- PROCESS-NAME,trojan,DIRECT
- PROCESS-NAME,trojan-go,DIRECT
- PROCESS-NAME,ss-local,DIRECT
- PROCESS-NAME,privoxy,DIRECT
- PROCESS-NAME,leaf,DIRECT
- PROCESS-NAME,v2ray.exe,DIRECT
- PROCESS-NAME,xray.exe,DIRECT
- PROCESS-NAME,naive.exe,DIRECT
- PROCESS-NAME,trojan.exe,DIRECT
- PROCESS-NAME,trojan-go.exe,DIRECT
- PROCESS-NAME,ss-local.exe,DIRECT
- PROCESS-NAME,privoxy.exe,DIRECT
- PROCESS-NAME,leaf.exe,DIRECT
- PROCESS-NAME,Surge,DIRECT
- PROCESS-NAME,Surge 2,DIRECT
- PROCESS-NAME,Surge 3,DIRECT
- PROCESS-NAME,Surge 4,DIRECT
- PROCESS-NAME,Surge%202,DIRECT
- PROCESS-NAME,Surge%203,DIRECT
- PROCESS-NAME,Surge%204,DIRECT
- PROCESS-NAME,Thunder,DIRECT
- PROCESS-NAME,DownloadService,DIRECT
- PROCESS-NAME,qBittorrent,DIRECT
- PROCESS-NAME,Transmission,DIRECT
- PROCESS-NAME,fdm,DIRECT
- PROCESS-NAME,aria2c,DIRECT
- PROCESS-NAME,Folx,DIRECT
- PROCESS-NAME,NetTransport,DIRECT
- PROCESS-NAME,uTorrent,DIRECT
- PROCESS-NAME,WebTorrent,DIRECT
- PROCESS-NAME,aria2c.exe,DIRECT
- PROCESS-NAME,BitComet.exe,DIRECT
- PROCESS-NAME,fdm.exe,DIRECT
- PROCESS-NAME,NetTransport.exe,DIRECT
- PROCESS-NAME,qbittorrent.exe,DIRECT
- PROCESS-NAME,Thunder.exe,DIRECT
- PROCESS-NAME,ThunderVIP.exe,DIRECT
- PROCESS-NAME,transmission-daemon.exe,DIRECT
- PROCESS-NAME,transmission-qt.exe,DIRECT
- PROCESS-NAME,uTorrent.exe,DIRECT
- PROCESS-NAME,WebTorrent.exe,DIRECT
- DOMAIN,clash.razord.top,DIRECT
- DOMAIN,yacd.haishan.me,DIRECT
- RULE-SET,private,DIRECT
- RULE-SET,reject,REJECT
- RULE-SET,icloud,DIRECT
- RULE-SET,apple,DIRECT
- RULE-SET,google,DIRECT
- RULE-SET,proxy,PROXY
- RULE-SET,direct,DIRECT
- RULE-SET,telegramcidr,PROXY
- GEOIP,LAN,DIRECT
- GEOIP,CN,DIRECT
  - MATCH,PROXY

参考资料(不分先后顺序):感谢各位大佬的无私分享

延伸阅读: proxy-provider 如何添加自建节点 

最后修改日期: 21 5 月, 2024

留言

怎么添加自建节点?试了半天,不是错误,就是无法引用

    很简单,把自建节点通过订阅转换链接网站转换成clash 订阅链接就可以了

请问一下 “filter“ 怎么用做排除啊?

    filter 不能做排除

    `filter` 支持正则表达式,排除的语法是: ‘^(?!.*(日本|香港|新加坡|美国)).*’ 把国家换成你要排除的即可

initial proxy provider xxx error: yaml: unmarshal errors: line 1: cannot unmarshal !!str `dm1lc3M…` into provider.ProxySchema 我的服务的 clash 订阅链接好像对内容做了转化,没办法用 type: http的方式把它转化过来。 但是 Clash Pro 的托管配置功能又可以把他转化成 yaml 文件,就很迷茫。 暂时用type: http方式去引用转化好的 yaml 文件。。。 求指教更优雅的方式。

    更正:type: file方式去引用转化好的 yaml 文件。。。

      在m2 macmini上遇到同样的问题。感谢你的用法启发,用file方式引用yaml暂时用起来了。

    对,个人建议去网上找一找clash订阅链接转换网站,转换后,再试试看

    貌似 Clash 不能解析在这里填的链接,只能用 Clash 的配置文件。我的处理方式是在本地用 subconverter 转换,链接就填转换的链接。如果没有什么特别需求的话,链接是 http://127.0.0.1:25500/sub?target=clash&url=订阅链接 缺点是要保持 subconverter 开启。如果觉得它的窗口碍事的话,可以移动到另一个桌面。除此之外,和直接成功用机场给的链接差不多,算是比较优雅的方式了。

    错误提示:initial proxy provider pqjc error: yaml: unmarshal errors: line 1: cannot unmarshal !!str dHJvamF… into provider.ProxySchema 原因:因订阅地址后面 token 一般使用 BASE64 编码,Clash 无法识别 解决方式:订阅地址加 &flag=clash,示例:https://gtoken=82ec7c3&flag=clash

为什么 groups 里面一定得带一个 name 为 PROXY 的,看其它机场节点并没有这样

    那是因为,默认的分流规则,引用了name 为 PROXY的策略组;不建议修改

备忘:proxy-providers Http 的 Path 需要先到指定目录新建好才可以

    不会吧?客户端,应该会自动新建一个文件夹并把对应的http 包含的配置文件下载到该文件夹

proxy-groups: – name: PROXY 这个为什么不能剔除啊

问题反馈: Clash Premium版本:2022.11.25 Premium (14324) 当前版本,rule-providers下的每个RULE-SET项下的path好像是无效了,会自动下载到”C:\Users\\.config\clash\providers\rule”这个目录下,无法更改路径,并且自动以一串哈希值命名,无法自定义文件名(如”gfw.yaml”)。 另,同理,proxy-providers下的每个机场的配置项下的path也无法自定义,被自动下载到”C:\Users\\.config\clash\providers\proxy”目录中,并自动以一串哈希值命名配置文件,而无法自定义文件名(如”BL.yaml”)。

    建议卸载客户端后,重新安装,CFW 有版本更新了配置文件和规则集文件,默认的文件位置

      当我配置里直接使用http会创建一个providers文件夹在里面创建规则&订阅,但是生成的是一串哈希值,当我将http改为file就需要在设置的路径已有对应的文件。请问一下这个可以解决吗?

GrinderLee 

以前一直用的好好的,但是前几个月clash更新一次后到现在 provider一直无法更新,提示clash initial proxy provider file must have a proxies field,找了很多资料找不到原因了

请教一下,如何在proxy-groups里过滤某个proxy-provider的订阅节点?

    `filter` 字段去删选 节点名称;比如说,你想用节点名含有 Singapore 字样, proxy-groups: – name: PROXY type: url-test url: http://www.gstatic.com/generate_204 interval: 300 filter: ‘Singapore’ use: – BL – KY

      卡米猪 

      你好,我用 clash verge 按以下配置,老是报错:proxy group[0]: PROXY ‘🇭🇰 Hong Kong丨01’ not found, 请指导下是什么问题? 配置如下: proxy-providers: sub1: type: http path: ./profiles/proxies/suba.yaml url: https://subaxxxxx.com?token=xxxxx interval: 86400 health-check: enable: true url: http://www.gstatic.com/generate_204 interval: 3600 proxy-groups: – name: PROXY type: select use: – suba proxies: – 🇭🇰 Hong Kong丨01 suba.yaml里面proxies如下(部分内容): proxies: – { name: ‘🇭🇰 Hong Kong丨01’, type: ss, server: xxx, port: ‘16001’, cipher: aes-256-gcm, password: xxx, udp: true } 如下,如果 proxy-groups 里面使用 filter 是没问题的 proxy-groups: – name: PROXY type: select use: – suba filter: ‘🇭🇰’ 我比较疑惑的是,看文档不是说可以直接在 proxy-groups 中制定 proxy-provider 提供的单个 proxies 节点吗?

        不对,请参考以下配置文件。正确的操作不走是: 1.在 proxy-provider 前,单独新建一个 proxies 的代理集 2. 按照clash的节点格式要求,依次添加新节点。 3.在 proxygroups中的 proxies 去依次添加节点名称,以便引用新加的节点。 配置文件范本: mixed-port: 7890 allow-lan: false mode: Rule log-level: silent external-controller: 127.0.0.1:60000 proxies: – name: Hong Kong 01 type: ss server: 107.xxx.xx.xxx port: “1xx8” cipher: aes-256-gcm password: YRQxxxxx – name: Hong Kong 02 type: ss server: 038b8xxxol port: “xxx” cipher: aes-128-gcm password: 3649xxxx udp: true protocol: origin – name: Hong Kong 03 type: ss server: 03xx0.xx.lol port: “4xxx1” cipher: aes-128-gcm password: 364xxxxx udp: true protocol: origin proxy-providers: KY: type: http path: ./profiles/proxies/KY.yaml url: https://api.xxxxx interval: 3600 filter: IEPL-香港 health-check: enable: true url: http://www.youtube.com interval: 300 proxy-groups: – name: PROXY type: select url: http://www.youtube.com interval: 600 use: – KY proxies: – Hong Kong 01 – Hong Kong 02 – Hong Kong 03

请问 proxies下的bar.yaml文件 长什么样子啊,能分享一下吗, 假如我想让 openai.com 固定走美国的节点,这个文件如何编辑

    可以先看看这个直播视频:https://www.youtube.com/live/8OTTEbbA6yI?si=_Z88D0O3NZx6Uel4&t=1341 关于 openai.COM 固定走美国的节点,请参照这个博客:https://jamesdaily.life/clash_2022 ;也可以加入电报群提问:https://bit.ly/tel_j

麻烦问下为什么每个proxy-providers 和 rule-providers 下的 path : 例如: path: ./profiles/proxies/providers1.yml ,最终下载到的节点信息或者规则集信息 保存的文件名称不是provicers1.yml ,而是一串数字.yaml, 但是又不影响使用,这个是怎么回事

    你理解到的文件路径不太正确,准确的是 proxy-providers 和 rule-providers 下的 path,为客户端的配置文件—点击鼠标右键 “ show in folder”–点击文件夹“ proxies ”或“ rules“,你再核对下

cfw 使用rule-provider 、proxy-provider。请问怎么让自行添加的规则覆盖掉在线规则。如bing,在线规则直连,但想要添加条自定义规则,使用代理访问

撰写回覆或留言

发布留言必须填写的电子邮件地址不会公开。