工具介绍

clash 是核心程序,没有图形化界面,但是兼容 Linux / macOS / Windows 三大平台。

clashX 是 clash 的图形化操作界面版本,内部集成 clash,仅可运行在 macOS 平台。

clash_for_windows_pkg 是 clash 的图形化操作界面版本,依赖于 clash 核心程序,二者要处于同一目录下。仅可运行在 Windows 平台。

clash-dashboard 是适配于 clash 的图形化面板,目前仍在开发,尚未发布。

clashX 1.6.0+ 与 clash 0.8+ 配置文件可通用。

配置文件格式采用 YAML,弃用 ini 格式。

两款工具要求配置文件必须存放在 $HOME/.config/config.yaml

下载规则

准备工作

  1. Windows 系统请暂时关闭 Windows Defender 的 “实时防护” 功能,否则他可能错误报告威胁,并阻止命令运行。
  2. 请确保你的计算机能成功连接到互联网。

Windows

  1. “开始” – “运行”(或按 Win + R 组合键),输入 cmd 后运行“命令提示符”。
  2. 复制并执行以下命令:mkdir %HOMEPATH%\.config\clash && cd /d %HOMEPATH%\.config\clash && certutil.exe -urlcache -split -f "https://cdn.jsdelivr.net/gh/Hackl0us/SS-Rule-Snippet@master/LAZY_RULES/clash.yaml" config.yaml && explorer .
  3. 在弹出的“资源管理器”窗口中,使用文本编辑工具编辑 config.yaml 配置文件即可。

macOS

  1. 运行 “终端” App。
  2. 复制并执行以下命令:mkdir -p $HOME/.config/clash/ && cd $HOME/.config/clash/ && sudo curl -o ./config.yaml https://cdn.jsdelivr.net/gh/Hackl0us/SS-Rule-Snippet@master/LAZY_RULES/clash.yaml -k -s && sudo chmod 775 ./config.yaml && open .
  3. 在弹出的“Finder”窗口中,使用文本编辑工具编辑 config.yaml 配置文件即可。

Linux

  1. 复制并执行以下命令:mkdir -p $HOME/.config/clash/ && cd $HOME/.config/clash/ && sudo curl -o ./config.yaml https://cdn.jsdelivr.net/gh/Hackl0us/SS-Rule-Snippet@master/LAZY_RULES/clash.yaml -k -s && sudo chmod 775 ./config.yaml
  2. 使用 nano / vim / gedit 等类似工具编辑当前目录下 config.yaml 配置文件即可。

编写配置文件

Clash 配置文件的基本格式官方 Wiki 有足够详尽的说明,有兴趣可以自己阅读,这里就不重复解释了,直接提供一个通用的配置(注意需要在 proxy-providers 中粘贴自己转换得到的链接):

mixed-port: 7890
allow-lan: true
mode: rule
log-level: info
ipv6: false
#dns: #DNS 设置一般无需打开,如果你坚持想用,请确保你知道在做什么
  #enable: true
  #listen: 0.0.0.0:53
  #ipv6: false
  #default-nameserver:
    #- 223.5.5.5
    #- 119.29.29.29
  #enhanced-mode: redir-host
  #nameserver:
    #- https://doh.pub/dns-query
    #- https://dns.alidns.com/dns-query
  #fallback:
    #- https://1.1.1.1/dns-query
    #- https://dns.google/dns-query
  #fallback-filter:
    #geoip: true
    #geoip-code: CN
    #ipcidr:
      #- 240.0.0.0/4

proxy-providers:
  myproxy:
    type: http
    url: https://example.com #粘贴 Proxy Provider Converter 提供的链接
    interval: 172800
    path: ./myproxy.yaml
    health-check:
      enable: true
      interval: 600
      # lazy: true
      url: http://www.gstatic.com/generate_204

proxy-groups:
  - name: "PROXY"
    type: select
    use:
      - myproxy
  - name: "Ads"
    type: select
    proxies:
      - REJECT
      - PROXY
      - DIRECT
  - name: "Apple"
    type: select
    proxies:
      - DIRECT
      - PROXY
  - name: "Telegram"
    type: select
    use:
      - myproxy
    proxies:
      - PROXY
  - name: "YouTube"
    type: select
    use:
      - myproxy
    proxies:
      - PROXY
  - name: "GlobalMedia"
    type: select
    use:
      - myproxy
    proxies:
      - PROXY
  - name: "Steam"
    type: select
    use:
      - myproxy
    proxies:
      - DIRECT
      - PROXY
  - name: "Others"
    type: select
    proxies:
      - PROXY
      - DIRECT

