Clash Usage Guide
Relevant source files
The following files were used as context for generating this wiki page:This repository provides a self-managed set of traffic-forwarding rules for Clash, based on the ACL4SSR project. The system is designed to intelligently route network traffic based on domain names, IP addresses, and other criteria, separating domestic traffic for direct connection from international traffic that requires a proxy. The configuration is primarily managed through a main YAML file, a collection of rule provider files, and Python scripts for automating rule updates.
The core architecture involves using .list files as the source of truth for rules, which are then processed by scripts to generate compatible configuration files for both Clash (.yaml) and sing-box (.srs). This allows for a single source of rules to be used across different proxy clients.
Core Configuration (GeneralClashConfig.yml)
The main configuration file, Clash/GeneralClashConfig.yml, defines the core behavior of the Clash client, including ports, network settings, logging, and DNS resolution logic.
Key Parameters
The following table summarizes the essential configuration parameters.
| Parameter | Value | Description |
|---|---|---|
mixed-port | 7890 | A single port for both HTTP and SOCKS5 proxy services. |
allow-lan | true | Allows other devices on the local network to connect to the proxy. |
bind-address | * | Binds to all IP addresses when allow-lan is true. |
mode | rule | Sets the default mode to follow the defined rules for traffic routing. |
log-level | info | Sets the logging level. Options are silent, error, warning, info, debug. |
external-controller | 127.0.0.1:9090 | The address for the Clash RESTful API, used for management via dashboards. |
ipv6 | true | Enables IPv6 support. |
Sources: Clash/GeneralClashConfig.yml:5-30
DNS Resolution Logic
The configuration specifies a sophisticated DNS resolution strategy to improve speed and avoid DNS pollution. The logic is detailed in the comments of the configuration file.
The diagram below illustrates the DNS request flow in Clash as configured in this repository.
Sources: Clash/GeneralClashConfig.yml:82-90
The configuration uses a mix of standard and secure DNS servers (DoH/DoT) to balance performance and security.
nameserver: Contains fast, domestic DNS servers for quick resolution of local domains.- Example:
223.5.5.5(AliDNS),119.29.29.29(DNSPod)
- Example:
fallback: Contains secure, non-polluted international DNS servers for resolving foreign domains.- Example:
8.8.8.8(Google DNS),tls://dns.google:853(Google DoT)
- Example:
Sources: Clash/GeneralClashConfig.yml:62-79
Clash for Windows (CFW) Settings
The configuration includes several settings specific to the Clash for Windows client.
System Proxy Bypass (cfw-bypass)
This is a critical feature that defines which domains should bypass the system proxy and connect directly. The list is extensive and categorized to cover a wide range of Chinese domestic services.
Bypass Categories:
- Personal direct-connect list (
MyList) - Generic CN TLDs (
.cn,.xn--fiqs8s, etc.) - Major Chinese tech companies (Alibaba, Baidu, Bilibili, ByteDance, Tencent)
- Streaming and media services (Iqiyi, Youku, MGTV)
- E-commerce sites (JD, Pinduoduo, Suning)
- Gaming platforms (SteamCN)
- Public CDNs and DNS services
- Common local IP ranges (
127.*,192.168.*, etc.)
Sources: Clash/GeneralClashConfig.yml:210-990
Other CFW Settings
| Parameter | Value | Description |
|---|---|---|
cfw-latency-url | http://www.gstatic.com/generate_204 | URL used to test proxy latency. |
cfw-conn-break-strategy | proxy: none | Defines how connections are handled when switching proxies. none means existing connections are not broken. |
cfw-proxies-order | default | Sorts proxies in the UI based on their order in the configuration file. |
Sources: Clash/GeneralClashConfig.yml:118-119, 150-153, 172-177
Rule Providers
The repository heavily utilizes external rule files, known as "Providers," to manage large lists of domains and IPs. These are organized under the Clash/Providers/ directory.
Provider Types
-
Proxy Providers: These files define which traffic should be routed through a proxy.
ProxyGFWlist.yaml: A comprehensive list containing thousands of rules for sites and services blocked by the GFW. It also includes rules for popular international services like Google, Facebook, and Telegram.ProxyLite.yaml: A lighter version of the proxy list, containing rules for essential services and major platforms.
-
Ruleset Providers: These are smaller, more focused rule sets for specific categories of services. They are located in
Clash/Providers/Ruleset/.
| Ruleset File | Description |
|---|---|
AI.yaml | Rules for AI platforms like OpenAI, Claude, and Gemini. |
Developer.yaml | Rules for developer tools and sites like Docker, GitLab, and Stack Overflow. |
Scholar.yaml | Rules for domestic and international academic websites like IEEE, Nature, and CNKI. |
Wikipedia.yaml | Rules for Wikipedia and its sister projects. |
Crypto.yaml | Rules for cryptocurrency exchanges and services like Binance, Coinbase, and Ethereum. |
Microsoft.yaml | Rules for various Microsoft services, including Office 365, Azure, and OneDrive. |
Sources: Clash/Providers/ProxyGFWlist.yaml, Clash/Providers/ProxyLite.yaml, Clash/Providers/Ruleset/AI.yaml, Clash/Providers/Ruleset/Developer.yaml, Clash/Providers/Ruleset/Scholar.yaml, Clash/Providers/Ruleset/Wikipedia.yaml, Clash/Providers/Ruleset/Crypto.yaml, Clash/Providers/Microsoft.yaml
Provider File Format
The provider files use a simple YAML structure with a payload key, followed by a list of rule entries.
# Source: Clash/Providers/Ruleset/Wikipedia.yaml
payload:
# 内容:Wikipedia 维基相关域名
# 数量:12条
- DOMAIN-SUFFIX,mediawiki.org
- DOMAIN-SUFFIX,wikibooks.org
- DOMAIN-SUFFIX,wikidata.org
- DOMAIN-SUFFIX,wikileaks.org
- DOMAIN-SUFFIX,wikimedia.org
Sources: Clash/Providers/Ruleset/Wikipedia.yaml:1-8
Automation and Conversion
The repository includes Python scripts to automate the generation of provider files from simpler .list files, ensuring maintainability and compatibility with different proxy clients.
Clash Provider Generation (update_providers.py)
The update_providers.py script converts .list files into Clash-compatible .yaml provider files.
This diagram shows the conversion process managed by the script.
Sources: update_providers.py
sing-box Rule Generation (update_sing_box.py)
Similarly, the update_sing_box.py script converts the same .list files into rule sets for the sing-box client. It generates an intermediate JSON file which is then compiled into a binary .srs file.
This diagram shows the conversion and compilation flow for sing-box.
Sources: update_sing_box.py
Rule Conversion Tools
The Tool/ directory contains utilities for manual rule format conversions, such as macros for the Notepad++ editor. These macros facilitate converting rules between formats like Surge, ACL, and plain domain lists using regular expressions.
Sources: Tool/Surge转acl工具/shortcuts.xml
Summary
The Self-Rule repository offers a powerful and well-organized system for managing Clash proxy rules. It leverages a centralized set of source lists and automates the generation of configuration files for multiple proxy clients. The detailed GeneralClashConfig.yml provides fine-grained control over DNS and proxy behavior, while the extensive cfw-bypass and ProxyGFWlist ensure that traffic is routed efficiently and correctly. The inclusion of automation scripts makes the entire system scalable and easy to maintain.