使用 dig 和 nslookup 诊断 DNS
使用 dig、nslookup 和 host 诊断 Linux 上的名称解析问题,检查 DNS 记录、追踪解析路径并发现配置错误。
使用 dig 和 nslookup 诊断 DNS 是 CoddyKit 上的免费 Linux Networking & TCP/IP for Developers 课时。 这是第 4 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 Linux Networking & TCP/IP for Developers 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 Linux Networking & TCP/IP for Developers 课程共包含 4 节课。
本课时的部分内容尚未翻译,以英文显示。
Why DNS Diagnostics Matter
Many 'network is down' reports are really DNS failures. The host is reachable by IP, but the name will not resolve.
Linux ships tools to inspect resolution directly:
dig— flexible, scriptable lookupsnslookup— classic interactive toolhost— quick one-line answers
This lesson focuses on reading their output to find the real problem.
A Basic dig Query
Run dig followed by a hostname to fetch its A record.
The key part of the output is the ANSWER SECTION, which lists the resolved addresses and their TTL.
dig example.comReading the dig Answer Section
Each answer line shows: name TTL class type value.
- TTL — seconds the record may be cached
- type — A, AAAA, MX, CNAME, etc.
- value — the resolved data
Use +short to strip everything except the value.
dig +short example.comQuerying Specific Record Types
Append the record type to look up anything besides an A record.
dig example.com MX— mail serversdig example.com AAAA— IPv6dig example.com TXT— text records (SPF, verification)
dig example.com MXChoosing a Specific Resolver
Use @server to bypass your local resolver and ask a specific DNS server. This isolates whether your local cache is the problem.
Below queries Google Public DNS directly.
dig @8.8.8.8 example.comTracing the Resolution Path
dig +trace walks from the root servers down to the authoritative server, printing each delegation step.
This reveals broken delegations or stale glue records that a normal query hides.
dig +trace example.comReverse DNS Lookups
To map an IP back to a name, use -x. This queries the PTR record.
Missing PTR records often cause mail delivery and logging issues.
dig -x 8.8.8.8Using nslookup Interactively
nslookup can run one-shot or interactively. In interactive mode you set type= and switch servers with server.
nslookup -type=MX example.comQuick Answers with host
host gives compact output, ideal for quick checks.
host example.com— A and AAAAhost -t NS example.com— nameservers
host -t NS example.comInterpreting Status Codes
The status field in the dig header is critical:
- NOERROR — resolved fine
- NXDOMAIN — name does not exist
- SERVFAIL — server failed (often DNSSEC or upstream issues)
Checking the Local Resolver Config
Linux resolution settings live in /etc/resolv.conf and /etc/nsswitch.conf.
If dig works but applications fail, suspect nsswitch.conf ordering or a stale resolv.conf.
cat /etc/resolv.confQuick Check
Test your understanding of dig output.
Recap
You now diagnose DNS issues directly:
digfor flexible, scriptable lookups and+trace@serverto isolate resolver problems-xfor reverse lookups- Read status codes (NOERROR/NXDOMAIN/SERVFAIL)
- Check
/etc/resolv.confandnsswitch.conffor local issues
These skills complement packet capture and firewall analysis for end-to-end troubleshooting.
用 AI 导师学习 Linux Networking & TCP/IP for Developers — 免费
在浏览器中编写并运行真实代码,获得全天候 AI 导师的即时帮助,并在网页或应用中继续学习。
- 课程
- 12
- 课程
- 48
常见问题解答
「使用 dig 和 nslookup 诊断 DNS」课时是免费的吗?
是的 — 「使用 dig 和 nslookup 诊断 DNS」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 Linux Networking & TCP/IP for Developers 课程的其余内容,请升级到 CoddyKit PRO。 Linux Networking & TCP/IP for Developers 课程共包含 4 节课。
「使用 dig 和 nslookup 诊断 DNS」这节课中我会学到什么?
使用 dig、nslookup 和 host 诊断 Linux 上的名称解析问题,检查 DNS 记录、追踪解析路径并发现配置错误。 你通过在浏览器中直接运行的动手代码来练习 Linux Networking & TCP/IP for Developers,全天候 AI 导师会在你学习这节课的过程中回答你的问题。
学习 Linux Networking & TCP/IP for Developers 需要有经验吗?
无需任何先前经验。CoddyKit 上的 Linux Networking & TCP/IP for Developers 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 4 节课,共 4 节。
「使用 dig 和 nslookup 诊断 DNS」课时需要多长时间?
大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。
我能在这节 Linux Networking & TCP/IP for Developers 课中编写并运行代码吗?
能。每节 Linux Networking & TCP/IP for Developers 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。
此课程中的所有课时
- 使用 Wireshark/tcpdump 抓包
- 网络性能工具
- Linux 防火墙(Netfilter/iptables)
- 使用 dig 和 nslookup 诊断 DNS