linux下安装使用dig命令,debian和centos可用

老黑
老黑
老黑
19
文章
0
评论
2020年11月2日15:08:24 评论

linux vps提供商的vps大多数都是mini版或者精简版,并没有自带dig命令,这时我们需要手动安装dig命令。

linux下安装使用dig命令,debian和centos可用

linux下安装使用dig命令,debian和centos可用

debian系统

apt-get install dnsutils

centos系统

yum install bind-utils

dig命令大多时候可以取代nslookup

dig命令支持A\AAA\CNAME\NS\MX\TXT等常见类型,使用方法也非常简单

简明使用,只会输出A记录(写脚本的时候容易获取ip地址)

root@iZwz9avyv2945ilt432lffZ:~# dig a ixmu.net

; <<>> DiG 9.10.3-P4-Debian <<>> a ixmu.net
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 52501
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;ixmu.net.                      IN      A

;; ANSWER SECTION:
ixmu.net.               300     IN      A       59.56.78.44

;; Query time: 12 msec
;; SERVER: 100.100.2.136#53(100.100.2.136)
;; WHEN: Mon Nov 02 15:00:44 CST 2020
;; MSG SIZE  rcvd: 53

大部分的时候dig最下面显示了查询所用的时间及DNS服务器,时间,数据大小。DNS超时时间为30秒,查询时间对于排查DNS问题很有用。

;; Query time: 48 msec
;; SERVER: 10.202.72.118#53(10.202.72.118)
;; WHEN: Sun Oct 12 21:41:47 2014
;; MSG SIZE  rcvd: 225

DNS的解析是递规解析,那么用dig可以加+trace参数,会显示完整的,无缓存,递规的查询,显示的是完整的trace记录。

root@iZwz9avyv2945ilt432lffZ:~# dig ixmu.com +trace

; <<>> DiG 9.10.3-P4-Debian <<>> ixmu.com +trace
;; global options: +cmd
.                       1849    IN      NS      c.root-servers.net.
.                       1849    IN      NS      j.root-servers.net.
.                       1849    IN      NS      i.root-servers.net.
.                       1849    IN      NS      f.root-servers.net.
.                       1849    IN      NS      e.root-servers.net.
.                       1849    IN      NS      m.root-servers.net.
.                       1849    IN      NS      k.root-servers.net.
.                       1849    IN      NS      h.root-servers.net.
.                       1849    IN      NS      d.root-servers.net.
.                       1849    IN      NS      l.root-servers.net.
.                       1849    IN      NS      b.root-servers.net.
.                       1849    IN      NS      g.root-servers.net.
.                       1849    IN      NS      a.root-servers.net.
.                       88981   IN      RRSIG   NS 8 0 518400 20201110050000 20201028040000 26116 . xhiiRZWRQD18irvY5WWQyTBqQOIAoIgEwpvasTy1rlAOBD14LNwKLTDz sdG8YGN1fYm0I02lilrQ2hdOzbVVKQJee9oqTKIx3OIEOMfWkfMxnIcg UvjkVhSYgYO+hqjzoI+C53s4qoesvnuXBXjnHtYiZE0pRUoAQ0MYxNpk 0wnIfyomhyzzCcZe2eJdqydO+w53gtJ6AQU3bvL3DTBe3GYxkGx9BP27 AKgOEBCVL3QOUXtEqIHJ23RhxZHzLKRB1HTYGkb1QZyib0/+9EMzhKga 8qHiVThFAJ+sZjLEVw4R2nlQCgX1Ki2yNM4hxj4/Wd0CwQQOj4foZADu ngAnbQ==
;; Received 525 bytes from 100.100.2.136#53(100.100.2.136) in 0 ms

com.                    172800  IN      NS      a.gtld-servers.net.
com.                    172800  IN      NS      b.gtld-servers.net.
com.                    172800  IN      NS      c.gtld-servers.net.
com.                    172800  IN      NS      d.gtld-servers.net.
com.                    172800  IN      NS      e.gtld-servers.net.
com.                    172800  IN      NS      f.gtld-servers.net.
com.                    172800  IN      NS      g.gtld-servers.net.
com.                    172800  IN      NS      h.gtld-servers.net.
com.                    172800  IN      NS      i.gtld-servers.net.
com.                    172800  IN      NS      j.gtld-servers.net.
com.                    172800  IN      NS      k.gtld-servers.net.
com.                    172800  IN      NS      l.gtld-servers.net.
com.                    172800  IN      NS      m.gtld-servers.net.
com.                    86400   IN      DS      30909 8 2 E2D3C916F6DEEAC73294E8268FB5885044A833FC5459588F4A9184CF C41A5766
com.                    86400   IN      RRSIG   DS 8 1 86400 20201115050000 20201102040000 26116 . a1cgYDa/OC+sOdqBEjcL1AHwBnjVpTfC9lG4hNWAM6EFvwDDv3c0Z2P0 ae64cpTTu1uWdX7OGT9R/EHH1PXRGlbAmRMcMq2kpPaZy6oJpQkEOJQe wtyfVftlfGbo0P2VqznFs4+6yWNHnESO0pD/c6Wg3j9wBvDlnF2Oi9g/ hOPzo+NNMQ7lZboeRhGFiERdf5dikmKi1v+WAttAk1MgdL8hv9WfjZYN 8PEI/ndGOL8Fz8n8r/mQhkn36r/Pc573auXNdgxOqnH4ntVP77E7J5lF ywvnEIU+fPxICsFH0VEGKE/1nthTYYMRh7kW8bHuvI9flu2mlTvY0rTN 86/RsQ==
;; Received 1168 bytes from 192.58.128.30#53(j.root-servers.net) in 215 ms

