Clash config.yaml Explained: proxies, proxy-groups, and rules
A section-by-section guide to config.yaml, covering ports, modes, DNS, proxies, proxy-groups, rule providers, rules, and common YAML mistakes.
Ports and modes: check how traffic reaches the core first
The examples below use mihomo (Clash Meta) and belong in the same config.yaml, in the order shown. Keep top-level keys flush left. If an existing file already has a key with the same name, edit that section rather than adding a duplicate at the end. Practice on a local copy of your configuration: subscription updates may overwrite edits made directly to a subscription file, and a client may merge or override settings at startup.
mixed-port: 7890
allow-lan: false
mode: rule
log-level: info
mixed-port: 7890: Accepts HTTP and SOCKS proxy connections on the same port. Set a local app's proxy address to127.0.0.1:7890and choose a proxy type supported by that app. If the port is already in use, change it to7892and update the app's proxy port as well.allow-lan: false: This example is for local use only; it does not expose the proxy to other devices on the LAN. If another device needs to connect, it cannot use127.0.0.1to reach the computer running the core.mode: rule: Routes traffic according torules. If the client is currently in Global or Direct mode while troubleshooting, switch back to Rule mode first so a mode mismatch is not mistaken for an error in rule order.
Configuring a listening port does not automatically route app traffic through it. Start by connecting a proxy-capable app explicitly to the mixed port and confirming the connection appears in the logs. Then consider enabling the system proxy or TUN. The system proxy only affects apps that follow system settings; TUN receives traffic at the network layer and is a separate entry point, not a feature that turns on automatically when you change mixed-port.
dns: distinguish DNS results from proxy routing
dns:
enable: true
enhanced-mode: fake-ip
fake-ip-range: 198.18.0.1/16
fake-ip-filter:
- '+.lan'
- '+.local'
nameserver:
- 223.5.5.5
nameserver lists upstream resolvers; this example uses an IP address. When an app's DNS queries are handled by the core, Fake-IP mode can return a virtual IPv4 address from the 198.18.0.0/16 range. When the app connects to that address, the core uses its mapping to recover the domain name and match it against the rules. Seeing 198.18.x.x does not mean the upstream website uses that address, nor does it mean the request has gone through a proxy.
This example uses the default filter mode and excludes +.lan and +.local from virtual address allocation. Filter entries only change how DNS answers are returned; they do not add Direct rules or reveal the names of local devices to public resolvers. For example, if a router's local domain still fails to resolve, check whether the query reaches a local resolver that can answer it. dns.enable enables the core's DNS module, but does not change the system DNS setting on its own. If an app uses its own encrypted DNS, check which resolution path it actually takes.
proxies: define outbound nodes
proxies:
- name: Local SOCKS
type: socks5
server: 127.0.0.1
port: 1080
proxies is the list of nodes. Each - starts an entry; name is the reference name used in the configuration, type specifies the protocol, and server and port specify the outbound service address. This example assumes another SOCKS5 service is listening on 1080 on the same machine. Without that service, requests routed through this node will fail. Test routing with the DIRECT policy shown below before adding a real node.
7890is the entry point apps use to connect to mihomo;1080is the outbound port mihomo uses to connect to another service. Do not point an outbound node back at your own mixed proxy port. When using a real node, keep the fields required by its protocol; changing onlytypewhile reusing the SOCKS configuration is not enough.
proxy-groups: put available routes into a policy group
proxy-groups:
- name: Manual Select
type: select
proxies:
- DIRECT
- Local SOCKS
The top-level proxies defines nodes; the group-level proxies references them. The names are the same, but the keys are at different levels. Local SOCKS must exactly match the node's name; DIRECT is a built-in policy and does not need a separate definition. The rules below point to the group name Manual Select, not to a server address entered a second time.
select creates a manual selection group; it does not switch nodes based on latency. During testing, check the group's current selection in the client's proxy policy view rather than inferring it from the list order, since the client may restore a previous selection. If a connection matches this group but goes Direct, first check whether DIRECT is still selected in the group.
rule-providers: declare a rule set, then reference it from rules
rule-providers:
demo-direct:
type: file
behavior: classical
format: yaml
path: ./rules/demo-direct.yaml
This section only registers a local rule set named demo-direct. Save the following content as a separate rule file; do not add it to the main configuration. Relative paths are resolved from mihomo's working directory, which may not be the directory containing the file opened in your editor when using a graphical client. If the client reports that the file is missing, first check the current instance's data directory, then look for rules/demo-direct.yaml inside it.
payload:
- 'DOMAIN,example.org'
- 'DOMAIN-SUFFIX,example.net'
classical accepts entries with match types; the entries here specify match conditions without an outbound policy. By contrast, a rule set with behavior: domain uses domain-matching entries without the DOMAIN, or DOMAIN-SUFFIX, prefix. If you switch to type: http, provide the rule set address in url and make sure format matches the remote content. interval: 86400 sets an update interval of 86,400 seconds; it does not control node subscription updates.
rules: put exceptions first and end with MATCH
rules:
- DOMAIN,docs.example.com,DIRECT
- DOMAIN-SUFFIX,example.com,Manual Select
- RULE-SET,demo-direct,DIRECT
- MATCH,DIRECT
In Rule mode, rules are checked in list order, and the policy on the first matching rule is used. DOMAIN matches an exact hostname; DOMAIN-SUFFIX matches that domain and its subdomains. Put the exception for docs.example.com before the example.com suffix rule; otherwise, the suffix rule will match first. Enter a domain in a rule, not a web address with https:// or a path.
In RULE-SET,demo-direct,DIRECT, the second field is the rule set key and the third is the policy. The example sends both the rule set and the fallback to Direct, making it easy to test before adding a node. Since both have the same destination, use the matching entry in the logs to tell them apart. MATCH catches connections that did not match earlier rules. If it appears in the middle, later rules will never run.
| Target hostname | Expected match | Outbound policy |
|---|---|---|
docs.example.com | DOMAIN | DIRECT |
www.example.com | DOMAIN-SUFFIX | Manual Select |
example.org | RULE-SET | DIRECT |
www.example.org | MATCH | DIRECT |
This table assumes the core receives a hostname and the rule set has loaded. The example domains demonstrate matching; do not use whether a website opens to judge if a rule matched correctly. If an app sends only the destination IP to the core, with no available domain mapping or identification result, domain rules may skip the connection. Changing the rule order cannot fix an entry point that provides no domain name.
Load failures and routing issues: troubleshoot in three layers
- Check the YAML structure first. Indent with spaces, not tabs. Keep top-level keys flush left. In the examples here, list items under
proxiesuse two leading spaces, and a node'stypealigns with itsname. Use English commas in rule entries. Quote values that contain a colon followed by a space or a#that might be treated as the start of a comment. The reported line may only be where the parser detected the problem, so check the line above it too. - Check names and files next. Work backward from the last rule to its policy name, from
RULE-SETto its rule set key, and from the group list to the node name. Check capitalization, full-width punctuation, and accidental spaces. If mihomo is installed locally, runmihomo -t -d . -f config.yamlfrom the directory containing your configuration copy so the test uses the same working directory as the example rule file. A successful check does not guarantee that a port can be bound or that a node is online. - Check runtime behavior last. After reloading, confirm that the client has enabled the modified configuration and is in Rule mode. Send a test request that explicitly uses the local HTTP proxy:
curl --proxy http://127.0.0.1:7890 https://example.org/. In the core logs, check the matched rule for the target domain, then check the final outbound route. If the request does not appear in the logs at all, check the listening port and traffic entry point first. If a policy matched but the connection failed, check DNS, the node, or the destination service.
Change only one thing per test cycle: verify the entry point first, then the rule match, and finally the outbound route selected by the policy group. This helps distinguish between a configuration that did not load, a rule that did not match, and a successful match with an unavailable outbound route—without repeatedly rewriting the entire file.