Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Windows 綜合教學 >> 系統指令

nslookup 指令詳解:DNS 疑難排解與網域查詢實戰

編輯:系統指令

nslookup 是 Windows/Linux 內建的 DNS 查詢工具,可驗證正向/反向解析、指定查詢類型、指定 DNS 伺服器、模擬遞迴解析流程,是網管排查網域解析問題的必備指令。

基本用法

nslookup [選項] [網域名|IP] [DNS伺服器]

1. 查詢 IP 位址 (A/AAAA/CNAME 記錄)

nslookup www.example.com
# 顯示使用的 DNS 伺服器、網域 IP、CNAME 別名資訊

2. 反向查詢 (PTR 記錄)

nslookup 192.168.1.100
# 由 IP 解析對應主機名

3. 指定查詢類型 (-qt=type)

nslookup -qt=mx example.com      # 郵件伺服器記錄
nslookup -qt=ns example.com      # 名稱伺服器記錄
nslookup -qt=txt example.com     # 文字記錄 (SPF/DMARC 等)
nslookup -qt=soa example.com     # 授權起始記錄
nslookup -qt=any example.com     # 所有記錄類型

常見記錄類型: A, AAAA, CNAME, MX, NS, PTR, TXT, SOA, SRV, CAA, DS, DNSKEY。

4. 指定 DNS 伺服器

nslookup www.example.com 8.8.8.8           # 使用 Google DNS
nslookup -qt=mx example.com ns1.example.com  # 直接查詢授權伺服器

5. 除錯模式 (-d / -d2)

nslookup -d www.example.com
# 顯示完整 DNS 封包:Header, Question, Answer, Authority, Additional、TTL 值

6. 關閉遞迴查詢 (-norecurse)

nslookup -norecurse www.example.com a.root-servers.net
# 模擬根伺服器 → 頂級域伺服器 → 授權伺服器的逐層解析流程

進階排查場景

現象可能原因排查指令
解析失敗:Non-existent domain區域檔缺少記錄、序號未增、同步延遲nslookup -qt=any domain.com @auth-ns
找不到 DNS 伺服器:No response from server網路不通、DNS 服務掛掉、防火牆封鎖 53 埠ping DNS_IP; telnet DNS_IP 53
解析結果不一致快取未失效、分割視圖、劫持nslookup domain.com @不同DNS; 比對 TTL
郵件收發異常MX 記錄錯誤、優先級設定、SPF/DKIM 缺失nslookup -qt=mx domain.com; nslookup -qt=txt domain.com
驗證 DNSSEC需支援 DNSSEC 的解析器nslookup -qt=dnskey domain.com; dig +dnssec

互動模式

nslookup
> set type=mx
> example.com
> server 8.8.8.8
> example.com
> exit

替代工具

  • dig (Domain Information Groper):Linux 標準工具,輸出結構化、支援 DNSSEC、多查詢、+trace 追蹤完整解析鏈。
  • host:簡易查詢,適合腳本。
  • PowerShell Resolve-DnsName:Windows 現代化 Cmdlet,物件導向輸出。
  • 線上工具:MXToolbox, DNSChecker, Google Dig, ICANN Lookup。

熟練 nslookup 各類查詢模式,能快速定位 DNS 解析故障、驗證記錄部署、排查快取與劫持問題。建議網管建立常用查詢腳本,納入日常巡檢流程。

Copyright © Windows教程網 All Rights Reserved