Skip to content

基础

本页讲解 YAML 文档的扁平顶层键 —— 监听端口、访问控制、网络标志与 路由模式选择。它们都直接位于 RawConfig 上,并在 config/config.go 中接入运行时。

选项

字段类型默认值允许值描述
portint00 | <port>HTTP 代理监听端口。0 禁用。
socks-portint00 | <port>SOCKS5 监听端口。0 禁用。
redir-portint00 | <port>Linux REDIRECT 入站端口(iptables NAT)。0 禁用。
tproxy-portint00 | <port>Linux TPROXY 入站端口(iptables mangle)。0 禁用。
mixed-portint00 | <port>同一监听器上复用 HTTP 与 SOCKS5 的端口。0 禁用。
inbound-tfoboolfalsetrue | false在入站监听器上启用 TCP Fast Open(仅 Linux)。
inbound-mptcpboolfalsetrue | 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-lanboolfalsetrue | false把监听器绑定到 0.0.0.0 / :: 而不是 127.0.0.1。
bind-addressstring** | <address>覆盖绑定地址;* 表示按 `allow-lan` 选择。
modeT.TunnelModerulerule | global | direct隧道决策策略。`rule` 走规则列表;`global` 一律送往 GLOBAL;`direct` 完全绕过代理。
unified-delayboolfalsetrue | false从 URL 测试延迟中扣除 TLS 握手时间,便于跨代理公平比较。
ipv6boolfalsetrue | falseIPv6 总开关。为 false 时过滤 AAAA 记录并禁用 IPv6 路由。
interface-namestring(auto)<interface>把所有出站拨号绑定到该接口(例如 eth0)。
routing-markint0<uint32>出站套接字上设置的 Linux SO_MARK。0 禁用。
tcp-concurrentboolfalsetrue | false对每条连接并发拨号 A 与 AAAA,谁先连上用谁(Happy Eyeballs 风格)。
find-process-modeprocess.FindProcessModestrictstrict | always | off为路由(`PROCESS-NAME` 规则)查找发起进程的力度。
global-client-fingerprintstring(removed)<utls fingerprint>已移除并被忽略。请改为在每个代理上直接设置 `client-fingerprint`。
global-uastringclash.meta/<version><string>订阅与资源下载的默认 User-Agent。
etag-supportbooltruetrue | false重新拉取订阅 URL 时遵循 ETag 头。
keep-alive-idleint0<seconds>TCP keepalive 空闲时长。0 使用操作系统默认。
keep-alive-intervalint0<seconds>TCP keepalive 探测间隔。0 使用操作系统默认。
disable-keep-aliveboolfalsetrue | 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 互不冲突 —— 三者可以同时开放, 但在 portmixed-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)

由 Argsment 出品的 Core Tutorial