Linux/UNIX:DNS查找命令

时间:2020-01-09 10:45:58  来源:igfitidea点击:

如何在Linux或者UNIX或者Apple OS X操作系统下执行dns查找,而不使用第三方网站对DNS使用进行故障排除?您可以在Linux/UNIX下使用以下任何dns查找实用程序。您可以跳过所有第三方网站,并使用以下命令调试dns服务器和查找问题:

  • host 命令DNS查找实用程序。
  • dig命令DNS查找实用程序。

这两个命令都可以让您获得对各种dns查询的答案,例如IP地址(A),邮件交换(MX),名称服务器(NS),文本注释(TXT)或者ANY(所有)类型。

主机DNS查找示例

host命令是用于执行DNS查找的简单实用程序。
通常用于将名称转换为IP地址,反之亦然。
如果未提供任何参数或者选项,则host命令将显示其命令行参数和选项的简短摘要。
语法如下:

host example.com
host -t TYPE example.com
host -t a example.com

找出域IP

$ host -t a theitroad.local

输出示例:

theitroad.local has address 75.126.153.206

找出域邮件服务器

$ host -t mx theitroad.local

输出示例:

theitroad.local mail is handled by 2 theitroad.local.S9A2.PSMTP.com.
theitroad.local mail is handled by 3 theitroad.local.S9B1.PSMTP.com.
theitroad.local mail is handled by 4 theitroad.local.S9B2.PSMTP.com.
theitroad.local mail is handled by 1 theitroad.local.S9A1.PSMTP.com.

找出域名服务器

$ host -t ns theitroad.local

输出示例:

theitroad.local name server ns2.theitroad.net.
theitroad.local name server ns1.theitroad.net.
theitroad.local name server ns5.theitroad.net.
theitroad.local name server ns4.theitroad.net.

找出已注册的TXT域(例如SPF)

$ host -t txt theitroad.local

输出示例:

theitroad.local descriptive text "v=spf1 a mx ip4:10.16.48.99 ip4:10.16.48.98 ip4:10.16.48.102 ip4:10.16.48.101 ip4:10.16.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.theitroad.local

输出示例:

files.theitroad.local is an alias for files.theitroad.local.edgesuite.net.

找出域SOA记录

$ host -t soa theitroad.local

输出示例:

theitroad.local has SOA record ns1.theitroad.net. Hyman.theitroad.com. 2008072353 10800 3600 604800 3600

查询特定名称服务器

在ns2.theitroad.net中查询名为theitroad.local的域:

$ host theitroad.local ns2.theitroad.net

输出示例:

Using domain server:
Name: ns2.theitroad.net
Address: 75.126.168.152#53
Aliases: 

theitroad.local has address 75.126.153.206
theitroad.local has IPv6 address 2607:f0d0:1002:51::4
theitroad.local mail is handled by 3 theitroad.local.S9B1.PSMTP.com.
theitroad.local mail is handled by 4 theitroad.local.S9B2.PSMTP.com.
theitroad.local mail is handled by 1 theitroad.local.S9A1.PSMTP.com.
theitroad.local mail is handled by 2 theitroad.local.S9A2.PSMTP.com.

显示有关域记录和区域的所有信息

您需要传递-a(all)选项并要求host命令进行ANY类型的查询:

$ host -a theitroad.local

或者

$ host -t any theitroad.local

输出示例:

Trying "theitroad.local"
;; Truncated, retrying in TCP mode.
Trying "theitroad.local"
;; ->>HEADER

使用IPv6查询传输

使用IPv6查询传输测试dns查找(您必须具有基于IPV6的连接,包括启用IPv6的解析名称服务器):

$ host -6 theitroad.local
$ host -6 -a theitroad.local
$ host -6 theitroad.local ns1.theitroad.net
$ host -6 -t ns theitroad.local ns3.theitroad.net

输出示例:

Using domain server:
Name: ns3.theitroad.net
Address: 2001:48c8:10:1::2#53
Aliases: 

theitroad.local name server ns2.theitroad.net.
theitroad.local name server ns4.theitroad.net.
theitroad.local name server ns5.theitroad.net.
theitroad.local name server ns1.theitroad.net.

反向IP查找

输入命令:

$ host {IP-Address-Here}
$ host 75.126.153.206

输出示例:

206.153.126.75.in-addr.arpa domain name pointer www.theitroad.local.

获取TTL信息

执行命令,如下所示:

$ host -v -t {TYPE} {example.com}
$ host -v -t a theitroad.local
$ host -v -t a i.hexindia.net

输出示例:

Trying "theitroad.local"
;; ->>HEADER

如果再次运行同一命令,您会注意到TTL编号(1866)减少了。

挖掘DNS查找示例

