用 dig 查询 DNS 记录

查询域名的任意 DNS 记录类型,既可以输出精简结果,也可以查看包含报文头和 TTL 的完整应答。

Linux网络DNS诊断低风险
执行 dig example.com A +short,即可用简洁列表获取 example.com 的 IPv4 地址。

01命令

命令
$ dig example.com A +short

02作用说明

默认输出很详细,包含 QUESTION、ANSWER、SERVER 各部分和 TTL,适合排查问题;加 +short 则只输出结果值。通过第二个参数指定记录类型:dig example.com MX +short、dig example.com TXT +short,IPv6 用 AAAA。用 @ 可指定 DNS 服务器:dig example.com @1.1.1.1——这是区分「缓存问题」和「解析未生效」的关键技巧,因为默认解析器可能缓存了旧答案。反向解析使用 dig -x 1.2.3.4。

03风险

风险低风险
使用条件dig comes from the bind9-dnsutils (Debian/Ubuntu) or bind-utils (Fedora/RHEL) package

04撤销

✓无需撤销——该命令不会改变持久状态。

05来源

  • dig(1) — DNS lookup utility
    Ubuntu manpages · vendor-doc · 2026-09-17
    依据: The dig manual documents querying a name for a given type (A, MX, etc.) and the +short option to print a terse answer.

最后验证: 2026-09-17 · 分类: 网络

06相关方案