Linux / UNIX:DNS 查找命令
您可以在 Linux / UNIX 下使用以下任一 DNS 查找实用程序。您可以跳过所有第三方网站,并使用以下命令调试 DNS 服务器和 DNS 查找问题:
所有命令将允许您获得各种 DNS 查询的答案,例如 IP 地址 (A)、邮件交换 (MX)、名称服务器 (NS)、文本注释 (TXT) 或任何 (全部) 类型。
教程详细信息 | |
---|---|
难度等级 | 简单的 |
Root 权限 | 不 |
要求 | Linux 或 Unix 终端 |
类别 | 网络实用程序 |
操作系统兼容性 | BSD • Linux • macOS • Unix |
预计阅读时间 | 3 分钟 |
主机 DNS 查找示例
host 命令是用于执行 DNS 查找的简单实用程序。它通常用于将名称转换为 IP 地址,反之亦然。当未提供任何参数或选项时,host 命令将显示其命令行参数和选项的简短摘要。语法如下:
host example.com host -t TYPE example.com host -t a example.com
任务:找出域IP
$ host -t a example.com
示例输出:
example.com has address 75.126.153.206
任务:找出域邮件服务器
$ host -t mx example.com
示例输出:
example.com mail is handled by 2 example.com.S9A2.PSMTP.com. example.com mail is handled by 3 example.com.S9B1.PSMTP.com. example.com mail is handled by 4 example.com.S9B2.PSMTP.com. example.com mail is handled by 1 example.com.S9A1.PSMTP.com.
任务:找出域名服务器
$ host -t ns example.com
示例输出:
example.com name server ns2.example.net. example.com name server ns1.example.net. example.com name server ns5.example.net. example.com name server ns4.example.net.
任务:找出记录的域 TXT(例如 SPF)
$ host -t txt example.com
示例输出:
example.com descriptive text "v=spf1 a mx ip4:74.86.48.99 ip4:74.86.48.98 ip4:74.86.48.102 ip4:74.86.48.101 ip4:74.86.48.100 ip4:72.26.218.170 ip4:93.89.92.12 ip4:180.92.186.178 include:_spf.google.com ~all"
任务:找出域 CNAME 记录
$ host -t cname files.example.com
示例输出:
files.example.com is an alias for files.example.com.edgesuite.net.
任务:找出域 SOA 记录
$ host -t soa example.com
示例输出:
example.com has SOA record ns1.example.net. vivek.example.com. 2008072353 10800 3600 604800 3600
任务:查询特定名称服务器
查询 ns2.example.net 中名为 example.com 的域名:
$ host example.com ns2.example.net
示例输出:
Using domain server: Name: ns2.example.net Address: 75.126.168.152#53 Aliases: example.com has address 75.126.153.206 example.com has IPv6 address 2607:f0d0:1002:51::4 example.com mail is handled by 3 example.com.S9B1.PSMTP.com. example.com mail is handled by 4 example.com.S9B2.PSMTP.com. example.com mail is handled by 1 example.com.S9A1.PSMTP.com. example.com mail is handled by 2 example.com.S9A2.PSMTP.com.
任务:显示有关域记录和区域的所有信息
您需要传递 -a (全部)选项并要求主机命令进行类型 ANY 的查询:
$ host -a example.com
或
$ host -t any example.com
示例输出:
Trying "example.com" ;; Truncated, retrying in TCP mode. Trying "example.com" ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 34079 ;; flags: qr rd ra; QUERY: 1, ANSWER: 14, AUTHORITY: 0, ADDITIONAL: 0 ;; QUESTION SECTION: ;example.com. IN ANY ;; ANSWER SECTION: example.com. 3423 IN AAAA 2607:f0d0:1002:51::4 example.com. 3600 IN SOA ns1.example.net. vivek.example.com. 2008072353 10800 3600 604800 3600 example.com. 3600 IN TXT "v=spf1 a mx ip4:74.86.48.99 ip4:74.86.48.98 ip4:74.86.48.102 ip4:74.86.48.101 ip4:74.86.48.100 ip4:72.26.218.170 ip4:93.89.92.12 ip4:180.92.186.178 include:_spf.google.com ~all" example.com. 3600 IN MX 2 example.com.S9A2.PSMTP.com. example.com. 3600 IN MX 3 example.com.S9B1.PSMTP.com. example.com. 3600 IN MX 4 example.com.S9B2.PSMTP.com. example.com. 3600 IN MX 1 example.com.S9A1.PSMTP.com. example.com. 2805 IN A 75.126.153.206 example.com. 3423 IN NS ns2.example.net. example.com. 3423 IN NS ns5.example.net. example.com. 3423 IN NS ns1.example.net. example.com. 3423 IN NS ns4.example.net. example.com. 84092 IN RRSIG NSEC 8 2 86400 20101125013720 20101026010313 50568 biz. OjDv09mccTZR2bYCl4D57QcnNEkBq6bNEa20ExsI6NC2sI9pmiKLnq+w UnCYxWMnkMi7WNXwIhhUWtNhV48X3wJGj1Mufrhq8MnO25JIcRE6UJF2 y12TTZHHE0UJV6HSkw1sac3XlZKXLi/oSvE/IXTsdj2SckPh+pMlaieQ jAA= example.com. 84092 IN NSEC exampleZEN.biz. NS RRSIG NSEC Received 749 bytes from 192.168.1.254#53 in 0.1 ms
任务:使用 IPv6 查询传输
使用 IPv6 查询传输测试您的 DNS 查找(您必须具有基于 IPV6 的连接,包括启用 IPv6 的解析名称服务器):
示例输出:
$ host -6 example.com
$ host -6 -a example.com
$ host -6 example.com ns1.example.net
$ host -6 -t ns example.com ns3.example.net
Using domain server:
Name: ns3.example.net
Address: 2001:48c8:10:1::2#53
Aliases:
example.com name server ns2.example.net.
example.com name server ns4.example.net.
example.com name server ns5.example.net.
example.com name server ns1.example.net.
任务:反向 IP 查找
输入命令:
示例输出:
$ host {IP-Address-Here}
$ host 75.126.153.206
206.153.126.75.in-addr.arpa domain name pointer www.example.com.
任务:获取 TTL 信息
输入以下命令:
示例输出:
$ host -v -t {TYPE} {example.com}
$ host -v -t a example.com
$ host -v -t a i.hexindia.net
Trying "example.com"
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 17431
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 4, ADDITIONAL: 7
;; QUESTION SECTION:
;example.com. IN A
;; ANSWER SECTION:
example.com. 1866 IN A 75.126.153.206
;; AUTHORITY SECTION:
example.com. 3850 IN NS NS1.example.NET.
example.com. 3850 IN NS NS4.example.NET.
example.com. 3850 IN NS NS5.example.NET.
example.com. 3850 IN NS NS2.example.NET.
;; ADDITIONAL SECTION:
NS1.example.NET. 85669 IN A 72.26.218.170
NS1.example.NET. 85689 IN AAAA 2001:48c8:7::2
NS2.example.NET. 85669 IN A 75.126.168.152
NS2.example.NET. 85669 IN AAAA 2607:f0d0:1002:51::3
NS4.example.NET. 85669 IN A 93.89.92.12
NS4.example.NET. 85669 IN AAAA 2a01:348:0:15:5d59:50c:0:1
NS5.example.NET. 85669 IN AAAA 2001:48c8:10:1::2
Received 291 bytes from 10.0.80.11#53 in 2 ms
如果再次运行相同的命令,您会注意到 TTL 数字(1866)减少了。
dig DNS 查找示例
dig(域信息搜索器)是一种用于查询DNS 名称服务器的灵活工具。它执行 DNS 查找并显示从查询的名称服务器返回的答案。大多数 DNS 管理员使用 dig 来解决 DNS 问题,因为它灵活、易用且输出清晰。hos dns 查找工具的功能比 dig 少。
示例
基本语法是:
dig @{ns1.example.com} {example.com} dig @{ns1.example.com} {example.com} {TYPE} dig example.com a dig example.com mx dig example.com ns dig example.com txt dig @ns1.example.net example.com a
任务:跟踪域委派路径
了解如何使用根服务器解析域名,即打开对正在查找的名称的根名称服务器的委托路径的跟踪。启用跟踪后,dig 将进行迭代查询以解析正在查找的名称。它将遵循来自根服务器的引用,显示用于解析查找的每个服务器的答案:
示例输出:
$ dig +trace example.com
<<>> DiG 9.3.6-P1-RedHat-9.3.6-4.P1.el5_4.2 <<>> +trace example.com ;; global options: printcmd . 41219 IN NS b.root-servers.net. . 41219 IN NS e.root-servers.net. . 41219 IN NS i.root-servers.net. . 41219 IN NS d.root-servers.net. . 41219 IN NS g.root-servers.net. . 41219 IN NS k.root-servers.net. . 41219 IN NS l.root-servers.net. . 41219 IN NS c.root-servers.net. . 41219 IN NS m.root-servers.net. . 41219 IN NS a.root-servers.net. . 41219 IN NS h.root-servers.net. . 41219 IN NS j.root-servers.net. . 41219 IN NS f.root-servers.net. ;; Received 436 bytes from 10.0.80.11#53(10.0.80.11) in 2 ms biz. 172800 IN NS h.gtld.biz. biz. 172800 IN NS c.gtld.biz. biz. 172800 IN NS e.gtld.biz. biz. 172800 IN NS b.gtld.biz. biz. 172800 IN NS g.gtld.biz. biz. 172800 IN NS a.gtld.biz. biz. 172800 IN NS f.gtld.biz. ;; Received 316 bytes from 192.228.79.201#53(b.root-servers.net) in 34 ms example.com. 7200 IN NS NS5.example.NET. example.com. 7200 IN NS NS1.example.NET. example.com. 7200 IN NS NS2.example.NET. example.com. 7200 IN NS NS4.example.NET. ;; Received 115 bytes from 2001:503:8028:ffff:ffff:ffff:ffff:ff7e#53(h.gtld.biz) in 23 ms example.com. 3600 IN A 75.126.153.206 example.com. 3600 IN NS ns4.example.net. example.com. 3600 IN NS ns5.example.net. example.com. 3600 IN NS ns1.example.net. example.com. 3600 IN NS ns2.example.net. ;; Received 307 bytes from 2001:48c8:10:1::2#53(NS5.example.NET) in 222 ms
任务:仅获取简短答案
获取答案的快速方法是键入以下命令:
示例输出:
$ dig +short example.com
75.126.153.206
任务:显示所有记录
$ dig +noall +answer example.com any
示例输出:
example.com. 3490 IN A 75.126.153.206 example.com. 2733 IN NS NS2.example.NET. example.com. 2733 IN NS NS1.example.NET. example.com. 2733 IN NS NS4.example.NET. example.com. 2733 IN NS NS5.example.NET. example.com. 85668 IN RRSIG NSEC 8 2 86400 20101125013720 20101026010313 50568 biz. OjDv09mccTZR2bYCl4D57QcnNEkBq6bNEa20ExsI6NC2sI9pmiKLnq+w UnCYxWMnkMi7WNXwIhhUWtNhV48X3wJGj1Mufrhq8MnO25JIcRE6UJF2 y12TTZHHE0UJV6HSkw1sac3XlZKXLi/oSvE/IXTsdj2SckPh+pMlaieQ jAA= example.com. 85668 IN NSEC exampleZEN.biz. NS RRSIG NSEC
任务:反向 IP 查找
键入以下命令:
示例输出
$ dig -x +short {IP-Address-here}
$ dig -x 75.126.153.206 +short
www.example.com.
任务:查找域 SOA 记录
$ dig +nssearch example.com
示例输出:
SOA ns1.example.net. vivek.example.com. 2008072353 10800 3600 604800 3600 from server ns5.example.net in 81 ms. SOA ns1.example.net. vivek.example.com. 2008072353 10800 3600 604800 3600 from server ns4.example.net in 216 ms. SOA ns1.example.net. vivek.example.com. 2008072353 10800 3600 604800 3600 from server ns1.example.net in 347 ms. SOA ns1.example.net. vivek.example.com. 2008072353 10800 3600 604800 3600 from server ns2.example.net in 316 ms.
任务:使用 dig 找出 TTL 值
$ dig +nocmd +noall +answer {TYPE} {example.com}
$ dig +nocmd +noall +answer a example.com
示例输出:
example.com. 1642 IN A 75.126.153.206
再次运行,输入:
$ dig +nocmd +noall +answer a example.com
示例输出:
example.com. 1629 IN A 75.126.153.206