萬盛學電腦網

您现在的位置: 萬盛學電腦網 >> 網路安全 >  >> 網路基礎知識

nslookup 命令完整指南:DNS 診斷、互動/非互動模式、錯誤碼對照表

nslookup 是診斷 DNS 基礎設施的核心工具,支援互動與非互動模式。前提:已安裝 TCP/IP 協議。當網路禁用 ping/telnet 時,nslookup 仍可分析域名解析路徑。

語法與參數

nslookup [-SubCommand ...] [{ComputerToFind | [-Server]}]
  • -SubCommand:指定子命令 (如 set type=mx、ls、finger)。
  • ComputerToFind:查詢目標主機名或 IP。若非當前 DNS 域,需加尾點 (如 example.com.)。
  • -Server:指定 DNS 伺服器,省略則用預設。

兩種模式

非互動模式 (單次查詢)

nslookup www.example.com [dns-server]

互動模式 (連續查詢/調試)

nslookup [-] [dns-server]
> set type=mx
> example.com
> server 8.8.8.8
> www.google.com
> exit

互動模式技巧:Ctrl+B 中斷、exit 退出、\command 轉義內建命令。

常見錯誤訊息對照

錯誤訊息原因對策
Timed outDNS 伺服器超時無回應set timeout 增加超時 / set retry 增加重試
No response from server目標主機未運行 DNS 服務確認埠 53 開放、服務啟動
No records域名存在但無該類型記錄set querytype 切換類型 (A/AAAA/MX/NS/TXT/CNAME)
Non-existent domain域名不存在檢查拼字、域名註冊狀態
Connection refused / Network unreachable無法建立 TCP/ UDP 53 連線檢查防火牆、路由、ACL
Server failureDNS 伺服器內部錯誤查看伺服器日誌、聯繫管理員
RefusedDNS 伺服器拒絕服務 (如遞歸查詢未授權)使用授權伺服器或授權區域查詢
Format error查詢封包格式錯誤檢查 nslookup 版本/參數語法

實戰範例

C:\> nslookup
Default Server: dns.example.com
Address: 192.168.1.1

> sina.com.cn
Server: dns.example.com
Address: 192.168.1.1

Non-authoritative answer:
Name: sina.com.cn
Address: 218.30.66.101

輸出說明:Default Server/Address 為當前使用的 DNS;Non-authoritative answer 表示非授權回應 (快取);Name/Address 為查詢結果。

進階用法

  • set debug / set d2:顯示完整 DNS 封包內容 (標頭、問題、回答、授權、附加區域)。
  • ls -d domain.com:列出域域傳送 (AXFR) 所有記錄 (需權限)。
  • set vc:強制使用 TCP 53 連線 (測試 TCP DNS 通道)。
  • root:查詢根域名伺服器。

nslookup 雖歷久彌新,但現代替代工具 dig (Domain Information Groper) 輸出更結構化、支援 DNSSEC、EDNS0、COOKIE 等擴展,建議並行掌握。

copyright © 萬盛學電腦網 all rights reserved