dig(域信息groper)是用于查询DNS名称服务器的灵活工具。
它执行DNS查找,并显示从查询的名称服务器返回的答案。
由于DNS的灵活性,易用性和输出的清晰度,大多数DNS管理员都使用dig来解决DNS问题。

hos dns查找工具的功能少于dig。

例子

基本语法为:

dig @{ns1.example.com} {example.com}
dig @{ns1.example.com} {example.com} {TYPE}
dig theitroad.local a
dig theitroad.local mx
dig theitroad.local ns 
dig theitroad.local txt
dig @ns1.theitroad.net theitroad.local a

跟踪域委托路径

查看如何使用根服务器解析域,即打开对来自根名称服务器的委派路径的跟踪,以查找要查找的名称。
启用跟踪后,dig会进行迭代查询以解析正在查找的名称。
它将遵循来自根服务器的引用,显示来自用于解析查找的每个服务器的答案:

$ dig +trace theitroad.local

输出示例:

DiG 9.3.6-P1-RedHat-9.3.6-4.P1.el5_4.2  +trace theitroad.local
;; 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

com.			172800	IN	NS	h.gtld.com.
com.			172800	IN	NS	c.gtld.com.
com.			172800	IN	NS	e.gtld.com.
com.			172800	IN	NS	b.gtld.com.
com.			172800	IN	NS	g.gtld.com.
com.			172800	IN	NS	a.gtld.com.
com.			172800	IN	NS	f.gtld.com.
;; Received 316 bytes from 192.228.79.201#53(b.root-servers.net) in 34 ms

theitroad.local.		7200	IN	NS	NS5.theitroad.NET.
theitroad.local.		7200	IN	NS	NS1.theitroad.NET.
theitroad.local.		7200	IN	NS	NS2.theitroad.NET.
theitroad.local.		7200	IN	NS	NS4.theitroad.NET.
;; Received 115 bytes from 2001:503:8028:ffff:ffff:ffff:ffff:ff7e#53(h.gtld.com) in 23 ms

theitroad.local.		3600	IN	A	75.126.153.206
theitroad.local.		3600	IN	NS	ns4.theitroad.net.
theitroad.local.		3600	IN	NS	ns5.theitroad.net.
theitroad.local.		3600	IN	NS	ns1.theitroad.net.
theitroad.local.		3600	IN	NS	ns2.theitroad.net.
;; Received 307 bytes from 2001:48c8:10:1::2#53(NS5.theitroad.NET) in 222 ms

仅获得简短答案

快速获得答案的快速方法是执行以下命令:

$ dig +short theitroad.local

输出示例:

75.126.153.206

显示所有记录

$ dig +noall +answer theitroad.local any

输出示例:

theitroad.local.		3490	IN	A	75.126.153.206
theitroad.local.		2733	IN	NS	NS2.theitroad.NET.
theitroad.local.		2733	IN	NS	NS1.theitroad.NET.
theitroad.local.		2733	IN	NS	NS4.theitroad.NET.
theitroad.local.		2733	IN	NS	NS5.theitroad.NET.
theitroad.local.		85668	IN	RRSIG	NSEC 8 2 86400 20101125013720 20101026010313 50568 com. OjDv09mccTZR2bYCl4D57QcnNEkBq6bNEa20ExsI6NC2sI9pmiKLnq+w UnCYxWMnkMi7WNXwIhhUWtNhV48X3wJGj1Mufrhq8MnO25JIcRE6UJF2 y12TTZHHE0UJV6HSkw1sac3XlZKXLi/oSvE/IXTsdj2SckPh+pMlaieQ jAA=
theitroad.local.		85668	IN	NSEC	theitroadZEN.com. NS RRSIG NSEC

反向IP查找

执行以下命令:

$ dig -x +short {IP-Address-here}
$ dig -x 75.126.153.206 +short

输出示例

www.theitroad.local.

查找域SOA记录

$ dig +nssearch theitroad.local

输出示例:

SOA ns1.theitroad.net. Hyman.theitroad.com. 2008072353 10800 3600 604800 3600 from server ns5.theitroad.net in 81 ms.
SOA ns1.theitroad.net. Hyman.theitroad.com. 2008072353 10800 3600 604800 3600 from server ns4.theitroad.net in 216 ms.
SOA ns1.theitroad.net. Hyman.theitroad.com. 2008072353 10800 3600 604800 3600 from server ns1.theitroad.net in 347 ms.
SOA ns1.theitroad.net. Hyman.theitroad.com. 2008072353 10800 3600 604800 3600 from server ns2.theitroad.net in 316 ms.

使用挖掘找出TTL值

$ dig +nocmd +noall +answer {TYPE} {example.com}
$ dig +nocmd +noall +answer a theitroad.local

输出示例:

theitroad.local.		1642	IN	A	75.126.153.206

再次运行,执行:

$ dig +nocmd +noall +answer a theitroad.local

输出示例:

theitroad.local.		1629	IN	A	75.126.153.206