Linux 中的 nslookup 命令:7 个实际示例Linux 中的 nslookup 命令:7 个实际示例Linux 中的 nslookup 命令:7 个实际示例Linux 中的 nslookup 命令:7 个实际示例
  • 文章
  • 正则表达式
    • 工具
  • 登录
找到的结果: {phrase} (显示: {results_count} 共: {results_count_total})
显示: {results_count} 共: {results_count_total}

加载更多搜索结果...

搜索范围
模糊匹配
搜索标题
搜索内容
发表 admin at 2025年2月28日
类别
  • 未分类
标签

Linux 中的 nslookup 命令:7 个实际示例

nslookup 是 Linux 中流行的网络命令之一,用于查询域名系统 (DNS) 记录。了解如何使用 nslookup 命令。

您可以使用 ip 命令来获取自己的 Linux 系统的 IP 地址。但是网络服务或网站的 IP 地址又如何呢?

您可以使用 nslookup 查询 DNS 并获取网站的 IP 地址、名称服务器、域名等信息。

Linux 中 nslookup 命令的示例

让我向您展示 nslookup 命令的一些示例。

1. 获取网站的IP地址

nslookup 以其最简单的形式(不带任何选项)返回域名和 IP 地址(IPv4 和 IPv6)。 nslookup 最流行的用途之一是使用此方法获取 Linux 中网站的 IP 地址。

nslookup <URL>

这是一个示例输出:

nslookup linux教程
Server: 127.0.0.53
Address: 127.0.0.53#53

Non-authoritative answer:
Name: linux教程
Address: 142.93.143.135
Name: linux教程
Address: fd00:0:12:13::8e5d:8f87

上面命令输出中的127.0.0.53地址是我自己系统由systemd设置的DNS。在某些情况下,可能是 8.8.8.8 等。

❓
什么是非权威答案?
在 nslookup 命令的输出中,您经常会注意到“非权威答案”。这意味着您获得的 DNS 查询答案来自非权威来源。
这是因为当您使用 nslookup 时,答案不是直接来自您正在查询的服务器的名称服务器。它主要来自互联网服务提供商的名称服务器。

2. 获取名称服务器(NS记录)

您还可以使用 nslookup 仅显示与域关联的名称服务器。这些名称服务器存储各种与 DNS 相关的记录。通常,一个域有多个名称服务器用于备份目的。

要仅显示名称服务器,您所需要做的就是指定 nslookup 查询的类型:

nslookup -type=ns <URL>

Linux 手册网站的示例输出是:

nslookup -type=ns linux教程
Server: 127.0.0.53
Address: 127.0.0.53#53

Non-authoritative answer:
linux教程 nameserver = dns2.registrar-servers.com.
linux教程 nameserver = dns1.registrar-servers.com.

Authoritative answers can be found from:

3.显示MX记录

DNS 中的 MX 记录指定域名的邮件服务器设置。这确定哪个邮件服务器处理相关域的电子邮件。

nslookup -type=mx <URL>

示例输出可能如下所示:

nslookup -type=mx linux教程
Server: 127.0.0.53
Address: 127.0.0.53#53

Non-authoritative answer:
linux教程 mail exchanger = 5 alt2.aspmx.l.google.com.
linux教程 mail exchanger = 1 aspmx.l.google.com.
linux教程 mail exchanger = 10 alt3.aspmx.l.google.com.
linux教程 mail exchanger = 5 alt1.aspmx.l.google.com.
linux教程 mail exchanger = 10 alt4.aspmx.l.google.com.

Authoritative answers can be found from:

请注意,有时,邮件服务器设置未定义,在这些情况下,使用 nslookup 的 mx 查询可能会返回如下输出:

nslookup -type=mx linux教程
Server: 127.0.0.53
Address: 127.0.0.53#53

Non-authoritative answer:
*** Can’t find linux教程: No answer

Authoritative answers can be found from:

4.使用nslookup获取SOA记录

您可以通过指定查询类型,使用 nslookup 查询并显示 SOA(授权开始)记录:

nslookup -type=soa <URL>

示例输出如下:

nslookup -type=soa linux教程
Server: 127.0.0.53
Address: 127.0.0.53#53

Non-authoritative answer:
linux教程
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 linux教程
Server: 127.0.0.53
Address: 127.0.0.53#53

Non-authoritative answer:
linux教程
origin = dns1.registrar-servers.com
mail addr = hostmaster.registrar-servers.com
serial = 2019051520
refresh = 43200
retry = 3600
expire = 604800
minimum = 3601
linux教程 nameserver = dns1.registrar-servers.com.
linux教程 nameserver = dns2.registrar-servers.com.
Name: linux教程
Address: 142.93.143.135

Authoritative answers can be found from:

6. 反向DNS查找

到目前为止,您已经查询了某个域的 DNS 并获取了其 IP 地址。您可以进行反向 DNS 查找并搜索与 IP 地址关联的域名。

nslookup <IP_ADDRESS>

例如,如果我在 Linux Handbook 的服务器上使用 nslookup 进行反向 DNS 查找,这就是我得到的答案:

nslookup 142.93.143.135
135.143.93.142.in-addr.arpa name = 217283.cloudwaysapps.com.

Authoritative answers can be found from:

您没想到会出现这样的输出,是吗?这是因为在撰写本文时 Linux 手册是通过 Cloudways 托管的。借助 Cloudways,您只需点击几下即可安装多个 WordPress 网站。当创建新的 WordPress 安装时,它会被放置在 Cloudways 自己的 URL 中。 DNS 设置稍后更改为目标网站的地址。

这就是输出显示 Cloudways 地址而不是 linux教程 的原因

7.使用nslookup查询特定DNS服务器端口

DNS 服务器使用 TCP 协议,因此默认使用端口 53。如果 DNS 服务器使用其他端口,您可以使用 nslookup 在查询中指定端口:

nslookup -port=<Port_Number> <URL>

我认为这些材料足以让您了解如何在 Linux 中使用 nslookup 命令。如果您有疑问或建议,请随时在下面发表评论。

©2015-2025 艾丽卡 support@alaica.com