域名换了服务器,DNS 控制台显示「已生效」,ping 一下却是旧 IP。更邪门的是别的机器都正常,就你自己这台不行。
九成不是 DNS 没改对,而是某一层缓存还攥着旧记录。按「从外到内」查,一层层缩小范围。
第一步:确认权威服务器改没改
别信控制台的绿色对勾,直接从根开始追:
dig +trace example.com A
它依次问根服务器、顶级域、权威服务器,最后给出权威答案。最后一段是新 IP,说明上游改对了,问题在你这边;还是旧 IP,就是控制台没保存成功,或者改的是另一个记录。
只想看权威结果,可以直接指定 NS:
dig @ns1.yourdns.com example.com A +short
第二步:对比几个公共 DNS
dig @8.8.8.8 example.com A +short
dig @1.1.1.1 example.com A +short
dig @223.5.5.5 example.com A +short
dig @114.114.114.114 example.com A +short
有的返回新 IP、有的还是旧的,说明还在 TTL 传播期内。看一眼 TTL 就知道要等多久:
dig example.com A | grep -A1 "ANSWER SECTION"
TTL 3600 最长等一小时,86400 就是一天。改记录前先把 TTL 调小(比如 300),改完再调回去,能大幅减少等待。
第三步:清本机缓存
先看本机解析走哪条路:
resolvectl status
cat /etc/resolv.conf
systemd-resolved 清缓存:
sudo resolvectl flush-caches
跑着 nscd 或 dnsmasq 的:
sudo systemctl restart nscd
sudo systemctl restart dnsmasq
第四步:hosts 文件
这个坑最隐蔽——半年前为测试临时写的一行,早忘了:
cat /etc/hosts
grep example.com /etc/hosts
Windows 在 C:\Windows\System32\drivers\etc\hosts。
第五步:浏览器自己的缓存
系统清了、浏览器还记着,是「明明清了还是不行」的最常见原因。
- Chrome / Edge:
chrome://net-internals/#dns,点 Clear host cache - Firefox:
about:networking#dns,点 Clear DNS Cache
第六步:如果用了 CDN 代理
Cloudflare 这类服务有个经典误会:域名开着橙云时,dig 拿到的永远是 Cloudflare 的 IP,不是你的源站。
dig example.com A +short
# 104.x.x.x / 172.67.x.x 这类地址 = 走了代理
这时要改的是记录背后的源站,不是解析结果。验证源站直接指定 IP 测:
curl -I --resolve example.com:443:1.2.3.4 https://example.com
三平台清缓存速查
Windows: ipconfig /flushdns
macOS: sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder
Linux: sudo resolvectl flush-caches
按这个顺序走,一般三分钟能定位:先确认上游,再判断是否传播期,然后清本机缓存,最后查 hosts 和浏览器。四步里总有一层是答案,不用一上来就重启服务器。






















暂无评论内容