Rule-Based Routing: Deciding Traffic by Domain and Region
Rules are the core of Clash. The rules list in the config file is matched top to bottom: requests hitting DOMAIN-SUFFIX, DOMAIN-KEYWORD, GEOIP, and similar conditions are routed to a proxy or direct connection as specified; anything unmatched falls through to MATCH. Domains and IPs in mainland China go direct while everything else is proxied, with no manual toggling back and forth. Unlike traditional proxy tools that only offer a global or direct mode, rule-based routing decides each connection individually — direct traffic never takes a detour, and proxied traffic is never missed. Rules can be managed through a subscription or appended and overridden locally in the client.
rules:
- DOMAIN-SUFFIX,github.com,Select Proxy
- DOMAIN-SUFFIX,bilibili.com,DIRECT
- GEOIP,CN,DIRECT
- MATCH,Select Proxy
TUN Mode: Capturing Traffic That Skips the System Proxy
Some programs — command-line tools, games, certain client apps — ignore system proxy settings, so regular HTTP/SOCKS ports have no effect on them. TUN mode creates a virtual network adapter that pulls all outbound traffic from the device into the Clash core, then applies the same rule set, closing the gap the system proxy can't reach at the network layer. Enabling it requires administrator rights (Windows) or Network Extension permission (macOS); combined with dns-hijack, it can also intercept DNS queries to prevent tampered results. For everyday use, start with the system proxy and switch on TUN only when a program refuses to go through it.
tun:
enable: true
stack: system
auto-route: true
dns-hijack:
- any:53
Subscription Management: Keeping the Node List Current
A subscription is a URL pointing to a remote config. The client fetches it on the interval set in proxy-providers, so added or removed nodes and address changes sync locally without maintaining server details by hand. Multiple subscriptions can coexist, each updating independently, then get organized together through proxy groups. If a fetch fails, the client falls back to the last cached copy without breaking existing connections. Importing works the same way across clients: copy the subscription link and paste it into the config or subscription page; URL-based subscriptions can also be run through a conversion service to generate a full Clash config with complete rules.
proxy-providers:
main:
type: http
url: "https://example.com/sub.yaml"
interval: 86400
path: ./providers/main.yaml
Proxy Groups: Auto Speed Test, Failover, and Manual Fallback
A proxy group bundles multiple nodes into a single unit that rules can reference. url-test periodically pings every member and auto-selects the lowest latency; fallback guarantees availability in list order, switching to the next node if the preferred one fails; load-balance spreads connections across nodes; select keeps a manual entry point. All four types can nest inside each other — for example, a manual group whose candidates are several auto-test groups, balancing convenience with control. The tolerance parameter prevents nodes with similar latency from flip-flopping.
proxy-groups:
- name: Auto Select
type: url-test
url: http://www.gstatic.com/generate_204
interval: 300
tolerance: 50