nslookup命令
时间:2020-03-05 15:29:05 来源:igfitidea点击:
我们可以使用NSLookup查询DNS并获取,名称服务器,域名等的IP地址等信息。
Linux中NSLookup命令的示例
让我向我们展示NSLookup命令的一些示例。
1.获取的IP地址
在其最简单的表单中,没有任何选项,NSLookup返回域名和IP地址(IPv4和IPv6)。
最受欢迎的nslookup之一是使用此方法获取Linux中的IP地址。
nslookup <URL>
这是一个示例输出:
nslookup theitroad.com Server: 127.0.0.53 Address: 127.0.0.53#53 Non-authoritative answer: Name: theitroad.com Address: 142.93.143.135 Name: theitroad.com Address: fd00:0:12:13::8e5d:8f87
上面的命令输出中的127.0.0.53地址是我自己的系统的DNS由SystemD设置。
在某些情况下,它可能是8.8.8.8等。
What is non-authoritative answer? In the output of nslookup command, you’ll often notice ‘non-authoritative answer’. It means that the answer you got for your DNS query is coming for a non-authoritative source. It’s because when you use nslooku, the answer is not coming directly from the name server of the server you are querying. Mostly it comes from your internet service provider’s name server.
2.获取名称服务器(NS记录)
我们还可以显示与具有NSLookup与域关联的名称服务器。
这些名称服务器存储各种DNS相关记录。
通常,域具有多个名称服务器,用于备份目的。
要显示名称服务器,我们需要做的就是指定NSLookup查询的类型:
nslookup -type=ns <URL>
Linux手册的示例输出是:
nslookup -type=ns theitroad.com Server: 127.0.0.53 Address: 127.0.0.53#53 Non-authoritative answer: theitroad.com nameserver = dns2.registrar-servers.com. theitroad.com nameserver = dns1.registrar-servers.com. Authoritative answers can be found from:
3.显示MX记录
DNS中的MX记录指定域名的邮件服务器设置。
这确定了哪些邮件服务器处理所讨论的域的电子邮件。
nslookup -type=mx <URL>
示例输出可能是这样的:
nslookup -type=mx itstheitroad.com Server: 127.0.0.53 Address: 127.0.0.53#53 Non-authoritative answer: itstheitroad.com mail exchanger = 5 alt2.aspmx.l.google.com. itstheitroad.com mail exchanger = 1 aspmx.l.google.com. itstheitroad.com mail exchanger = 10 alt3.aspmx.l.google.com. itstheitroad.com mail exchanger = 5 alt1.aspmx.l.google.com. itstheitroad.com mail exchanger = 10 alt4.aspmx.l.google.com. Authoritative answers can be found from:
请注意,有时,邮件服务器设置未定义,在这些情况下,使用nslookup的mx查询可以返回这样的输出:
nslookup -type=mx theitroad.com Server: 127.0.0.53 Address: 127.0.0.53#53 Non-authoritative answer: *** Can’t find theitroad.com: No answer Authoritative answers can be found from:
4.使用nslookup获取SOA录制
我们可以通过指定查询类型来查询和显示使用NSLookup的SOA(启动权限)记录:
nslookup -type=soa <URL>
示例输出将是这样的:
nslookup -type=soa theitroad.com Server: 127.0.0.53 Address: 127.0.0.53#53 Non-authoritative answer: theitroad.com origin = dns1.registrar-servers.com mail addr = hostmaster.registrar-servers.com serial = 2019051520 refresh = 43200 retry = 3600 expire = 604800 minimum = 3601 Authoritative answers can be found from:
我们可以阅读此处SOA记录的各种属性。
5.使用NSLookup显示所有DNS记录
我们可以使用任何选项在一个命令中显示所有上述记录(已设置)。
nslookup -type=any <URL>
我们将看到所有上述命令的统一输出:
nslookup -type=any theitroad.com Server: 127.0.0.53 Address: 127.0.0.53#53 Non-authoritative answer: theitroad.com origin = dns1.registrar-servers.com mail addr = hostmaster.registrar-servers.com serial = 2019051520 refresh = 43200 retry = 3600 expire = 604800 minimum = 3601 theitroad.com nameserver = dns1.registrar-servers.com. theitroad.com nameserver = dns2.registrar-servers.com. Name: theitroad.com Address: 142.93.143.135 Authoritative answers can be found from:
6.反向DNS查找
到目前为止,我们已经查询了某个域的DNS并获得了IP地址。
我们可以执行反向DNS查找并搜索与IP地址关联的域名。
nslookup <IP_ADDRESS>
例如,如果我在Linux手册的服务器上使用NSLookup进行反向DNS查找,那就是我得到的答案:
nslookup 142.91.143.135 135.143.91.142.in-addr.arpa name = www.baidu.com. Authoritative answers can be found from:
7.使用NSLookup查询特定的DNS服务器端口
DNS服务器使用TCP协议,因此默认使用端口53.
如果DNS服务器使用了其他一些端口,则可以使用nslookup指定查询中的端口:
nslookup -port=<Port_Number> <URL>