Custom Routing Rules
Deep dive into Clash Party's Configuration Override feature, learn how to write custom routing rules, and master common rule syntax like DOMAIN and IP-CIDR.
Clash Party’s “Configuration Override” feature allows you to inject custom configurations without modifying the original subscription file. This is extremely useful when you need to force specific websites to proxy, direct connection, or block them.
This article will detail the rule writing syntax and provide plenty of practical examples.
What are Routing Rules?
Routing Rules are the core logic for how Clash handles network requests. Whenever a network request is initiated, Clash matches it against the rule list from top to bottom.
- Once a match is found, the request is handled according to the Strategy specified by that rule (e.g., Proxy, Direct, or Reject).
- If no rules match, the default fallback strategy (usually
MATCHorFINAL) is used.
How to Add Custom Rules
Here are the steps to add custom rules in Clash Party:
- Go to Settings > Configuration Override.
- Click the New button.
- Select the Rules type.
- Enter your rules in the editor (YAML format).
- Save and enable the override configuration.
Tip
Rule Syntax Structure
A standard Clash rule consists of three parts, separated by commas:
Type,Value,Strategy
- Type: The matching method, such as domain suffix, keyword, IP range, etc.
- Value: The specific content to match, like
google.comor192.168.0.0/16. - Strategy: The action to take after matching, such as
Proxy,Direct,Reject, or the specific name of your proxy group (e.g.,US Node).
Common Strategies
- DIRECT: Connect directly, bypassing the proxy.
- REJECT: Reject the request, blocking traffic (often used for ad blocking).
- PROXY / Proxy: Use the default proxy node or proxy group (depends on your main group name, usually subscriptions have a group named Proxy or Selector).
- Proxy Group Name: You can fill in any proxy group name that exists in your subscription here, such as
Streaming,Apple, etc.
Rule Types Explained
1. Domain Rules
DOMAIN-SUFFIX
The most commonly used rule type. Matches the domain and all its subdomains.
- Syntax:
DOMAIN-SUFFIX,domain,Strategy - Example:
# Matches google.com, www.google.com, maps.google.com, etc. - DOMAIN-SUFFIX,google.com,Proxy
DOMAIN-KEYWORD
Matches if the domain contains the keyword. Slightly slower, recommended only when the full domain is unknown.
- Syntax:
DOMAIN-KEYWORD,keyword,Strategy - Example:
# Matches adservice.google.com, my-ad-site.com, etc. - DOMAIN-KEYWORD,ad,REJECT
DOMAIN
Exact match of the entire domain; subdomains do not take effect.
- Syntax:
DOMAIN,domain,Strategy - Example:
# Matches www.google.com only, does not match mail.google.com - DOMAIN,www.google.com,Proxy
2. IP Rules
IP-CIDR / IP-CIDR6
Matches if the destination IP address is within the specified network range. no-resolve is an optional parameter indicating no DNS resolution should be performed (if the request is already in IP form).
- Syntax:
IP-CIDR,IP/Mask,Strategy[,no-resolve] - Example:
# Direct connection for LAN - IP-CIDR,192.168.0.0/16,DIRECT # Proxy for Google DNS - IP-CIDR,8.8.8.8/32,Proxy
GEOIP
Matches based on the country/region of the destination IP. Depends on the GeoIP database.
- Syntax:
GEOIP,CountryCode,Strategy[,no-resolve] - Example:
# Direct connection for Mainland China IPs - GEOIP,CN,DIRECT
3. Port and Process Rules
DST-PORT
Matches the destination port of the request.
- Syntax:
DST-PORT,Port,Strategy - Example:
# Block HTTP traffic on port 80 (example only, use with caution) - DST-PORT,80,REJECT
PROCESS-NAME
Matches the name of the application initiating the request. Very useful on Windows/macOS.
- Syntax:
PROCESS-NAME,ProcessName,Strategy - Example:
# Force Telegram to use Proxy - PROCESS-NAME,Telegram.exe,Proxy # Force Spotify to connect Direct - PROCESS-NAME,Spotify.exe,DIRECT
Example Library
Here are some common configuration scenarios you can copy directly into Configuration Override.
Scenario 1: Force Specific Sites to Proxy
Sometimes automatic routing rules might be inaccurate, or you want to force a specific site to use proxy (e.g., for testing).
- DOMAIN-SUFFIX,bilibili.com,Proxy
- DOMAIN-SUFFIX,weibo.com,Proxy
Scenario 2: Custom Ad Blocking
Block specific trackers or ad domains.
- DOMAIN-SUFFIX,doubleclick.net,REJECT
- DOMAIN-KEYWORD,analytics,REJECT
Scenario 3: Fix Banking App Access Issues
Some banking apps or websites are very sensitive to proxies and must be forced to connect directly.
- DOMAIN-SUFFIX,chase.com,DIRECT
- DOMAIN-SUFFIX,paypal.com,DIRECT
- DOMAIN-KEYWORD,bank,DIRECT
Scenario 4: Specific Software Routing
Force Zoom meeting software to connect directly for stability, and force Discord to use proxy.
# Windows Example
- PROCESS-NAME,Zoom.exe,DIRECT
- PROCESS-NAME,Discord.exe,Proxy
# macOS Example (usually doesn't need .app suffix, depends on actual process name)
- PROCESS-NAME,Zoom,DIRECT
- PROCESS-NAME,Discord,Proxy
Scenario 5: Development Environment Routing
If you are a developer, you may need to connect to company intranets or specific test servers.
# Direct connection for company intranet IP range
- IP-CIDR,10.0.0.0/8,DIRECT
# Proxy for specific test domain
- DOMAIN-SUFFIX,test-env.company.com,Proxy
FAQ & Notes
Priority Issues: Custom rules are usually added to the top of the list, so they have the highest priority. If you write
DOMAIN-SUFFIX,google.com,DIRECT, even if the subscription hasgoogle.com,Proxy, your direct rule will be executed first.Proxy Group Name Must Exist: If you fill in a specific proxy group name (like
Netflix) in the strategy part instead ofDIRECTorREJECT, please ensure that a proxy group with this name actually exists in your subscription, otherwise it will cause configuration errors.YAML Format Sensitivity:
- There is usually a space after the colon.
- Indentation must use spaces, not Tabs.
- List items start with
-.
Role of
no-resolve: Usingno-resolvein IP rules prevents Clash from making unnecessary DNS resolution requests to match IP rules. If the traffic itself is domain-based, Clash will resolve the domain to get the IP before matching IP rules. Withno-resolve, if the request is a domain, this IP rule is skipped directly (unless DNS resolution has already been completed in previous steps). It is generally recommended to add,no-resolveto the end ofGEOIPandIP-CIDRrules.
Recommended Open Source Rule Sets
If you need extensive, well-categorized rules (such as “all Apple services”, “all ad domains”, etc.), writing them by hand can be tedious. Here are some well-known community-maintained rule set projects that you can reference or reference via rule-providers (advanced usage):
Loyalsoldier/clash-rules
- Features: Very famous, focuses on GeoIP and domain categorization, suitable as a base rule library.
- Includes:
Google,Apple,Telegram,GFW,Greatfire, etc. - Link: GitHub Repository
ACL4SSR/ACL4SSR
- Features: Long history, extremely detailed categorization, used by default in many subscription conversion services.
- Includes:
Netflix,Disney+,Spotify,Steam,OneDriveand various streaming and app routing. - Link: GitHub Repository
blackmatrix7/ios_rule_script
- Features: Extremely high update frequency, covers a massive amount of apps and services, you can find rules for almost any app you’ve heard of.
- Includes: Categorized by APP name (e.g.,
TikTok,Twitter,OpenAI, etc.), perfect for finding domain lists for specific apps. - Link: GitHub Repository
By mastering these rule writing techniques, you can fully control Clash Party’s routing behavior and create the network environment that suits you best.