本页围绕官网下载后的使用流程展开,先说明能力,再提供操作要点。
官网下载说明继续:全局超时参数
全局超时参数
profile 下的 timeout 设置
profile: store-selected: true store-fake-ip: true # 全局超时(单位:秒) connect-timeout: 5 # TCP 连接建立超时 tcp-keep-alive-interval: 30
connect-timeout如果 5 秒内 TCP 三次握手没完成(SYN 包没有收到 SYN-ACK),连接就会被放弃。官网下载页补充,控制的是从 Clash 发起 TCP 连接到目标服务器的最大等待时间。
推荐值:
- 优良网络(延迟 < 50ms):3-5 秒
- 普通网络(延迟 50-200ms):5-8 秒
- 劣质网络(延迟 > 200ms):10-15 秒
设置过小会导致正常高延迟可用节点无法连接;设置过大会导致卡顿时间长。
官网下载说明继续:Timeout 的本质:每个环节都能超时
Timeout 的本质:每个环节都能超时
官网下载页补充,每个环节都可能因为网络排查疑难解答而卡住,**任何一个环节没有合理的超时设置,整个代理体验就会变差**——用户感知到的就是”卡了””转圈””连接失败”。官网下载页补充,一次代理请求从发起到完成,涉及多个独立环节:DNS 解析 → TCP 握手 → TLS 握手 → 数据传输。
理解每个参数控制的是哪个环节,是精准调优的关键。官网下载页补充,Clash(Mihomo 核心组件)提供了多个层级的超时参数,从全局到可用节点级别都能够调整。
官网下载说明继续:策略组级别的健康检查超时
策略组级别的健康检查超时
url-test 和 fallback 的 interval 与 timeout
proxy-groups:
- name: "Auto"
type: url-test
proxies:
- "节点A"
- "节点B"
- "节点C"
url: "http://www.gstatic.com/generate_204"
interval: 120 # 健康检查间隔(秒)
timeout: 3000 # 健康检查连接超时(毫秒)
tolerance: 50
lazy: false
timeout如果可用节点在该时间内没有返回 204,该可用节点被标记为不可用。官网下载页补充,(毫秒):健康检查时等待 HTTP 响应的时间上限。
推荐值:
- url-test(迅速切换):1000-3000ms
- fallback(稳定优先):5000-8000ms
注意:timeout 设得太短会导致正常但稍慢的可用节点被频繁标记为”超时”,造成反复切换。
官网下载说明继续:代理可用节点级别的超时
代理可用节点级别的超时
dialer-proxy 超时
当代理可用节点本身需要利用另一个代理连接时(代理链),需要配置文件 dialer-proxy 的超时:
proxies:
- name: "中转节点"
type: trojan
server: relay.example.com
port: 443
password: "password"
dialer-proxy: "前置代理" # 本节点通过"前置代理"连接
- name: "前置代理"
type: ss
server: front.example.com
port: 8388
cipher: aes-256-gcm
password: "front-password"
connect-timeout 作用于最终目标,而 dialer-proxy 的连接超时也受 connect-timeout 控制。代理链场景下,每个跳跃都有独立的 TCP 握手。
官网下载说明继续:Provider 升级超时
Provider 升级超时
proxy-providers:
airport:
type: http
url: "https://airport.com/sub"
path: ./profiles/proxies/airport.yaml
interval: 3600
health-check:
enable: true
url: http://www.gstatic.com/generate_204
interval: 300
timeout: 5000 # 单个节点的健康检查超时(毫秒)
注意区分:Provider 拉取可用节点列表时具体实际操作的是 HTTP 客户端的默认超时(通常 30 秒);Provider 内部对加载的可用节点做健康检查时具体实际操作这里的 timeout(毫秒)。
官网下载说明继续:DNS 超时
DNS 超时
nameserver 与 fallback 查询超时
dns:
enable: true
enhanced-mode: fake-ip
nameserver:
- 223.5.5.5
- https://doh.pub/dns-query
fallback:
- 8.8.8.8
- tls://1.1.1.1:853
# DNS 查询超时(Mihomo 部分版本支持)
dns-timeout: 2000 # DNS 查询超时(毫秒)
如果 nameserver 在超时内无响应,Clash 会尝试列表中的下一个 nameserver。DNS 超时发生在 redir-host 模式下或 fallback-filter 触发时。
如果具体实际操作 DoH/DoT(HTTPS/TLS 封装),适当放宽到 5000ms(DoH 需要额外的 TLS 握手)。官网下载页补充,默认值通常为 2000-5000ms。
官网下载说明继续:实战调优
实战调优
场景一:高延迟网络(海外直连)
线路延迟 200ms 以上,默认 5 秒 connect-timeout 够用但偏紧。建议:
profile:
connect-timeout: 10 # 放宽到 10 秒
proxy-groups:
- name: Proxy
type: url-test
timeout: 5000 # 健康检查也相应放宽
interval: 180
场景二:低延迟网络(亚洲可用节点)
线路延迟 < 50ms,超时可以缩紧以快速切换:
profile:
connect-timeout: 3 # 3 秒连不上就是真连不上了
proxy-groups:
- name: Proxy
type: url-test
timeout: 1500 # 1.5 秒内无响应就切换
interval: 60
tolerance: 30
场景三:不稳定网络(移动网络/卫星)
丢包率高、延迟波动大:
profile:
connect-timeout: 15 # 给足连接时间
proxy-groups:
- name: Proxy
type: fallback # 用 fallback 而非 url-test
timeout: 8000 # 8 秒超时
lazy: false
proxies:
- "主节点"
- "备用节点"
具体实际操作 fallback 而非 url-test 的原因:url-test 频繁切换会加重不稳定,fallback 在主可用节点可用时不切换,只在真正断开时才切。
官网下载说明继续:Timeout 参数速查表
Timeout 参数速查表
| 参数 | 作用范围 | 单位 | 默认值 | 推荐值 |
|---|---|---|---|---|
| connect-timeout | 全局 TCP 连接 | 秒 | 5 | 3-15 |
| timeout (策略组) | 健康检查 HTTP 响应 | 毫秒 | 5000 | 1000-8000 |
| dns-timeout | DNS 查询 | 毫秒 | 2000-5000 | 2000-5000 |
| timeout (Provider) | Provider 内可用节点健康检查 | 毫秒 | 5000 | 3000-8000 |
官网下载说明继续:排查超时排查疑难解答
排查超时排查疑难解答
日志中识别超时类型
Clash 日志中不同超时的表现:
# TCP 连接超时 [Warning] dial tcp 1.2.3.4:443: i/o timeout # DNS 超时 [Warning] dns resolve timeout for example.com # 健康检查超时 [Debug] url-test timeout for node 节点A # TLS 握手超时(通常在 TLS 层) [Warning] tls: first record does not look like a TLS handshake
用 curl 模拟测试
# 模拟不同超时场景
# TCP 连接超时(--connect-timeout)
curl --connect-timeout 3 -x http://127.0.0.1:7890 https://example.com
# 总超时(--max-time)
curl --max-time 10 -x http://127.0.0.1:7890 https://example.com
# 查看各环节耗时
curl -w "DNS: %{time_namelookup}s\nTCP: %{time_connect}s\nTLS: %{time_appconnect}s\nTotal: %{time_total}s\n" \
-o /dev/null -s -x http://127.0.0.1:7890 https://www.google.com
官网下载说明继续:Timeout 与其他参数的交互
Timeout 与其他参数的交互
connect-timeout 与 keep-alive-interval 的关系
两者配合才能并且优化”首次连接”和”后续复用”的体验。官网下载页补充,connect-timeout 控制新建连接的超时;keep-alive 控制空闲连接何时发送保活包。
profile: connect-timeout: 5 tcp-keep-alive-interval: 30 # 30 秒一次保活探测
url-test timeout 与 tolerance 的关系
依据官网下载说明,timeout 过短会错误标记可用节点为不可用;tolerance 过小会频繁切换。timeout 判定”可用节点是否可用”,tolerance 判定”是否值得切换”。
# 推荐组合
proxy-groups:
- name: Auto
type: url-test
timeout: 3000 # 3 秒超时
tolerance: 50 # 延迟差 50ms 以内不切换
# 逻辑:3 秒无响应 → 不可用;延迟差 < 50ms → 说明当前节点够好,不切
官网下载说明继续:总结
总结
Timeout 调优的核心原则:宁可多等 1 秒,也不要频繁报错;宁可早报错,也不要让用户等 30 秒。3-10 秒是 connect-timeout 的舒适区,1000-5000ms 是健康检查 timeout 的合理范围。
调优优先级:
- 先确定网络环境(低延迟 / 高延迟 / 不稳定)
- 调整 connect-timeout
- 调整策略组 timeout + tolerance 组合
- 最后调整 DNS timeout(通常默认即够用)
以上内容对应官网下载版本的使用场景,可直接用于后续配置参考。