验证DNS改完是否生效,需用dig + curl组合:dig +short测解析IP与GSLB,curl -w测time_namelookup(应≤0.02s)、connect和total耗时,并排除systemd-resolved干扰。

怎么验证DNS改完有没有效果
改完 /etc/resolv.conf 或 hosts 后,不能只看 composer install 快没快——它夹杂 autoload、解压、脚本执行等干扰项。真正测 DNS 优化是否生效,得剥离 Composer 逻辑,直接测域名解析耗时和 HTTPS 连通性。
用 dig + curl 组合验证 DNS 解析与首包延迟
先确认 DNS 是否真变快、是否命中边缘节点:
-
dig +short mirrors.aliyun.com:看返回 IP 是否合理(如223.6.6.6),且不同地区结果是否不同(验证 GSLB 是否启用) -
curl -o /dev/null -s -w "%{time_namelookup}s %{time_connect}s %{time_total}s" https://mirrors.aliyun.com/composer/ --connect-timeout 5 --max-time 10:三个时间分别代表 DNS 解析、TCP+TLS 建连、总耗时;time_namelookup降到 0.02s 以内才算 DNS 优化到位 - 必须加
--connect-timeout 5,否则弱网下会卡在 DNS 后无限等待;--max-time 10防止 TLS 握手失败拖太久
为什么 ping 不准,而 curl -I 更可靠
ping packagist.org 只测 ICMP,但 Composer 走的是 HTTPS,中间可能被防火墙拦截、TLS 证书校验失败或 CDN 拒绝非 User-Agent 请求。常见错误:
围绕关键发现、作用机制、临床相关性及研究局限性展开讨论。适用于撰写或优化任何生物医学论文的“讨论(Discussion)”部分——包括结果解读、与既往文献关联、阐释意外发现、界定研究局限性,以及撰写结论。当用户输入以下任一指令时也会自动触发该功能: - “write my discussion” - “help me discuss my findings” - “how do I compare to prior studies” - “write the limitations par
-
ping通但curl -I https://mirrors.aliyun.com卡住 → 很可能是 TLS 握手被运营商干扰或证书链不完整 -
curl -I返回403→ 镜像源要求特定User-Agent,需加-H "User-Agent: Composer/2.7.0" -
curl -I返回200但Content-Type: text/html→ 实际是反爬跳转页,不是真实镜像响应,不可用
别漏掉 systemd-resolved 的静默覆盖
很多 Linux 发行版(Ubuntu 20.04+、Fedora)默认启用 systemd-resolved,它会偷偷接管 /etc/resolv.conf 并注入自己的 stub 地址(如 127.0.0.53),导致你手动写的 nameserver 完全不生效。
检查方式:systemctl is-active systemd-resolved;若输出 active,必须执行:sudo systemctl disable --now systemd-resolved,再手动写死 /etc/resolv.conf。否则所有 DNS 优化都白做。

















