用于排除 DNS 查找故障的 8 个 Linux Nslookup 命令
nslookup 是一个命令行管理工具,用于测试 DNS 服务器(域名服务器)并进行故障排除。它还用于查询特定的 DNS 资源记录 (RR)。大多数操作系统都带有内置的 nslookup 功能。
本文详细演示了广泛使用的 nslookup 命令。 Nslookup 可以以两种模式运行:交互式和非交互式。
交互模式用于查询DNS服务器有关各种域和主机的信息。 非交互模式用于查询域或主机的信息。
您可能还对以下文章感兴趣:
- Linux Find 命令的 35 个实用示例
- Linux 网络管理的 20 个 Netstat 命令
- 20 个用于包管理的 Linux YUM(Yellowdog Updater,修改版)命令
- Linux 中用于 RPM 包管理的 27 个“DNF”(Yum 分支)命令
1. 找出域名的“A”记录(IP地址)
# nslookup yahoo.com
Server: 4.2.2.2
Address: 4.2.2.2#53
Non-authoritative answer:
Name: yahoo.com
Address: 72.30.38.140
Name: yahoo.com
Address: 98.139.183.24
Name: yahoo.com
Address: 209.191.122.70
上面的命令查询域www.yahoo.com与4.2.2.2公共DNS服务器,下面部分显示非权威答案:显示 www.yahoo.com 的一条记录
2.找出反向域名查找
# nslookup 209.191.122.70
Server: 4.2.2.2
Address: 4.2.2.2#53
Non-authoritative answer:
70.122.191.209.in-addr.arpa name = ir1.fp.vip.mud.yahoo.com.
Authoritative answers can be found from:
3. 找出特定的域名查找。
# nslookup ir1.fp.vip.mud.yahoo.com.
Server: 4.2.2.2
Address: 4.2.2.2#53
Non-authoritative answer:
Name: ir1.fp.vip.mud.yahoo.com
Address: 209.191.122.70
4. 查询MX(邮件交换)记录。
# nslookup -query=mx www.yahoo.com
Server: 4.2.2.2
Address: 4.2.2.2#53
Non-authoritative answer:
www.yahoo.com canonical name = fd-fp3.wg1.b.yahoo.com.
fd-fp3.wg1.b.yahoo.com canonical name = ds-fp3.wg1.b.yahoo.com.
ds-fp3.wg1.b.yahoo.com canonical name = ds-any-fp3-lfb.wa1.b.yahoo.com.
ds-any-fp3-lfb.wa1.b.yahoo.com canonical name = ds-any-fp3-real.wa1.b.yahoo.com.
Authoritative answers can be found from:
wa1.b.yahoo.com
origin = yf1.yahoo.com
mail addr = hostmaster.yahoo-inc.com
serial = 1344827307
refresh = 30
retry = 30
expire = 86400
minimum = 1800
MX 记录用于将域名映射到该域的邮件交换服务器列表。这样它就表明无论接收/发送到 @yahoo.com 的邮件都将被路由到邮件服务器。
5. 查询NS(Name Server)记录。
# nslookup -query=ns www.yahoo.com
Server: 4.2.2.2
Address: 4.2.2.2#53
Non-authoritative answer:
www.yahoo.com canonical name = fd-fp3.wg1.b.yahoo.com.
fd-fp3.wg1.b.yahoo.com canonical name = ds-fp3.wg1.b.yahoo.com.
ds-fp3.wg1.b.yahoo.com canonical name = ds-any-fp3-lfb.wa1.b.yahoo.com.
ds-any-fp3-lfb.wa1.b.yahoo.com canonical name = ds-any-fp3-real.wa1.b.yahoo.com.
Authoritative answers can be found from:
wa1.b.yahoo.com
origin = yf1.yahoo.com
mail addr = hostmaster.yahoo-inc.com
serial = 1344827782
refresh = 30
retry = 30
expire = 86400
minimum = 1800
6. 查询SOA(Start of Authority)记录。
# nslookup -type=soa www.yahoo.com
Server: 4.2.2.2
Address: 4.2.2.2#53
Non-authoritative answer:
www.yahoo.com canonical name = fd-fp3.wg1.b.yahoo.com.
fd-fp3.wg1.b.yahoo.com canonical name = ds-fp3.wg1.b.yahoo.com.
ds-fp3.wg1.b.yahoo.com canonical name = ds-any-fp3-lfb.wa1.b.yahoo.com.
ds-any-fp3-lfb.wa1.b.yahoo.com canonical name = ds-any-fp3-real.wa1.b.yahoo.com.
Authoritative answers can be found from:
wa1.b.yahoo.com
origin = yf1.yahoo.com
mail addr = hostmaster.yahoo-inc.com
serial = 1344827965
refresh = 30
retry = 30
expire = 86400
minimum = 1800
7. 查询所有可用的DNS记录。
# nslookup -query=any yahoo.com
Server: 4.2.2.2
Address: 4.2.2.2#53
Non-authoritative answer:
yahoo.com
origin = ns1.yahoo.com
mail addr = hostmaster.yahoo-inc.com
serial = 2012081016
refresh = 3600
retry = 300
expire = 1814400
minimum = 600
Name: yahoo.com
Address: 98.139.183.24
Name: yahoo.com
Address: 209.191.122.70
Name: yahoo.com
Address: 72.30.38.140
yahoo.com mail exchanger = 1 mta7.am0.yahoodns.net.
yahoo.com mail exchanger = 1 mta5.am0.yahoodns.net.
yahoo.com mail exchanger = 1 mta6.am0.yahoodns.net.
yahoo.com nameserver = ns3.yahoo.com.
yahoo.com nameserver = ns4.yahoo.com.
yahoo.com nameserver = ns2.yahoo.com.
yahoo.com nameserver = ns8.yahoo.com.
yahoo.com nameserver = ns1.yahoo.com.
yahoo.com nameserver = ns6.yahoo.com.
yahoo.com nameserver = ns5.yahoo.com.
Authoritative answers can be found from:
8. 启用调试模式
要启用调试模式,“设置调试”将返回详细信息,例如TTL,这是输出。
# nslookup -debug yahoo.com
> set debug
> yahoo.com
Server: 4.2.2.2
Address: 4.2.2.2#53
------------
QUESTIONS:
yahoo.com, type = A, class = IN
ANSWERS:
-> yahoo.com
internet address = 72.30.38.140
ttl = 1523
-> yahoo.com
internet address = 98.139.183.24
ttl = 1523
-> yahoo.com
internet address = 209.191.122.70
ttl = 1523
AUTHORITY RECORDS:
ADDITIONAL RECORDS:
------------
Non-authoritative answer:
Name: yahoo.com
Address: 72.30.38.140
Name: yahoo.com
Address: 98.139.183.24
Name: yahoo.com
Address: 209.191.122.70
在本文中,我们尝试介绍 nslookup 命令,这些命令可以帮助您搜索 (DNS) 域名服务相关信息。
下一篇文章将介绍Linux dig 命令,该命令类似于nslookup。如果您喜欢这篇文章,请与您的朋友分享,并且不要忘记通过评论框提供您宝贵的反馈。