加入收藏 | 设为首页 | 会员中心 | 我要投稿 常州站长网 (https://www.0519zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 服务器 > 搭建环境 > Linux > 正文

10 Linux DIG Command Examples for DNS Lookup--reference

发布时间:2021-01-27 09:50:47 所属栏目:Linux 来源:网络整理
导读:副标题#e# by??on? Dig stands for domain information groper. Using dig command you can query DNS name servers for your DNS lookup related tasks. This article explains 10 examples on how to use dig command. 1. Simple dig Command Usage (Unde

; <<>> DiG 9.7.3-RedHat-9.7.3-2.el6 <<>> redhat.com NS +noall +answer
;; global options: +cmd
redhat.com. 558 IN NS ns2.redhat.com.
redhat.com. 558 IN NS ns1.redhat.com.
redhat.com. 558 IN NS ns3.redhat.com.
redhat.com. 558 IN NS ns4.redhat.com.

You can also use option -t to pass the query type (for example: NS) as shown below.

$ dig -t NS redhat.com +noall +answer

; <<>> DiG 9.7.3-RedHat-9.7.3-2.el6 <<>> -t NS redhat.com +noall +answer
;; global options: +cmd
redhat.com. 543 IN NS ns4.redhat.com.
redhat.com. 543 IN NS ns1.redhat.com.
redhat.com. 543 IN NS ns3.redhat.com.
redhat.com. 543 IN NS ns2.redhat.com.

5. View ALL DNS Records Types Using dig -t ANY

To view all the record types (A,MX,NS,etc.),use ANY as the record type as shown below.

$ dig redhat.com ANY +noall +answer

; <<>> DiG 9.7.3-RedHat-9.7.3-2.el6 <<>> redhat.com ANY +noall +answer
;; global options: +cmd
redhat.com. 430 IN MX 5 mx1.redhat.com.
redhat.com. 430 IN MX 10 mx2.redhat.com.
redhat.com. 521 IN NS ns3.redhat.com.
redhat.com. 521 IN NS ns1.redhat.com.
redhat.com. 521 IN NS ns4.redhat.com.
redhat.com. 521 IN NS ns2.redhat.com.

(or) Use -t ANY

$ dig -t ANY redhat.com  +noall +answer

; <<>> DiG 9.7.3-RedHat-9.7.3-2.el6 <<>> -t ANY redhat.com +noall +answer
;; global options: +cmd
redhat.com. 367 IN MX 10 mx2.redhat.com.
redhat.com. 367 IN MX 5 mx1.redhat.com.
redhat.com. 458 IN NS ns4.redhat.com.
redhat.com. 458 IN NS ns1.redhat.com.
redhat.com. 458 IN NS ns2.redhat.com.
redhat.com. 458 IN NS ns3.redhat.com.

6. View Short Output Using dig +short

To view just the ip-address of a web site (i.e the A record),use the short form option as shown below.

$ dig redhat.com +short
209.132.183.81

You can also specify a record type that you want to view with the +short option.

$ dig redhat.com ns +short
ns2.redhat.com.
ns3.redhat.com.
ns1.redhat.com.
ns4.redhat.com.

7. DNS Reverse Look-up Using dig -x

To perform a DNS reverse look up using the ip-address using dig -x as shown below

For example,if you just have an external ip-address and would like to know the website that belongs to it,do the following.

$ dig -x 209.132.183.81 +short
www.redhat.com.

To view the full details of the DNS reverse look-up,remove the +short option.

$ dig -x 209.132.183.81

; <<>> DiG 9.7.3-RedHat-9.7.3-2.el6 <<>> -x 209.132.183.81
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY,id: 62435
;; flags: qr rd ra; QUERY: 1,ADDITIONAL: 3

;; QUESTION SECTION:
;81.183.132.209.in-addr.arpa. IN PTR

;; ANSWER SECTION:
81.183.132.209.in-addr.arpa. 600 IN PTR www.redhat.com.

;; AUTHORITY SECTION:
183.132.209.in-addr.arpa. 248 IN NS ns2.redhat.com.
183.132.209.in-addr.arpa. 248 IN NS ns1.redhat.com.
183.132.209.in-addr.arpa. 248 IN NS ns3.redhat.com.
183.132.209.in-addr.arpa. 248 IN NS ns4.redhat.com.

;; ADDITIONAL SECTION:
ns1.redhat.com. 363 IN A 209.132.186.218
ns2.redhat.com. 363 IN A 209.132.183.2
ns3.redhat.com. 363 IN A 209.132.176.100

;; Query time: 35 msec
;; SERVER: 209.144.50.138#53(209.144.50.138)
;; WHEN: Thu Jan 12 10:15:00 2012
;; MSG SIZE rcvd: 193

8. Use a Specific DNS server Using dig @dnsserver

By default dig uses the DNS servers defined in your /etc/resolv.conf file.

If you like to use a different DNS server to perform the query,specify it in the command line as @dnsserver.

The following example uses ns1.redhat.com as the DNS server to get the answer (instead of using the DNS servers from the /etc/resolv.conf file).

$ dig @ns1.redhat.com redhat.com

; <<>> DiG 9.7.3-RedHat-9.7.3-2.el6 <<>> @ns1.redhat.com redhat.com
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY,id: 20963
;; flags: qr aa rd; QUERY: 1,ADDITIONAL: 4
;; WARNING: recursion requested but not available

;; QUESTION SECTION:
;redhat.com. IN A

;; ANSWER SECTION:
redhat.com. 60 IN A 209.132.183.81

(编辑:常州站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

热点阅读