操作系统环境准备
- 操作系统建议使用ubuntu,如果使用CentOS会有较多的系统组件无法yum安装,需要再去寻找源文件编译安装。
- ubuntu需安装桌面环境,如果没有安装桌面环境,执行./autogen.sh会报“error: possibly undefined macro: AC_MSG_NOTICE“等找不到宏错误
dnsperf安装
-
官方推荐了两种安装方式,通过下载源码和git仓库。下面简单说下下载源码安装的方式(该方式反复测试安装失败,不推荐)
通过https://www.dns-oarc.net/tools/dnsperf下载最新的源码压缩包
tar zxvf dnsperf-version.tar.gz
cd dnsperf-version
./configure [options]
make
make install
Git仓库安装
安装依赖包及需要用的编译工具
sudo apt install -y git autoconf automake make libtool pkg-config check g++ libz-dev librsync-dev libssl-dev libldns-dev libck-dev libyajl-dev libnghttp2-dev uthash-dev
git clone https://github.com/DNS-OARC/dnsperf.git
cd dnsperf
cd src
vim dnsperf.c
修改socket最大值,默认是256
cd ..
./autogen.sh
./configure
make
make install
可能遇到的问题解决
./autogen.sh出现报错
报错:./autogen.sh: 19: ./autogen.sh: autoreconf: not found
解决方法:执行apt-get install automake autoconf libtool命令
./configure出现报错
第一种:
报错:configure: error: cannot find install-sh, install.sh, or shtool in "." "./.." "./../.."
问题原因:configure脚本的自动构建系统有问题
解决方法:执行autoreconf -vif命令重建
第二种:
报错:./configure: line 5859: syntax error near unexpected token `disable-static'
./configure: line 5859: `LT_INIT(disable-static)'
问题原因:软件包缺失,脚本无法执行
解决方法:apt-get install make pkg-config check g++ librsync-dev libz-dev libssl-dev uthash-dev libyajl-dev,如果执行完前面的命令还不行,再执行一遍autoreconf -vif
第三种:
报错:configure: error: libck headers not found
问题原因:没有libck-dev软件包
解决方法:执行apt install libck-dev
第四种:
报错:configure: error: nghttp2 headers not found
问题原因:没有libnghttp2-dev软件包
解决方法:执行apt install libnghttp2-dev
dnsperf使用
参数详解
-a the local address from which to send queries
-b socket send/receive buffer size in kilobytes
-x the local port from which to send queries (default: 0)
-s 用来指定DNS服务器的IP地址,默认值是127.0.0.1
-S print qps statistics every N seconds
-p 用来指定DNS服务器的端口,默认值是53
-d 用来指定DNS消息的内容文件,该文件中包含要探测的域名和资源记录类型,见下文
-D set the DNSSEC OK bit (implies EDNS)
-t 用来指定每个请求的超时时间,默认值是3000ms
-T the number of threads to run
-Q 用来指定本次压测的最大请求数,默认值是1000
-c 用来指定并发探测数,默认值是100. dnsperf会从-d指定的文件中随机选取100个座位探测域名来发送DNS请求.
-l 用来指定本次压测的时间,默认值是无穷大。
-n run through input at most N times
-e 本选项通过EDNS0,在OPT资源记录中运用edns-client-subnet来指定真实的client ip.
-E send EDNS option
-P 指定用哪个传输层协议发送DNS请求,udp或者tcp。默认值是udp
-f 指定用什么地址类型发送DNS请求,inet或者inet6。默认值是inet
-y the TSIG algorithm, name and secret
-q the maximum number of queries outstanding (default: 100)
-u send dynamic updates instead of queries
-v 除了标准的输出外,还输出每个相应码的个数。
-h 打印帮助
数据文件示例
上文中提到,-d选项指定数据文件名,数据文件示例如下:
1 # This is a comment and is ommited
2 # The columns after column 2 will be ommited if one line contains more than 3 colums.
3 www.app1.com A
数据文件中以“#”开头的行被认为是注释行,会被dnsperf忽略。
其中有效数据由两列组成,第一列是查询域名,第二列是查询的资源类型,dnsperf支持的资源类型如下:
A,NS,MD,MF,CNAME,SOA,MB,MG,MR,NULL,WKS,PTR,HINFO,MINFO,MX,TXT,AAAA,SRV,NAPTR,A6,ASFR,MAILB,MAILA,ANY.
如果请求很多次,要写入非常多域名,如
for i in $(seq 1 999999);do echo "www.aliyun.com A" >> dnsprob.txt; done
执行
dnsperf -d dnsprob.txt -s 223.5.5.5 -c 28000 -Q 50000 -l 600
如果提示Error: socket: Too many open files则需要配置下ulimit -n 65535
测试结果指标详解
下图是一个示例输出:标准输出中,queies sent是指本次探测发送的总请求数,queries completed是指本次探测收到响应的请求数,run time是指本次探测的时间,queries per second是指本次探测的QPS。
总结
dnsperf可以用于一般的DNS服务器压力测试,但是无法执行高突发请求,按照当前的测试结果,最大每秒钟大概6000多个包,对于模拟针对于DNS的dos攻击测试数量级远远不够。