参考博文
http://roclinux.cn/?p=2449
centos安装
yum install bind-utils
介绍:
dig全称是Domain Information Groper,它是一个dns查询工具
特点:
设置灵活、输出清晰、功能强大
命令格式:
dig [@server] [-b address] [-c class] [-f filename] [-k filename] [-m] [-p port#] [-q name] [-t type] [-x addr] [-y [hmac:]name:key] [-4] [-6] [name] [type] [class] [queryopt...] dig [-h] dig [global-queryopt...] [query...]
用法:
默认用法
dig www.test.com
返回内容:
常见返回内容有两种,一种是域名有CNAME的,一种是A记录的。
其中ANSWER SECTION是解析的结果。
AUTHORITY SECTION如果是A记录,是查询域名的NS服务器是哪些。
AUTHORITY SECTION如果是CNAME记录,是最后一个CNAME域名的NS服务器是哪些。
ADDITIONAL SECTION如果是A记录,是查询域名的NS服务器的真实地址。
ADDITIONAL SECTION如果是CNAME,是最后一个CNAME域名的NS服务器的真实地址。 Query time : 查询耗时
SERVER:查询服务器
下面中,是有基于CNAME的一个解析内容。域名经过了2次CNAME,然后解析到真实的ip. 同一个DNS服务器,CNAME只可以对应一条内容,A记录可以对应多条内容。
[root@vm172-31-48-17 ~]# dig www.baidu.com ; <<>> DiG 9.9.4-RedHat-9.9.4-50.el7_3.1 <<>> www.baidu.com ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 38744 ;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 5, ADDITIONAL: 6 ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 4096 ;; QUESTION SECTION: ;www.baidu.com. IN A ;; ANSWER SECTION: www.baidu.com. 357 IN CNAME www.a.shifen.com. www.a.shifen.com. 151 IN A 61.135.169.125 www.a.shifen.com. 151 IN A 61.135.169.121 ;; AUTHORITY SECTION: a.shifen.com. 958 IN NS ns1.a.shifen.com. a.shifen.com. 958 IN NS ns3.a.shifen.com. a.shifen.com. 958 IN NS ns5.a.shifen.com. a.shifen.com. 958 IN NS ns2.a.shifen.com. a.shifen.com. 958 IN NS ns4.a.shifen.com. ;; ADDITIONAL SECTION: ns1.a.shifen.com. 324 IN A 61.135.165.224 ns2.a.shifen.com. 1 IN A 180.149.133.241 ns3.a.shifen.com. 1 IN A 61.135.162.215 ns4.a.shifen.com. 324 IN A 115.239.210.176 ns5.a.shifen.com. 324 IN A 119.75.222.17 ;; Query time: 0 msec ;; SERVER: 198.18.254.30#53(198.18.254.30) ;; WHEN: Sun Jan 07 08:11:00 CST 2018 ;; MSG SIZE rcvd: 271
以下是A记录的返回,ANSWER SECTION返回的就是真实ip
[root@vm172-31-48-17 ~]# dig c.guanshizhai.online ; <<>> DiG 9.9.4-RedHat-9.9.4-50.el7_3.1 <<>> c.guanshizhai.online ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 13420 ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 11 ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 4096 ;; QUESTION SECTION: ;c.guanshizhai.online. IN A ;; ANSWER SECTION: c.guanshizhai.online. 600 IN A 120.92.51.3 ;; AUTHORITY SECTION: guanshizhai.online. 86400 IN NS f1g1ns1.dnspod.net. guanshizhai.online. 86400 IN NS f1g1ns2.dnspod.net. ;; ADDITIONAL SECTION: f1g1ns1.dnspod.net. 68997 IN A 14.215.150.17 f1g1ns1.dnspod.net. 68997 IN A 58.247.212.36 f1g1ns1.dnspod.net. 68997 IN A 61.151.180.44 f1g1ns1.dnspod.net. 68997 IN A 180.163.19.15 f1g1ns1.dnspod.net. 68997 IN A 182.140.167.166 f1g1ns2.dnspod.net. 68997 IN A 121.51.128.164 f1g1ns2.dnspod.net. 68997 IN A 182.140.167.188 f1g1ns2.dnspod.net. 68997 IN A 52.220.136.67 f1g1ns2.dnspod.net. 68997 IN A 61.129.8.159 f1g1ns2.dnspod.net. 68997 IN A 101.226.220.16 ;; Query time: 205 msec ;; SERVER: 198.18.254.30#53(198.18.254.30) ;; WHEN: Sun Jan 07 08:11:45 CST 2018 ;; MSG SIZE rcvd: 275
指定dns
dig @8.8.8.8 www.test.com
找出test.com权威服务器的解析结果
dig www.test.com +trace
输出精简信息
dig @8.8.8.8 www.test.com +short
指定文件名查询
dig -f 1.txt
文件里面的内容格式
www.test.com
img.test.com