dig命令
介绍
简介:dig命令是一个域名查询工具,可以根据域名查询对应的IP,或者根据IP查询对应的域名等其它功能。
适用范围:RedHat、RHEL、Ubuntu、CentOS、Fedora。
语法
1 dig [选项] (参数)
选项
参数选项
1 @<服务器地址>:指定进行域名解析的域名服务器;2 -b<ip地址>:当主机具有多个IP地址,指定使用本机的哪个IP地址向域名服务器发送域名查询请求;3 -f<文件名称>:指定dig以批处理的方式运行,指定的文件中保存着需要批处理查询的DNS任务信息;4 -P:指定域名服务器所使用端口号;5 -t<类型>:指定要查询的DNS数据类型;6 -x<IP地址>:执行逆向域名查询;7 -4:使用IPv4;8 -6:使用IPv6;9 -h:显示指令帮助信息。
查询选项
- 前面加no表示不输出对应内容 | 选项 | 说明 | | —- | —- | | +[no]cmd | 标识dig版本和已修改的查询选项 | | +[no]short | 提供一个简洁的答案。默认情况下,以详细的形式打印答案。 | | +[no]all | 设置或清除所有显示标志。 | | +[no]answer | 显示[不显示]应答的应答部分。默认设置是显示它。 |
使用
1.正向解析
[root@master ~]# dig www.baidu.com; <<>> DiG 9.9.4-RedHat-9.9.4-14.el7 <<>> www.baidu.com;; global options: +cmd;; Got answer:;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 26110;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 1;; OPT PSEUDOSECTION:; EDNS: version: 0, flags:; udp: 1280;; QUESTION SECTION:;www.baidu.com. IN A;; ANSWER SECTION:www.baidu.com. 228 IN CNAME www.a.shifen.com.www.a.shifen.com. 228 IN A 14.215.177.38www.a.shifen.com. 228 IN A 14.215.177.39;; Query time: 3 msec;; SERVER: 192.168.50.1#53(192.168.50.1);; WHEN: 日 1月 02 12:04:28 CST 2022;; MSG SIZE rcvd: 104
2.使用指定的DNS服务器查询
[root@master ~]# dig @202.103.24.68 www.baidu.com; <<>> DiG 9.9.4-RedHat-9.9.4-14.el7 <<>> @202.103.24.68 www.baidu.com; (1 server found);; global options: +cmd;; Got answer:;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 41548;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 5, ADDITIONAL: 5;; QUESTION SECTION:;www.baidu.com. IN A;; ANSWER SECTION:www.baidu.com. 600 IN CNAME www.a.shifen.com.www.a.shifen.com. 600 IN A 14.215.177.38www.a.shifen.com. 600 IN A 14.215.177.39;; AUTHORITY SECTION:a.shifen.com. 1081 IN NS ns3.a.shifen.com.a.shifen.com. 1081 IN NS ns2.a.shifen.com.a.shifen.com. 1081 IN NS ns4.a.shifen.com.a.shifen.com. 1081 IN NS ns1.a.shifen.com.a.shifen.com. 1081 IN NS ns5.a.shifen.com.;; ADDITIONAL SECTION:ns1.a.shifen.com. 271 IN A 110.242.68.42ns2.a.shifen.com. 1081 IN A 220.181.33.32ns3.a.shifen.com. 293 IN A 112.80.255.253ns4.a.shifen.com. 1081 IN A 14.215.177.229ns5.a.shifen.com. 140 IN A 180.76.76.95;; Query time: 5 msec;; SERVER: 202.103.24.68#53(202.103.24.68);; WHEN: 日 1月 02 12:01:19 CST 2022;; MSG SIZE rcvd: 260
3.仅显示权威应答
[root@master ~]# dig +noall @202.103.24.68 www.baidu.com +authoritya.shifen.com. 1198 IN NS ns2.a.shifen.com.a.shifen.com. 1198 IN NS ns1.a.shifen.com.a.shifen.com. 1198 IN NS ns3.a.shifen.com.a.shifen.com. 1198 IN NS ns5.a.shifen.com.a.shifen.com. 1198 IN NS ns4.a.shifen.com.
4.反向解析
[root@master ~]# dig -x 114.114.114.114 +shortpublic1.114dns.com.
5.查询CNAME记录
[root@master ~]# dig +nocmd +noall cloud.tencent.com CNAME +answercloud.tencent.com. 2977 IN CNAME cloud.tencent-cloud.com.cloud.tencent-cloud.com. 560 IN CNAME cloud.tencent.com.dsa.dnsv1.com.cloud.tencent.com.dsa.dnsv1.com. 560 IN CNAME 2794037.sched.d0-dk.tdnsv5.com.
6.查询邮件交换记录
[root@master ~]# dig +nocmd qq.com -t mx +noall +answerqq.com. 5389 IN MX 10 mx3.QQ.COM.qq.com. 5389 IN MX 30 mx1.QQ.COM.qq.com. 5389 IN MX 20 mx2.QQ.COM.
7.查询TXT记录
[root@master ~]# dig +nocmd qq.com -t txt +noall +answer +shortqq.com. 4891 IN TXT "v=spf1 include:spf.mail.qq.com -all"[root@master ~]# dig +nocmd qq.com -t txt +noall +answer +short"v=spf1 include:spf.mail.qq.com -all"
