Clash is arguably the most useful proxy software available today, with rich features, a clean interface, and easy to use. However, Clash is also faced with imperfect subscription rules. For example, the Notion note software (Notion. So) that I often use is not included in my subscription node rules, so that only global mode can be opened each time. Those who are familiar with Clash should know that Clash provides a functional interface to customize new rules, which is very friendly for white. However, this method has a fatal defect, that is, every time the subscription node is updated, the custom rules will be overwritten, resulting in the loss of rules. This article will introduce a method of adding custom rules by writing javascript code and preprocessing subscription rules using Clash’s Parser function, which can avoid the loss of rules caused by subscription updates.

Method details

Note: To use this method, Clash should be later than 0.11.10. If Clash is later than 0.11.10, please download the installation package from Github first.

Portal: Clash download address

  1. Open theSetting(Set), findProfiles(Under configuration file)Parsers.

  1. Click on the rightEditThe edit page is displayed.

  1. Enter the following code (this is a sample code that needs to be modified) :
parsers: # array
  - url: https://sub.paasi.com/subscribe/5**490/J*****oGHBE
    yaml:
      prepend-rules:
        - DOMAIN-SUFFIX,notion.so,GLOBAL
	- DOMAIN-SUFFIX,medium.com,GLOBAL
Copy the code

Among the changes that need to be made are the URL and preend-rules.

  • Url: change my subscription address, if you do not know, you can directly inProfilesClick on the current subscriptionChange imformation, copy the URL.
  • Prepen-rules Here add your custom rules, one line at a time, according toRule type.value.Agent strategyArrange, separated by commas. Note that each line needs to be delimited with a dash-Add a space At the beginning, also pay attention to alignment. How specific custom rules are written is explained in the second half of this article.
  1. Click on the lower right corner to save inProfilesUpdate the subscription so that new rules can be added. You can click on theEdit rulesView rules for verification. Then open the corresponding webpage to see if it takes effect.

Custom rule writing mode

Rule type selection

Clash currently supports the following rule types:

  • Domain-suffix: DOMAIN name SUFFIX matches
  • DOMAIN: the DOMAIN name matches
  • Domain-keyword: matches the DOMAIN name KEYWORD
  • Ip-cidr: IP segment matching
  • Src-ip-cidr: indicates that the source IP address segment matches
  • GEOIP: GEOIP database (country code) match
  • Dst-port: indicates that the destination PORT matches
  • Src-port: indicates that the source PORT matches
  • Process-name: indicates that the source PROCESS NAME matches
  • Rule-set: matches the RULE Provider RULE
  • MATCH: all matches are matched

Domain-suffix is the most commonly used SUFFIX. In order to docs.cfw.lbyczf.com/contents/mi… For example, the domain name is docs.cfw.lbyczf.com. A suffix is the part of a domain name formed from the back of the domain name. Some companies prefix the underlying domain name and resolve it to a separate IP address. For example, world.taobao.com adds the domain prefix world before taobao.com. Another common prefix is WWW. If I need to add both world.taobao.com and taobao.com to the custom rule. We can use domain-suffix with the value taobao.com. In general, it is recommended to use domain-suffix instead of DOMAIN, because many times you don’t know the DOMAIN name structure of the service you are using, and often you will jump to a subdomain with a prefix, and it will be embarrassing to suddenly find that you can’t open it.

The rest of the rule types can be guessed from the instructions, so you can explore for yourself.

Note:

To use process-name, Clash for Windows V0.11.5 or later is required. Rules must match all process names (including executable file suffixes) to take effect. This rule does not apply to TAP traffic.

The USER interface does not support adding the rule-set RULE. You need to manually edit the configuration file.

MATCH needs to be at the end of the rule list.

Proxy policy selection

The second part of the custom rule value is filled in according to the rule type and requirement. The third part of the custom rule value is the proxy policy. Here you can fill in the proxy node or policy. Click Edit Rules to enter the rule editing interface, click Add, and drop down to see all the optional nodes or policies.

In general we use DIRECT, GLOBAL, REJECT. DIRECT: does not go through the proxy, that is, does not directly connect to the proxy node. GLOBAL is the GLOBAL proxy node. REJECT disables connection. REJECT blocks websites.

Some subscriptions also offer a host of home-made strategies that readers can try on their own. When using directly enter the name, Chinese is also supported oh. Some people might ask, what if I have some weird symbols in front of me?

Click General, click Open Folder under Home Directory, Open the configuration Folder, click Profiles, find the corresponding yml file, Open it with Notepad++ or other software, copy and paste directly.

Now that rules are written, here are some examples of correct rules:

IP – CIDR 123.253.240.0/22, DIRECT

DOMAIN – SUFFIX, netflixdnstest0.com, agent

DOMAIN-SUFFIX,flash.cn,REJECT

DOMAIN-SUFFIX,notion.so,GLOBAL

The principle is introduced

Why does this approach prevent overwriting? The reason is that the Parser function preprocesses the configuration file, so every update is executed once, so the custom rules will always exist as long as you don’t remove the Parser.

expand

Parser is a very powerful feature that does a lot of preprocessing on subscription files to achieve a lot of rich effects. However, this feature is not very friendly for Xiaobai, and interested readers can check out Clash’s documentation to learn. Wish you all a happy work and study ~

Portal: Clash documentation

Cover image source network, delete. Article reprint please indicate the source and author, welcome to reprint.