一般来说linux下查询域名解析有两种选择,nslookup或者dig,而在使用上我觉得dig更加方便顺手。
如果是在debian下的话,只要装上dnsutils这个包就可以使用dig命令了。
最基本的使用方式就是
dig
即查询域名的A记录,查询的dns服务器将采用系统配置的服务器,即/etc/resovle.conf 中的。
如果要查询其他类型的记录,比如MX,CNAME,NS,PTR等,只需将类型加在命令后面即可
dig mx
dig ns
此外,如果你是一个系统管理员,部署好了一台dns服务器之后想对它进行解析测试,就必须要显式指定待测试的dns服务器地址了,例如
dig @202.106.0.20 a
默认情况下dig将采用udp协议进行查询,如果要采用tcp方式,可以加上 +tcp参数
dig a +tcp
另外一个重要的功能是+trace参数,使用这个参数之后将显示从根域逐级查询的过程
dig a +trace
比如,对本站域名www.linuxers.cn A记录的trace查询可以看到根域.,顶级域.cn,以及linuxers.cn的域名权威服务器的地址及其各自的返回结果,这样对于追踪dns解析中的问题有很大的帮助。
leconte@localhost:~$ dig www.linuxers.cn a +trace
; <<>> DiG 9.5.1-P3 <<>> www.linuxers.cn a +trace
;; global options: printcmd
. 215857 IN NS .
. 215857 IN NS .
. 215857 IN NS .
. 215857 IN NS .
. 215857 IN NS .
. 215857 IN NS .
. 215857 IN NS .
. 215857 IN NS .
. 215857 IN NS .
. 215857 IN NS .
. 215857 IN NS .
. 215857 IN NS .
. 215857 IN NS .
;; Received 228 bytes from 192.168.127.2#53(192.168.127.2) in 12 ms
cn. 172800 IN NS .
cn. 172800 IN NS .
cn. 172800 IN NS .
cn. 172800 IN NS .
cn. 172800 IN NS .
cn. 172800 IN NS .
;; Received 298 bytes from 199.7.83.42#53() in 496 ms
linuxers.cn. 21600 IN NS .
linuxers.cn. 21600 IN NS .
;; Received 80 bytes from 202.112.0.44#53() in 12 ms
www.linuxers.cn. 600 IN A 218.240.42.72
;; Received 49 bytes from 222.186.26.115#53() in 1132 ms
