ixmu.com.               172800  IN      NS      ns1.hasns.com.
ixmu.com.               172800  IN      NS      ns2.hasns.com.
ixmu.com.               172800  IN      NS      ns3.hasns.com.
ixmu.com.               172800  IN      NS      ns4.hasns.com.
CK0POJMG874LJREF7EFN8430QVIT8BSM.com. 86400 IN NSEC3 1 1 0 - CK0Q1GIN43N1ARRC9OSM6QPQR81H5M9A NS SOA RRSIG DNSKEY NSEC3PARAM
CK0POJMG874LJREF7EFN8430QVIT8BSM.com. 86400 IN RRSIG NSEC3 8 2 86400 20201109054042 20201102043042 31510 com. AQ/C247BFFWm7+G8mOcyTBflc19nk/0ymEf+tlKfkW8Mx1YE+7I5OobP BXAqpm6jvHsVH1zYH4JGZxrWdqbgrJeb8jKK21iUJrz+SXHRabY8LSlv y8xfz2UZeHB4EcBFWm17C1JarZv8+rBNMVqZJ39cofhjDSTguCxrn4Zr e69TaLxNLhfGZ3Vgon2hv3dGg91/CQcjzeu3XCda6pR3Aw==
0D09K5OVGRFRL42ERNAFORG9SR9AC82E.com. 86400 IN NSEC3 1 1 0 - 0D09U39F25BAGD9P57LMJ54A0OA2ILQJ NS DS RRSIG
0D09K5OVGRFRL42ERNAFORG9SR9AC82E.com. 86400 IN RRSIG NSEC3 8 2 86400 20201105074215 20201029053215 31510 com. X6LPpYTu++sdNo4mW2o7SKQ9Bov2jhTaPxRDPqkNiGRUXhLGpBvlf2Bz efo7LJIqx2U/S6+hRKTY6twt8YFuQl5oQF0G0jETa1xOMSeW6NMPaKA2 3rJkTqGLaMZ2fTLRFsQFTEWp5aoDA3E+yK8sSba0f5VQLFuJJ0Jr0Ys2 PHcEQrGuVPUPrm2CXubgNf16D4m70vMDyGKPpAJfLy97eg==
;; Received 728 bytes from 192.55.83.30#53(m.gtld-servers.net) in 215 ms

ixmu.com.               3600    IN      A       104.219.168.162
ixmu.com.               3600    IN      NS      ns2.hasns.com.
ixmu.com.               3600    IN      NS      ns1.hasns.com.
ixmu.com.               3600    IN      NS      ns3.hasns.com.
ixmu.com.               3600    IN      NS      ns4.hasns.com.
;; Received 131 bytes from 172.104.243.104#53(ns2.hasns.com) in 217 ms

服务器上很多时候是双线或三线,如果有智能解析的话要测试从某一个 ip 去请求 dns,加 -b 参数

root@iZwz9avyv2945ilt432lffZ:~# dig -b 172.17.17.91 ixmu.net

; <<>> DiG 9.10.3-P4-Debian <<>> -b 172.17.17.91 ixmu.net
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 7333
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;ixmu.net.                      IN      A

;; ANSWER SECTION:
ixmu.net.               300     IN      A       59.56.78.44

;; Query time: 7 msec
;; SERVER: 100.100.2.136#53(100.100.2.136)
;; WHEN: Mon Nov 02 15:03:41 CST 2020
;; MSG SIZE  rcvd: 53
黑软技术栈接受广大网友的投稿,如果你热爱创作分享,欢迎邮件投稿至pengjinpwu@aliyun.com;
如果我们的文章对你有所帮助,你很欣赏它,不妨动动手指点击上方"打赏"按钮,支持本站的发展。
老黑
  • 本文由 发表于 2020年11月2日15:08:24
  • 转载请务必保留本文链接:https://www.ixmu.net/article/173.html