在我文章中有一篇专门讲解DNS如何工作的,今天我们采用linux下nslookup工具来查询DNS。nslookup全称是”query Internet name server interactively”,主要是是用来查询DNS。
在使用nslookup之前,先确保已经安装了它。nslookup属于bind-utils包下一个命令,bind-utils软件包中很多DNS工具,比如:dig和nslookup等。通过如下命令来检查:
[root@lv-centos ~]# rpm -q bind-utils
bind-utils-9.9.4-38.el7_3.1.x86_64
#如果没有显示,则安装
[root@lv-centos ~]# yum install bind-utils
nslookup有交互式和非交互式两种工作模式。 在命令行中直接输入nslookup,无需输入任何参数即进入交互模式,由>提示。
#采用默认的域名服务器进入交互模式
[root@lv-centos ~]# nslookup
>brianlv.com
#通过**- 地址**来指定域名服务器,进入交互模式
[root@lv-centos ~]# nslookup - 192.168.1.100
>brianlv.com
#直接输入域名进入非交互模式
[root@lv-centos ~]# nslookup brianlv.com
DNS主要由DomainName、TimeToLive、Class、Type和Value这五种资源组成,下面来介绍一它的具体含义:
SOA:Start of Authority,授权起始信息,包含了一个域名最基本的信息,如管理员邮箱、TTL信息等。
[root@lv-centos ~]# nslookup -type=soa pku.edu.cn
Server: 219.238.164.7
Address: 219.238.164.7#53
Non-authoritative answer:
pku.edu.cn
origin = ns.pku.edu.cn
mail addr = hostmaster.pku.edu.cn
serial = 2017012001
refresh = 3600
retry = 900
expire = 604800
minimum = 600
Authoritative answers can be found from:
pku.edu.cn nameserver = ns.pku.edu.cn.
pku.edu.cn nameserver = sun1000e.pku.edu.cn
pku.edu.cn nameserver = pkuns.pku.edu.cn.
ns.pku.edu.cn internet address = 202.112.7.13
pkuns.pku.edu.cn internet address = 162.105.129.27
sun1000e.pku.edu.cn internet address = 162.105.129.26
表示从域名解析到IP地址,俗称”A记录”。
[root@lv-centos ~]# nslookup -type=a pku.edu.cn
Server: 219.238.164.7
Address: 219.238.164.7#53
Non-authoritative answer:
Name: pku.edu.cn
Address: 162.105.131.196
[root@lv-centos ~]# nslookup -type=mx pku.edu.cn
Server: 219.238.164.7
Address: 219.238.164.7#53
Non-authoritative answer:
pku.edu.cn mail exchanger = 0 mx1.pku.edu.cn.
pku.edu.cn mail exchanger = 0 mx2.pku.edu.cn.
Authoritative answers can be found from:
pku.edu.cn nameserver = sun1000e.pku.edu.cn.
pku.edu.cn nameserver = pkuns.pku.edu.cn.
pku.edu.cn nameserver = ns.pku.edu.cn.
ns.pku.edu.cn internet address = 202.112.7.13
pkuns.pku.edu.cn internet address = 162.105.129.27
sun1000e.pku.edu.cn internet address = 162.105.129.26
[root@lv-centos ~]# nslookup -type=ns pku.edu.cn
Server: 219.238.164.7
Address: 219.238.164.7#53
Non-authoritative answer:
pku.edu.cn nameserver = pkuns.pku.edu.cn.
pku.edu.cn nameserver = sun1000e.pku.edu.cn.
pku.edu.cn nameserver = ns.pku.edu.cn.
Authoritative answers can be found from:
ns.pku.edu.cn internet address = 202.112.7.13
pkuns.pku.edu.cn internet address = 162.105.129.27
sun1000e.pku.edu.cn internet address = 162.105.129.26
先介绍这几种常用的类型,其他类型用的很少。
这里主要介绍nslookup交互模式的实战。
[root@lv-centos ~]# nslookup
> baidu.com
Server: 219.238.164.7
Address: 219.238.164.7#53
Non-authoritative answer:
Name: baidu.com
Address: 111.13.101.208
Name: baidu.com
Address: 180.149.132.47
Name: baidu.com
Address: 220.181.57.217
Name: baidu.com
Address: 123.125.114.144
> server 8.8.8.8
Default server: 8.8.8.8
Address: 8.8.8.8#53
> baidu.com
Server: 8.8.8.8
Address: 8.8.8.8#53
Non-authoritative answer:
Name: baidu.com
Address: 111.13.101.208
Name: baidu.com
Address: 123.125.114.144
Name: baidu.com
Address: 180.149.132.47
Name: baidu.com
Address: 220.181.57.217
> set all
Default server: 8.8.8.8
Address: 8.8.8.8#53
Set options:
novc nodebug nod2
search recurse
timeout = 0 retry = 3 port = 53
querytype = A class = IN
srchlist = DHCP/HOST
> set debug
> baidu.com
Server: 8.8.8.8
Address: 8.8.8.8#53
------------
QUESTIONS:
baidu.com, type = A, class = IN
ANSWERS:
-> baidu.com
internet address = 180.149.132.47
ttl = 412
-> baidu.com
internet address = 220.181.57.217
ttl = 412
-> baidu.com
internet address = 111.13.101.208
ttl = 412
-> baidu.com
internet address = 123.125.114.144
ttl = 412
AUTHORITY RECORDS:
ADDITIONAL RECORDS:
------------
Non-authoritative answer:
Name: baidu.com
Address: 180.149.132.47
Name: baidu.com
Address: 220.181.57.217
Name: baidu.com
Address: 111.13.101.208
Name: baidu.com
Address: 123.125.114.144
也可以指定set querytype=A/MX
现在体会到了nslookup的强大了吧,现在如果想成为武林高手不得不提到dig。在后面的文章中,我将介绍dig的用法。