目录
最近发现使用香港代理访问new bing貌似被封禁了,于是就要修改一下家里软路由的代理分流规则,因为手上的主力机是MacBook,好用的代理软件最常用的也是Clash X,那索性就一起搞了,正好有小伙伴问我想自定义Clash的分流规则,网上查了资料改是改了,结果一更新订阅链接,自己的辛辛苦亏写的配置就被无情的覆盖了,问我怎么避免这个问题。那就借此机会简单整理一个硬核一点的教程吧。
很多同学看到一大坨的配置文件就头疼,其实大可不必,Clash的配置文件非常简单,简单理解基本规则后就属于有手就能配的。
开始之前简单理解一下几个基本概念。
1.代理(proxy)
代理一般代理指的是我们的代理服务节点,比如自建或者机场提供的可以访问“互联网”的节点。
1.1 代理集(proxy-providers)
如果你购买了机场,那么一般机场都会提供给你一堆的代理节点,此时我们就可以对这些节点按照一定的规则进行归类,这些个归类后的节点称之为代理集(proxy-providers)。
proxy-providers:
FlyingBird-HongKong:
type: http
path: ./ProxySet/FlyingBird/HongKong.yaml
url: "机场订阅地址"
interval: 1800
filter: 'Hong Kong'
health-check:
enable: true
url: http://www.gstatic.com/generate_204
interval: 300
FlyingBird-TaiWan:
type: http
path: ./ProxySet/FlyingBird/TaiWan.yaml
url: "机场订阅地址"
interval: 1800
filter: 'Taiwan'
health-check:
enable: true
url: http://www.gstatic.com/generate_204
interval: 300
代理集中归类的节点可以是本地配置节点也可以是机场订阅节点,可以是一个机场亦或者是多个机场,甚至也可以是符合自定义筛选规则的部分节点。
我们可以为代理集配置健康检查,定时检查并更新代理集中的代理节点。
1.2 策略组(proxy-groups)
策略组这个名字有点让人望而却步,个人认为译为“代理组”会更好理解一点。策略组的作用就是对代理集进行自由组合使用,当然它还提供了定时测速选择最优节点或者手动选择节点等功能。
proxy-groups:
- name: PROXY
type: url-test
url: http://www.gstatic.com/generate_204
interval: 300
use:
- FlyingBird-HongKong
- FlyingBird-TaiWan
- FlyingBird-Singapore
- FlyingBird-Malaysia
- FlyingBird-Japan
- FlyingBird-USA
- FlyingBird-UK
- FlyingBird-Turkey
- FlyingBird-Argentina
proxies:
- DIRECT
- name: 非香港
type: url-test
url: http://www.gstatic.com/generate_204
interval: 300
use:
- FlyingBird-TaiWan
- FlyingBird-Singapore
- FlyingBird-Malaysia
- FlyingBird-Japan
- FlyingBird-USA
- FlyingBird-UK
2.规则(rules)
规则决定了访问指定地址时使用哪个代理,也就是我们说的分流规则。
2.1 规则集(rule-providers)
规则负责将指定网络请求丢给指定的的代理去处理,仿佛左手请求,右手代理。那么首先要确定的就是网络请求,网络请求的界定既可以是一个特定的域名或者IP,也可以是特定域名结尾或者开头,亦或者是进程名称。我们一般将一组特定相关的请求归类到一起,称为规则集。这些规则往往都是爱好者们整理好开源在Github上并定期维护的,我们直接拿来用就可以了。
rule-providers:
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
2.2 规则(rules)
最后我们来看下代理如何分流。一行分流策略包含两部分,请求+代理。请求可以来自于规则集匹配,代理则可以来自于策略组。没有匹配到规则的网路请求如果使用代理访问则称为白名单模式,直接请求不经过代理则是黑名单模式。
我们自定义的分流策略也一般定义在此处。
3.示例配置文件
#---------------------------------------------------#
## 自定义Clash配置
## 作者: Colin Chang
## 更新:2023-04-13
#---------------------------------------------------#
mixed-port: 7890
allow-lan: false
mode: Rule
log-level: error
external-controller: 127.0.0.1:60000
proxy-providers:
FlyingBird-HongKong:
type: http
path: ./ProxySet/FlyingBird/HongKong.yaml
url: "机场订阅地址"
interval: 1800
filter: 'Hong Kong'
health-check:
enable: true
url: http://www.gstatic.com/generate_204
interval: 300
FlyingBird-TaiWan:
type: http
path: ./ProxySet/FlyingBird/TaiWan.yaml
url: "机场订阅地址"
interval: 1800
filter: 'Taiwan'
health-check:
enable: true
url: http://www.gstatic.com/generate_204
interval: 300
FlyingBird-Singapore:
type: http
path: ./ProxySet/FlyingBird/Singapore.yaml
url: "机场订阅地址"
interval: 1800
filter: 'Singapore'
health-check:
enable: true
url: http://www.gstatic.com/generate_204
interval: 300
FlyingBird-Malaysia:
type: http
path: ./ProxySet/FlyingBird/Malaysia.yaml
url: "机场订阅地址"
interval: 1800
filter: 'Malaysia'
health-check:
enable: true
url: http://www.gstatic.com/generate_204
interval: 300
FlyingBird-Japan:
type: http
path: ./ProxySet/FlyingBird/Japan.yaml
url: "机场订阅地址"
interval: 1800
filter: 'Japan'
health-check:
enable: true
url: http://www.gstatic.com/generate_204
interval: 300
FlyingBird-USA:
type: http
path: ./ProxySet/FlyingBird/USA.yaml
url: "机场订阅地址"
interval: 1800
filter: 'USA'
health-check:
enable: true
url: http://www.gstatic.com/generate_204
interval: 300
FlyingBird-UK:
type: http
path: ./ProxySet/FlyingBird/USA.yaml
url: "机场订阅地址"
interval: 1800
filter: 'USA'
health-check:
enable: true
url: http://www.gstatic.com/generate_204
interval: 300
FlyingBird-Turkey:
type: http
path: ./ProxySet/FlyingBird/Turkey.yaml
url: "机场订阅地址"
interval: 1800
filter: 'Turkey'
health-check:
enable: true
url: http://www.gstatic.com/generate_204
interval: 300
FlyingBird-Argentina:
type: http
path: ./ProxySet/FlyingBird/Argentina.yaml
url: "机场订阅地址"
interval: 1800
filter: 'Argentina'
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:
- FlyingBird-HongKong
- FlyingBird-TaiWan
- FlyingBird-Singapore
- FlyingBird-Malaysia
- FlyingBird-Japan
- FlyingBird-USA
- FlyingBird-UK
- FlyingBird-Turkey
- FlyingBird-Argentina
proxies:
- 直接连接
- name: 境外流量
type: url-test
url: http://www.gstatic.com/generate_204
interval: 300
use:
- FlyingBird-HongKong
- FlyingBird-TaiWan
- FlyingBird-Singapore
- FlyingBird-Malaysia
- FlyingBird-Japan
- FlyingBird-USA
- FlyingBird-UK
- name: Youtube
type: url-test
url: http://www.gstatic.com/generate_204
interval: 300
proxies:
- 境外流量
- name: Netflix
type: url-test
url: http://www.gstatic.com/generate_204
interval: 300
proxies:
- 境外流量
- name: Telegram
type: url-test
url: http://www.gstatic.com/generate_204
interval: 300
proxies:
- 境外流量
- name: Apple
type: url-test
url: http://www.gstatic.com/generate_204
interval: 300
proxies:
- 直接连接
- 境外流量
- name: Non-HK
type: url-test
url: http://www.gstatic.com/generate_204
interval: 300
use:
- FlyingBird-TaiWan
- FlyingBird-Singapore
- FlyingBird-Malaysia
- FlyingBird-Japan
- FlyingBird-USA
- FlyingBird-UK
- name: Colin
type: select
interval: 300
proxies:
- 直接连接
- 境外流量
- name: 直接连接
type: select
proxies:
- DIRECT
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-SUFFIX,openai.com,境外流量
- DOMAIN-SUFFIX,bing.com,Non-HK
- DOMAIN-SUFFIX,a-nomad.com,直接连接
- DOMAIN-SUFFIX,api2d.net,直接连接
- DOMAIN-SUFFIX,appstorrent.ru,Colin
- 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,direct,DIRECT
- RULE-SET,icloud,Apple
- RULE-SET,apple,Apple
- RULE-SET,google,境外流量
- RULE-SET,proxy,境外流量
- RULE-SET,telegramcidr,Telegram
- GEOIP,LAN,DIRECT
- GEOIP,CN,DIRECT
- MATCH,PROXY
留言