rule-providers:
  reject:
    type: http
    behavior: domain
    url: "https://ghproxy.com/https://raw.githubusercontent.com/Loyalsoldier/clash-rules/release/reject.txt"
    path: ./ruleset/reject.yaml
    interval: 86400

  icloud:
    type: http
    behavior: domain
    url: "https://ghproxy.com/https://raw.githubusercontent.com/Loyalsoldier/clash-rules/release/icloud.txt"
    path: ./ruleset/icloud.yaml
    interval: 86400

  apple:
    type: http
    behavior: domain
    url: "https://ghproxy.com/https://raw.githubusercontent.com/Loyalsoldier/clash-rules/release/apple.txt"
    path: ./ruleset/apple.yaml
    interval: 86400

  streaming:
    type: http
    behavior: classical
    url: "https://ghproxy.com/https://raw.githubusercontent.com/DivineEngine/Profiles/master/Clash/RuleSet/StreamingMedia/Streaming.yaml"
    path: ./ruleset/streaming.yaml
    interval: 86400
  
  steam:
    type: http
    behavior: classical
    url: 'https://ghproxy.com/https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/rule/Clash/Steam/Steam.yaml'
    path: ./ruleset/steam.yaml
    interval: 86400

  steamCN:
    type: http
    behavior: classical
    url: 'https://ghproxy.com/https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/rule/Clash/SteamCN/SteamCN.yaml'
    path: ./ruleset/steamCN.yaml
    interval: 86400
    
  youtube:
    type: http
    behavior: classical
    url: 'https://ghproxy.com/https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/rule/Clash/YouTube/YouTube.yaml'
    path: ./ruleset/youtube.yaml
    interval: 86400

  proxy:
    type: http
    behavior: domain
    url: "https://ghproxy.com/https://raw.githubusercontent.com/Loyalsoldier/clash-rules/release/proxy.txt"
    path: ./ruleset/proxy.yaml
    interval: 86400

  direct:
    type: http
    behavior: domain
    url: "https://ghproxy.com/https://raw.githubusercontent.com/Loyalsoldier/clash-rules/release/direct.txt"
    path: ./ruleset/direct.yaml
    interval: 86400

  private:
    type: http
    behavior: domain
    url: "https://ghproxy.com/https://raw.githubusercontent.com/Loyalsoldier/clash-rules/release/private.txt"
    path: ./ruleset/private.yaml
    interval: 86400

  telegramcidr:
    type: http
    behavior: ipcidr
    url: "https://ghproxy.com/https://raw.githubusercontent.com/Loyalsoldier/clash-rules/release/telegramcidr.txt"
    path: ./ruleset/telegramcidr.yaml
    interval: 86400

  lancidr:
    type: http
    behavior: ipcidr
    url: "https://ghproxy.com/https://raw.githubusercontent.com/Loyalsoldier/clash-rules/release/lancidr.txt"
    path: ./ruleset/lancidr.yaml
    interval: 86400

  applications:
    type: http
    behavior: classical
    url: "https://ghproxy.com/https://raw.githubusercontent.com/Loyalsoldier/clash-rules/release/applications.txt"
    path: ./ruleset/applications.yaml
    interval: 86400

rules:
  - RULE-SET,applications,DIRECT
  - DOMAIN,clash.razord.top,DIRECT
  - DOMAIN,yacd.haishan.me,DIRECT
  - RULE-SET,private,DIRECT
  - RULE-SET,reject,Ads
  - RULE-SET,icloud,Apple
  - RULE-SET,apple,Apple
  - RULE-SET,youtube,YouTube
  - RULE-SET,streaming,GlobalMedia
  - RULE-SET,steamCN,DIRECT
  - RULE-SET,steam,Steam
  - RULE-SET,proxy,PROXY
  - RULE-SET,direct,DIRECT
  - RULE-SET,telegramcidr,Telegram
  - RULE-SET,lancidr,DIRECT
  - GEOIP,CN,DIRECT
  - MATCH,Others

我没有能力手写成千上万的规则,而是引入了与 Proxy Provider 类似的 Rule Provider,直接使用网络上的第三方规则集。Clash 的规则是从前到后依次匹配的,已经匹配到的流量就不会向后继续匹配。值得注意的情况有:

  1. iCloud 与其他一些苹果服务有专门的 Apple 代理组,可以选择直连或代理(一般而言直连就够了);
  2. 尽管 streaming 规则集中包括了 YouTube,但我还是将 YouTube 规则单列出来放在前面,如果有送中节点的话可以免广告看 YouTube;
  3. Steam 登录和下载一直是老大难问题。以前使用机场规则时,我的经验是(国区)需要在登录时将 SteamOthers 代理组都选为直连,登录后再改为需要的代理节点,这样才不会无法登录,下载节点是国内,同时也能访问好友列表、创意工坊等内容。如今自己写的规则先将 steamCN 规定为直连,再把剩下的 steam 流量用一个代理组选择代理节点,体验就基本完美了。

当然这只是一个追求最大通用性的内容,你也可以自行修改增加需要的规则。比如我实际使用的规则中还包括一条 DOMAIN,***.sharepoint.com,MyOneDrive,再在 proxy-groups 里添加 MyOneDrive 这一代理组和所需的节点,这样在我向 5T OneDrive 上传视频时可以切换为直连节约流量,观看时又打开代理来保障体验。不过请注意,出于规则匹配顺序的原因,一般自己修改的这些规则都应该放在较为靠前的位置。另外,规则集可以在这些地方找到:

https://github.com/Loyalsoldier/clash-rules 简洁明了,注意需要设置为 behavior: domain

https://github.com/blackmatrix7/ios_rule_script/tree/master/rule/Clash 非常全面,behavior: classical

https://github.com/DivineEngine/Profiles/tree/master/Clash/RuleSet 知名选择,behavior: classical

这些规则集提供的 https://raw.githubusercontent.com 地址在国内通常无法访问,只需要在前面加上 https://ghproxy.com/,组成 https://ghproxy.com/https://raw.githubusercontent.com/Loyalsoldier/clash-rules/release/proxy.txt 这样的 URL 就好。

类似文章