dig常用命令

本文编写于2799天前,最后编辑于 2759天前,部分内容可能已经过时,请您自行斟酌确认。

Dig是域信息搜索器的简称(Domain Information Groper),使用dig命令可以执行查询域名相关的任务。

1. 理解dig的输出结果

$ dig chenrongrong.info

1 ; <<>> DiG 9.9.5-3ubuntu0.1-Ubuntu <<>> chenrongrong.info
2 ;; global options: +cmd
3 ;; Got answer:
4 ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 22752
5 ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 1

7 ;; OPT PSEUDOSECTION:
8 ; EDNS: version: 0, flags:; udp: 4096
9 ;; QUESTION SECTION:
10 ;chenrongrong.info.        IN    A

11 ;; ANSWER SECTION:
12 chenrongrong.info.    600    IN    A    103.245.222.133

13 ;; AUTHORITY SECTION:
14 chenrongrong.info.    600    IN    NS    f1g1ns2.dnspod.net.
15 chenrongrong.info.    600    IN    NS    f1g1ns1.dnspod.net.

16 ;; Query time: 183 msec
17 ;; SERVER: 127.0.1.1#53(127.0.1.1)
18 ;; WHEN: Thu Dec 25 16:04:51 CST 2014
19 ;; MSG SIZE  rcvd: 116

1~8: 显示了dig的基本设置信息,e.g. java -version

9-10: 显示了查询内容,这里查询的是域名chenrongrong.info的A记录

11-12: 显示了查询结果,域名chenrongrong.info的A记录是103.245.222.133(A (Address) 记录是用来指定主机名(或域名)对应的IP地址记)

13-15: 授权信息,域名chenrongrong.info的NS(nameserver)是dnspod的域名服务器

16-19: 统计信息

上述选项都可以通过对应选项选择是否输出,+[no]question,+[no]answer,+[no]authority,+[no]stat,当然+short更加简洁

2. 显示特定的输出结果

+[no]comments – Turn off the comment lines
+[no]authority – Turn off the authority section
+[no]additional – Turn off the additional section
+[no]stats – Turn off the stats section
+[no]answer – Turn off the answer section (Of course, you wouldn’t want to turn off the answer section)

3. 查询MX记录 MX(Mail Exchanger)记录查询:

$ dig redhat.com MX +noall +answer

or

$ dig -t MX redhat.com +noall +answer 后者-t代表查询类型,可以是A,MX,NS等,+noall 代表清除所有显示的选项

4. 查询域名服务器

$ dig -t NS chenrongrong.info +noall +answer

5. 查询所有DNS记录

$ dig -t ANY chenrongrong.info +answer

; <<>> DiG 9.9.5-3ubuntu0.1-Ubuntu <<>> -t ANY chenrongrong.info            +noall +answer
;; global options: +cmd
chenrongrong.info.    568    IN    A    103.245.222.133
chenrongrong.info.    568    IN    NS    f1g1ns2.dnspod.net.
chenrongrong.info.    568    IN    NS    f1g1ns1.dnspod.net.
chenrongrong.info.    568    IN    SOA    f1g1ns1.dnspod.net.freednsadmin.dnspod.com. 1417233166 3600 180 1209600 180

6. 简洁显示+short

+short参数只显示nameserver $ dig -t NS chenrongrong.info +short

f1g1ns2.dnspod.net.
f1g1ns1.dnspod.net.

7. DNS反向解析dig -x

我们一般所说的DNS域名解析指的是正向解析即从域名解析到相应的IP,反之从IP解析到对应的DNS服务器就是反向解析,8.8.8.8是google的一个公共DNS服务器,我们可以通过dig -x查找该ip对应的DNS服务器

$ dig -x 8.8.8.8 +short

google-public-dns-a.google.com.

8.显示域名的CNAME记录

CNAME记录,即:别名记录。这种记录允许您将多个名字映射到同一台计算机.

dig cname www.baidu.com +short

www.a.shifen.com.

dig可以使我们更好的理解DNS解析的过程,dig -h列出了更多详细的命令参数可供我们使用,这也是学习命令有效方式:

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注