DNS 排查工具箱
High Contrast
Dark Mode
Light Mode
Sepia
Forest
2 min read383 words

DNS 排查工具箱

站点出问题,第一步是确认问题出在哪一层。DNS 层、网络层、应用层的问题,排查工具和思路完全不同。


工具速览

工具 类型 主要用途
dig 命令行 DNS 记录精确查询,可指定查询服务器
nslookup 命令行 DNS 查询(Windows 友好)
curl 命令行 HTTP 请求验证,检查状态码和响应头
ping 命令行 检查 IP 可达性
traceroute 命令行 网络路由追踪
openssl 命令行 SSL 证书检查
DNS Checker 在线 全球多地域 DNS 传播查看
MXToolbox 在线 邮件记录和黑名单检查
SSL Labs 在线 SSL 证书详细分析
Whatsmydns 在线 全球 DNS 传播可视化

dig:最强的 DNS 排查工具

dig(Domain Information Groper)是 DNS 排查的首选工具,Mac/Linux 内置,Windows 需要安装 BIND 工具集。

基本用法

# 查询 A 记录(默认)
dig example.com
# 查询特定记录类型
dig example.com MX
dig example.com TXT
dig example.com CNAME
dig example.com NS
dig example.com AAAA
# 指定 DNS 服务器(绕过本地缓存)
dig @8.8.8.8 example.com A    # 用 Google DNS
dig @1.1.1.1 example.com A    # 用 Cloudflare DNS
dig @208.67.222.222 example.com A  # 用 OpenDNS

精简输出

# 只显示答案(去掉其他信息)
dig example.com A +short
# → 104.21.3.5
# 查询多个记录,精简显示
dig example.com A +short
dig example.com MX +short

追踪解析路径

# 从根服务器开始追踪完整解析过程
dig example.com +trace

查询权威服务器(跳过缓存)

# 先找权威 NS
dig example.com NS +short
# → ns1.cloudflare.com
# 直接问权威服务器
dig @ns1.cloudflare.com example.com A

nslookup:Windows 友好的替代

# 基本查询
nslookup example.com
# 指定记录类型
nslookup -type=MX example.com
# 指定 DNS 服务器
nslookup example.com 8.8.8.8

curl:HTTP 层验证

# 检查 HTTP 状态码
curl -s -o /dev/null -w "%{http_code}" https://example.com
# 查看响应头
curl -I https://example.com
# 详细请求信息(包括 DNS 解析时间、连接时间)
curl -v https://example.com
# 测量各阶段耗时
curl -s -o /dev/null -w "
DNS: %{time_namelookup}s
Connect: %{time_connect}s
SSL: %{time_appconnect}s
First byte: %{time_starttransfer}s
Total: %{time_total}s
" https://example.com
# 强制指定 IP(测试新服务器,不走 DNS)
curl --resolve example.com:443:203.0.113.6 https://example.com

openssl:SSL 证书检查

# 查看证书详情
echo | openssl s_client -connect example.com:443 -servername example.com 2>/dev/null | openssl x509 -noout -text
# 只查有效期
echo | openssl s_client -connect example.com:443 -servername example.com 2>/dev/null | openssl x509 -noout -dates
# 查看完整证书链
echo | openssl s_client -connect example.com:443 -servername example.com 2>/dev/null | openssl x509 -noout -issuer -subject

在线工具推荐

工具 地址 最适合
DNS Checker dnschecker.org 查 DNS 全球传播状态
MXToolbox mxtoolbox.com/SuperTool.aspx 邮件记录综合检查
SSL Labs ssllabs.com/ssltest SSL 证书详细评分
Whois Lookup who.is 域名注册信息
DNSViz dnsviz.net DNS 链路可视化
Down For Everyone downforeveryoneorjustme.com 快速确认是否全球宕机

下一节常见故障场景分析——网站打不开、SSL 报错、邮件退回,各类故障的根因分析。