在Linux和Windows下都可以用nslookup命令来查询域名的解析结果,如图1-13所示。
在Linux系统中还可以使用dig命名来查询DNS的解析过程,如下所示:
[junshan@v101055.sqa.cm4 admin]$ dig www.taobao.com
; <<>> DiG 9.3.6-P1-RedHat-9.3.6-4.P1.el5 <<>> www.taobao.com
;; global options: printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 16903
;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 3, ADDITIONAL: 3
;; QUESTION SECTION:
;www.taobao.com. IN A
;; ANSWER SECTION:
www.taobao.com. 1542 IN CNAME www.gslb.taobao.com.
www.gslb.taobao.com. 130 IN A 115.238.23.251
www.gslb.taobao.com. 130 IN A 115.238.23.241
;; AUTHORITY SECTION:
gslb.taobao.com. 70371 IN NS gslbns3.taobao.com.
gslb.taobao.com. 70371 IN NS gslbns1.taobao.com.
gslb.taobao.com. 70371 IN NS gslbns2.taobao.com.
;; ADDITIONAL SECTION:
gslbns1.taobao.com. 452 IN A 121.0.23.218
gslbns2.taobao.com. 452 IN A 115.124.17.70
gslbns3.taobao.com. 452 IN A 110.75.3.193
;; Query time: 5 msec
;; SERVER: 10.232.2.254#53(10.232.2.254)
;; WHEN: Sun Feb 12 19:19:05 2012
;; MSG SIZE rcvd: 201
结果的第1行输出了当前Linux的版本号,第2行说明可以增加可选参数printcmd,如果加上printcmd,打印出来的结果如下:
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 58602
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 0
;; QUESTION SECTION:
;printcmd. IN A
;; AUTHORITY SECTION:
. 10800 IN SOA a.root-servers.net. nstld. verisign-grs.com. 2012021200 1800 900 604800 86400
;; Query time: 208 msec
;; SERVER: 10.232.2.254#53(10.232.2.254)
;; WHEN: Sun Feb 12 19:20:59 2012
;; MSG SIZE rcvd: 101
“QUESTION SECTION”部分表示当前查询的域名是一个 A 记录,“ANSWER SECTION”部分返回了这个域名由CNAME到www.gslb.taobao.com,返回了这个域名对应的IP地址。
还可通过增加+trace参数跟踪这个域名的解析过程,如下所示:
[junshan@v101055.sqa.cm4 admin]$ dig www.taobao.com +trace
; <<>> DiG 9.3.6-P1-RedHat-9.3.6-4.P1.el5 <<>> www.taobao.com +trace
;; global options: printcmd
. 449398 IN NS k.root-servers.net.
. 449398 IN NS l.root-servers.net.
. 449398 IN NS m.root-servers.net.
. 449398 IN NS a.root-servers.net.
. 449398 IN NS b.root-servers.net.
. 449398 IN NS c.root-servers.net.
. 449398 IN NS d.root-servers.net.
. 449398 IN NS e.root-servers.net.
. 449398 IN NS f.root-servers.net.
. 449398 IN NS g.root-servers.net.
. 449398 IN NS h.root-servers.net.
. 449398 IN NS i.root-servers.net.
. 449398 IN NS j.root-servers.net.
;; Received 272 bytes from 10.232.2.254#53(10.232.2.254) in 0 ms
com. 172800 IN NS a.gtld-servers.net.
com. 172800 IN NS b.gtld-servers.net.
com. 172800 IN NS c.gtld-servers.net.
com. 172800 IN NS d.gtld-servers.net.
com. 172800 IN NS e.gtld-servers.net.
com. 172800 IN NS f.gtld-servers.net.
com. 172800 IN NS g.gtld-servers.net.
com. 172800 IN NS h.gtld-servers.net.
com. 172800 IN NS i.gtld-servers.net.
com. 172800 IN NS j.gtld-servers.net.
com. 172800 IN NS k.gtld-servers.net.
com. 172800 IN NS l.gtld-servers.net.
com. 172800 IN NS m.gtld-servers.net.
;; Received 492 bytes from 193.0.14.129#53(k.root-servers.net) in 607 ms
taobao.com. 172800 IN NS ns1.taobao.com.
taobao.com. 172800 IN NS ns2.taobao.com.
taobao.com. 172800 IN NS ns3.taobao.com.
;; Received 134 bytes from 192.5.6.30#53(a.gtld-servers.net) in 250 ms
www.taobao.com. 1800 IN CNAME www.gslb.taobao.com.
gslb.taobao.com. 86400 IN NS gslbns2.taobao.com.
gslb.taobao.com. 86400 IN NS gslbns3.taobao.com.
gslb.taobao.com. 86400 IN NS gslbns1.taobao.com.
;; Received 169 bytes from 110.75.1.19#53(ns1.taobao.com) in 0 ms
上面清楚地显示了整个域名是如何发起和解析的,从根域名(.)到gTLD Server(.com.)再到Name Server(taobao.com.)的整个过程都显示出来了。还可以看出DNS的服务器有多个备份,可以从任何一台查询到解析结果。