Configuration: make it run, then tune it

The file below starts as-is. Once these seven keys make sense, everything else is addition and subtraction.

Minimal working config

config.yaml
mixed-port: 7890
allow-lan: false
mode: rule
log-level: info
external-controller: 127.0.0.1:9090

dns:
  enable: true
  nameserver:
    - 223.5.5.5
    - 119.29.29.29

proxies:
  - name: node-1
    type: vless
    server: example.com
    port: 443

proxy-groups:
  - name: PROXY
    type: select
    proxies: [node-1]

rules:
  - GEOIP,CN,DIRECT
  - MATCH,PROXY

Indentation is syntax

YAML accepts spaces, never tabs. Convert tabs to two spaces or you get yaml: line N: found character that cannot start any token.

Seven keys you will actually touch

KeyEffectCommon mistake
mixed-portShared HTTP and SOCKS5 port, default 7890Fighting another proxy tool for the port
allow-lanWhether LAN devices may connectOn without a secret is an open proxy
moderule, global or directWriting rules crashes on start
external-controllerControl API the client reads state fromBinding 0.0.0.0 exposes it
dns.enableWhether the kernel owns DNSEnabled with an empty nameserver breaks resolution
tun.enableVirtual adapter capturing all trafficEnabled without permission: operation not permitted
rulesRouting rules, first match winsNo final MATCH: unmatched traffic goes direct

Four group types cover most cases

select
Manual choice. Use it for decisions only you can make, like "streaming" or "work"
url-test
Picks the fastest by latency, re-tested every interval seconds
fallback
Uses the first healthy node in order; suits a primary and a backup line
load-balance
Spreads one domain across nodes. Good for downloads, bad for anything needing a stable exit IP
A tested group
proxy-groups:
  - name: AUTO
    type: url-test
    url: https://www.gstatic.com/generate_204
    interval: 300
    tolerance: 50
    proxies: [node-1, node-2]

Order decides the outcome

Rules evaluate top to bottom and stop at the first match, so exceptions belong above the catch-all: specific domains first, then GEOIP,CN,DIRECT, then MATCH,PROXY. Put MATCH first and nothing below it ever runs.

  • DOMAIN-SUFFIX,example.com,PROXY: the workhorse.
  • DOMAIN-KEYWORD,google,PROXY: broad and easy to over-match; use sparingly.
  • IP-CIDR,10.0.0.0/8,DIRECT,no-resolve: LAN bypass without triggering DNS.
  • GEOIP,CN,DIRECT: needs the GeoIP data files.

Validate before restarting

mihomo -t -f ./config.yaml
# configuration file ./config.yaml test is successful

Validate, then restart the service or hit reload in the client. Skipping this turns every typo into a log-reading session.

Questions

Where does the config live?
Desktop clients manage their own directory. A standalone kernel reads config.yaml from the working directory you pass with -d.
I changed the port and nothing works.
You probably changed it in one place only. The kernel listens on the new port while the system proxy still points at the old one, so everything times out.
Does TOML or JSON work?
No. mihomo parses YAML. JSON is structurally compatible but the parser is YAML; do not mix them.