文章目录
前言
DNS(Domain Name System) , 域名系统,主要提供域名和IP之间映射关系的查询服务。
本节内容我们带大家了解下如何分析和排查DNS问题。
本次介绍nslookup 命令和dig 命令,这两个命令都是来自bind-utils包。
bash
[root@work ~]# rpm -ql bind-utils
/etc/trusted-key.key
/usr/bin/delv
/usr/bin/dig
/usr/bin/host
/usr/bin/mdig
/usr/bin/nslookup
/usr/bin/nsupdate
/usr/share/man/man1/delv.1.gz
/usr/share/man/man1/dig.1.gz
/usr/share/man/man1/host.1.gz
/usr/share/man/man1/mdig.1.gz
/usr/share/man/man1/nslookup.1.gz
/usr/share/man/man1/nsupdate.1.gz
一、nslookup
nslookup 命令主要用来诊断域名系统 (DNS) 基础结构的信息。
nslookup 使用
nslookup有两种工作模式,交互模式和非交互模式。
交互模式
输入nslookup命令,不加任何参数,就可以进入交互模式。
bash
[root@work ~]# nslookup
> www.360.com
Server: 114.114.114.114
Address: 114.114.114.114#53
Non-authoritative answer:
Name: www.360.com
Address: 27.115.124.133
> exit
# Server和Address 是使用的域名服务器信息
# Non-authoritative answer 表示非权威查询结果。
非交互模式
nslookup 第一个参数是要解析的域名,默认用/etc/resolv.conf里面第一个nameserver去解析。
nslookup 可以接受第二个参数,指定具体哪个nameserver去解析。
bash
[root@work ~]# nslookup www.360.com
Server: 114.114.114.114
Address: 114.114.114.114#53
Non-authoritative answer:
Name: www.360.com
Address: 27.115.124.133
[root@work ~]# nslookup www.360.com 8.8.8.8
Server: 8.8.8.8
Address: 8.8.8.8#53
Non-authoritative answer:
Name: www.360.com
Address: 27.115.124.133
二、dig命令
解析域名
bash
[root@work ~]# dig www.360.com
; <<>> DiG 9.11.4-P2-RedHat-9.11.4-26.P2.el7_9.13 <<>> www.360.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 10249
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 512
;; QUESTION SECTION:
;www.360.com. IN A
;; ANSWER SECTION:
www.360.com. 40 IN A 27.115.124.133
;; Query time: 21 msec
;; SERVER: 114.114.114.114#53(114.114.114.114)
;; WHEN: Sat Jun 01 10:53:25 CST 2024
;; MSG SIZE rcvd: 67
解析IP
指定DNS服务器
dig @8.8.8.8 www.360.com
bash
[root@work ~]# dig @8.8.8.8 www.360.com
; <<>> DiG 9.11.4-P2-RedHat-9.11.4-26.P2.el7_9.13 <<>> @8.8.8.8 www.360.com
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 25763
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 512
;; QUESTION SECTION:
;www.360.com. IN A
;; ANSWER SECTION:
www.360.com. 117 IN A 106.63.103.8
www.360.com. 117 IN A 180.163.251.93
;; Query time: 53 msec
;; SERVER: 8.8.8.8#53(8.8.8.8)
;; WHEN: Sat Jun 01 11:12:26 CST 2024
;; MSG SIZE rcvd: 94
dig 的trace功能
dig工具可以查看递归查询的过程。
dig +trace +nodnssec www.360.com
bash
# +trace 表示开启跟踪查询
# +nodnssec 表示禁止DNS安全扩展
[root@work ~]# dig +trace +nodnssec www.360.com
; <<>> DiG 9.11.4-P2-RedHat-9.11.4-26.P2.el7_9.13 <<>> +trace +nodnssec www.360.com
;; global options: +cmd
. 1279 IN NS m.root-servers.net.
. 1279 IN NS g.root-servers.net.
. 1279 IN NS l.root-servers.net.
. 1279 IN NS c.root-servers.net.
. 1279 IN NS b.root-servers.net.
. 1279 IN NS d.root-servers.net.
. 1279 IN NS i.root-servers.net.
. 1279 IN NS e.root-servers.net.
. 1279 IN NS f.root-servers.net.
. 1279 IN NS j.root-servers.net.
. 1279 IN NS a.root-servers.net.
. 1279 IN NS h.root-servers.net.
. 1279 IN NS k.root-servers.net.
;; Received 431 bytes from 114.114.114.114#53(114.114.114.114) in 22 ms
com. 172800 IN NS d.gtld-servers.net.
com. 172800 IN NS m.gtld-servers.net.
com. 172800 IN NS i.gtld-servers.net.
com. 172800 IN NS g.gtld-servers.net.
com. 172800 IN NS j.gtld-servers.net.
com. 172800 IN NS c.gtld-servers.net.
com. 172800 IN NS f.gtld-servers.net.
com. 172800 IN NS b.gtld-servers.net.
com. 172800 IN NS l.gtld-servers.net.
com. 172800 IN NS h.gtld-servers.net.
com. 172800 IN NS e.gtld-servers.net.
com. 172800 IN NS k.gtld-servers.net.
com. 172800 IN NS a.gtld-servers.net.
;; Received 1535 bytes from 170.247.170.2#53(b.root-servers.net) in 139 ms
360.com. 172800 IN NS dns8.360safe.com.
360.com. 172800 IN NS dns7.360safe.com.
360.com. 172800 IN NS dns4.360safe.com.
360.com. 172800 IN NS dns1.360safe.com.
360.com. 172800 IN NS dns3.360safe.com.
360.com. 172800 IN NS dns2.360safe.com.
;; Received 454 bytes from 192.5.6.30#53(a.gtld-servers.net) in 64 ms
www.360.com. 300 IN A 27.115.124.133
360.com. 3600 IN NS dns4.360safe.com.
360.com. 3600 IN NS dns8.360safe.com.
360.com. 3600 IN NS dns9.360safe.com.
360.com. 3600 IN NS dns2.360safe.com.
360.com. 3600 IN NS dns1.360safe.com.
360.com. 3600 IN NS dns3.360safe.com.
360.com. 3600 IN NS dns7.360safe.com.
;; Received 326 bytes from 42.236.105.6#53(dns8.360safe.com) in 22 ms
上面的结果主要是包括4个部分,每一个部分,分别查询了根域名服务器(.),顶级域名(com.),二级域名(360.com.),最终域名(www.360.com.)