基础
本页讲解 YAML 文档的扁平顶层键 —— 监听端口、访问控制、网络标志与 路由模式选择。它们都直接位于 RawConfig 上,并在 config/config.go 中接入运行时。
选项
| 字段 | 类型 | 默认值 | 允许值 | 描述 |
|---|---|---|---|---|
port | int | 0 | 0 | <port> | HTTP 代理监听端口。0 禁用。 |
socks-port | int | 0 | 0 | <port> | SOCKS5 监听端口。0 禁用。 |
redir-port | int | 0 | 0 | <port> | Linux REDIRECT 入站端口(iptables NAT)。0 禁用。 |
tproxy-port | int | 0 | 0 | <port> | Linux TPROXY 入站端口(iptables mangle)。0 禁用。 |
mixed-port | int | 0 | 0 | <port> | 同一监听器上复用 HTTP 与 SOCKS5 的端口。0 禁用。 |
inbound-tfo | bool | false | true | false | 在入站监听器上启用 TCP Fast Open(仅 Linux)。 |
inbound-mptcp | bool | false | true | false | 在入站监听器上启用多路径 TCP(仅 Linux)。 |
authentication | []string | [] | <user:pass> | HTTP / SOCKS 鉴权凭据白名单。为空则禁用鉴权。 |
skip-auth-prefixes | []netip.Prefix | [] | <CIDR> | 可绕过鉴权的源 IP 前缀。 |
lan-allowed-ips | []netip.Prefix | [] | <CIDR> | `allow-lan` 为 true 时,仅这些源 IP 前缀可访问。 |
lan-disallowed-ips | []netip.Prefix | [] | <CIDR> | `allow-lan` 为 true 时,拒绝这些源 IP 前缀。 |
allow-lan | bool | false | true | false | 把监听器绑定到 0.0.0.0 / :: 而不是 127.0.0.1。 |
bind-address | string | * | * | <address> | 覆盖绑定地址;* 表示按 `allow-lan` 选择。 |
mode | T.TunnelMode | rule | rule | global | direct | 隧道决策策略。`rule` 走规则列表;`global` 一律送往 GLOBAL;`direct` 完全绕过代理。 |
unified-delay | bool | false | true | false | 从 URL 测试延迟中扣除 TLS 握手时间,便于跨代理公平比较。 |
ipv6 | bool | false | true | false | IPv6 总开关。为 false 时过滤 AAAA 记录并禁用 IPv6 路由。 |
interface-name | string | (auto) | <interface> | 把所有出站拨号绑定到该接口(例如 eth0)。 |
routing-mark | int | 0 | <uint32> | 出站套接字上设置的 Linux SO_MARK。0 禁用。 |
tcp-concurrent | bool | false | true | false | 对每条连接并发拨号 A 与 AAAA,谁先连上用谁(Happy Eyeballs 风格)。 |
find-process-mode | process.FindProcessMode | strict | strict | always | off | 为路由(`PROCESS-NAME` 规则)查找发起进程的力度。 |
global-client-fingerprint | string | (removed) | <utls fingerprint> | 已移除并被忽略。请改为在每个代理上直接设置 `client-fingerprint`。 |
global-ua | string | clash.meta/<version> | <string> | 订阅与资源下载的默认 User-Agent。 |
etag-support | bool | true | true | false | 重新拉取订阅 URL 时遵循 ETag 头。 |
keep-alive-idle | int | 0 | <seconds> | TCP keepalive 空闲时长。0 使用操作系统默认。 |
keep-alive-interval | int | 0 | <seconds> | TCP keepalive 探测间隔。0 使用操作系统默认。 |
disable-keep-alive | bool | false | true | false | 完全禁用 TCP keepalive。 |
源码: config/config.go:393-460 · 锚定版本 v1.19.27 (5184081)
示例
yaml
mode: rule
mixed-port: 7890
allow-lan: false
bind-address: '*'
ipv6: false
unified-delay: true
tcp-concurrent: true
find-process-mode: strict
global-ua: my-mihomo/1.0
keep-alive-idle: 600
keep-alive-interval: 30说明
port/socks-port/mixed-port互不冲突 —— 三者可以同时开放, 但在port与mixed-port上都暴露 HTTP 角色会浪费一个监听器。bind-address的*是特殊值:表示「按当前allow-lan决定」 (为 true 用0.0.0.0,false 用127.0.0.1)。find-process-mode: always会让路由器对 每条 连接都调用平台 侧的进程查找系统调用,在繁忙的 macOS / Windows 上代价昂贵。 除非 PROCESS-NAME 规则关键,否则建议保持默认strict。global-client-fingerprint已被 移除:现在虽会被解析但会被 忽略。请改为在每个代理条目上直接设置client-fingerprint。- 配置文件可以是 age 加密的。解析 YAML 之前,mihomo 会尝试用
age解密文件;若文件已加密,则在加载时透明解密,再照常解析 明文 YAML。明文(未加密)配置文件原样加载。
源码: config/config.go:393-460 · v1.19.27 (5184081)
