DNS测试工具
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了DNS测试工具相关的知识,希望对你有一定的参考价值。
一、dig命令
dig - 用于测试dns系统, 因此, 不会查询hosts文件进行解析.
# 用法: dig [@dns_server] [-t rr_type] name [query option]
正向解析测试:
# 用法: dig -t A FQDN [@dns_server]
# 示例:
[[email protected] named]# dig -t A www.leistudy.com @192.168.123.100
; <<>> DiG 9.9.4-RedHat-9.9.4-51.el7_4.2 <<>> -t A www.leistudy.com @192.168.123.100
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 29655
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 3
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;www.leistudy.com. IN A
;; ANSWER SECTION:
www.leistudy.com. 86400 IN A 192.168.123.100
;; AUTHORITY SECTION:
leistudy.com. 86400 IN NS ns2.leistudy.com.
leistudy.com. 86400 IN NS ns1.leistudy.com.
;; ADDITIONAL SECTION:
ns1.leistudy.com. 86400 IN A 192.168.123.100
ns2.leistudy.com. 86400 IN A 192.168.123.101
;; Query time: 0 msec
;; SERVER: 192.168.123.100#53(192.168.123.100)
;; WHEN: Thu Mar 29 17:11:04 CST 2018
;; MSG SIZE rcvd: 129
query option:
# query option
# +[no]trace: 跟踪解析过程
# +[no]recurse: 进行递归解析
# 示例:
[[email protected] named]# dig -t A www.baidu.com +trace
; <<>> DiG 9.9.4-RedHat-9.9.4-51.el7_4.2 <<>> -t A www.baidu.com +trace
;; global options: +cmd
. 5 IN NS l.root-servers.net.
. 5 IN NS i.root-servers.net.
. 5 IN NS e.root-servers.net.
. 5 IN NS j.root-servers.net.
. 5 IN NS b.root-servers.net.
. 5 IN NS c.root-servers.net.
. 5 IN NS a.root-servers.net.
. 5 IN NS f.root-servers.net.
. 5 IN NS d.root-servers.net.
. 5 IN NS k.root-servers.net.
. 5 IN NS h.root-servers.net.
. 5 IN NS g.root-servers.net.
. 5 IN NS m.root-servers.net.
;; Received 239 bytes from 192.168.123.2#53(192.168.123.2) in 836 ms
com. 172800 IN NS a.gtld-servers.net.
com. 172800 IN NS b.gtld-servers.net.
... # 内容太多, 省略
a.shifen.com. 1200 IN NS ns1.a.shifen.com.
a.shifen.com. 1200 IN NS ns4.a.shifen.com.
;; Received 239 bytes from 202.108.22.220#53(dns.baidu.com) in 59 ms
反向解析测试:
# 用法: dig -x IP [@dns_server]或者dig -t PTR IP [@dns_server]
# 示例:
[[email protected] named]# dig -x 61.135.169.121 @119.29.29.29
; <<>> DiG 9.9.4-RedHat-9.9.4-51.el7_4.2 <<>> -x 61.135.169.121 @119.29.29.29
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 44185
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;121.169.135.61.in-addr.arpa. IN PTR
;; AUTHORITY SECTION:
169.135.61.in-addr.arpa. 6135 IN SOA dns.baidu.com. sa.baidu.com. 2012091801 300 600 2592000 7200
;; Query time: 560 msec
;; SERVER: 119.29.29.29#53(119.29.29.29)
;; WHEN: Thu Mar 29 17:25:44 CST 2018
;; MSG SIZE rcvd: 108
模拟区域传送:
# 用法: dig -t axfr ZONE_NAME @dns_server
# 示例: 正向区域传送
[[email protected] ~]# dig -t axfr leistudy.com @192.168.123.132
; <<>> DiG 9.9.4-RedHat-9.9.4-51.el7_4.2 <<>> -t axfr leistudy.com @192.168.123.132
;; global options: +cmd
leistudy.com. 86400 IN SOA ns1.leistudy.com. admin.leistudy.com.leistudy.com. 2018030101 3600 300 604800 86400
leistudy.com. 86400 IN NS ns1.leistudy.com.
leistudy.com. 86400 IN NS ns2.leistudy.com.
leistudy.com. 86400 IN MX 10 mx1.leistudy.com.
leistudy.com. 86400 IN MX 20 mx2.leistudy.com.
ftp.leistudy.com. 86400 IN CNAME www.leistudy.com.
mx1.leistudy.com. 86400 IN A 192.168.123.132
mx2.leistudy.com. 86400 IN A 192.168.123.101
ns1.leistudy.com. 86400 IN A 192.168.123.132
ns2.leistudy.com. 86400 IN A 192.168.123.101
www.leistudy.com. 86400 IN A 192.168.123.132
leistudy.com. 86400 IN SOA ns1.leistudy.com. admin.leistudy.com.leistudy.com. 2018030101 3600 300 604800 86400
;; Query time: 3 msec
;; SERVER: 192.168.123.132#53(192.168.123.132)
;; WHEN: Sat Mar 03 10:12:28 CST 2018
;; XFR size: 12 records (messages 1, bytes 299)
# 示例: 反向区域传送
[[email protected] ~]# dig -t axfr 123.168.192.in-addr.arpa @192.168.123.132
; <<>> DiG 9.9.4-RedHat-9.9.4-51.el7_4.2 <<>> -t axfr 123.168.192.in-addr.arpa @192.168.123.132
;; global options: +cmd
123.168.192.in-addr.arpa. 86400 IN SOA ns1.leistudy.com. admin.leistudy.com. 2018030101 3600 300 604800 86400
123.168.192.in-addr.arpa. 86400 IN NS ns1.leistudy.com.
123.168.192.in-addr.arpa. 86400 IN NS ns2.leistudy.com.
101.123.168.192.in-addr.arpa. 86400 IN PTR mx2.leistudy.com.
132.123.168.192.in-addr.arpa. 86400 IN PTR ns1.leistudy.com.
132.123.168.192.in-addr.arpa. 86400 IN PTR mx1.leistudy.com.
132.123.168.192.in-addr.arpa. 86400 IN PTR www.leistudy.com.
123.168.192.in-addr.arpa. 86400 IN SOA ns1.leistudy.com. admin.leistudy.com. 2018030101 3600 300 604800 86400
;; Query time: 1 msec
;; SERVER: 192.168.123.132#53(192.168.123.132)
;; WHEN: Sat Mar 03 10:12:50 CST 2018
;; XFR size: 8 records (messages 1, bytes 244)
二、host命令
host - DNS查询工具.
# 用法: host [-t rr_type] name [dns_server]
# 示例1: 正向解析查询
[[email protected] named]# host -t A www.leistudy.com 192.168.123.100
Using domain server:
Name: 192.168.123.100
Address: 192.168.123.100#53
Aliases:
www.leistudy.com has address 192.168.123.100
# 示例2: NS记录查询
[[email protected] named]# host -t NS leistudy.com 192.168.123.100
Using domain server:
Name: 192.168.123.100
Address: 192.168.123.100#53
Aliases:
leistudy.com name server ns1.leistudy.com.
leistudy.com name server ns2.leistudy.com.
三、nslookup命令
nslookup - 查询域名的dns信息, 可通过交互式方式进行.
# 用法: nslookup [option] [name|-] [server]
# 交互模式:
~]# nslookup
nslookup>
# server IP: 指明使用哪个DNS服务器进行查询
# set q=RR_TYPE: 指明查询的资源记录类型
# NAME: 要查询的名称
[[email protected] named]# nslookup
> server 192.168.123.100 # 设置要查询的dns服务器
Default server: 192.168.123.100
Address: 192.168.123.100#53
> www.leistudy.com # 默认直接返回A记录对应的地址
Server: 192.168.123.100
Address: 192.168.123.100#53
Name: www.leistudy.com
Address: 192.168.123.100
> set q=NS # 指明查询NS记录
> leistudy.com
Server: 192.168.123.100
Address: 192.168.123.100#53
leistudy.com nameserver = ns1.leistudy.com.
leistudy.com nameserver = ns2.leistudy.com.
> set q=A # 指明查询A记录
> web.leistudy.com
Server: 192.168.123.100
Address: 192.168.123.100#53
web.leistudy.com canonical name = www.leistudy.com.
Name: www.leistudy.com
Address: 192.168.123.100
以上是关于DNS测试工具的主要内容,如果未能解决你的问题,请参考以下文章
elasticsearch代码片段,及工具类SearchEsUtil.java