LoginSignup
10
9

More than 5 years have passed since last update.

DNS Queryのリアルタイム統計をサーバ内で表示(dnstop編)

Last updated at Posted at 2016-01-08

DNSの統計を出したり、性能を計るツールはいくつか出回っていますが、
今回はdnstopを動かしてみます。

dnstop:
http://dns.measurement-factory.com/tools/dnstop/

動きとしては、pcapを元にQueryの割合やSourceIPのランキングなどをリアルタイム表示します。
たぶん、ISP等で公開してるCache DNS等で無いと表示してもつまらないかもしれません。

パッケージ類もあるようですが今回はSourceを持ってくるところから行きたいと思います。
複雑な事はないのでサクっとインストールできると思います。

テスト環境

  • CentOS 6系(Digital Oceanを使ってます)

*ちなみにEPELにはあるみたいなのでSourceからいちいち入れなくてもOKのようです。

スクリーンショット 2016-01-08 17.56.59.png

インストールなど

1.必要なものをインストールします

データをキャプチャするのにpcap
データを描画させるのにncurses
を使う模様

# yum install libpcap-devel
# yum install ncurses-devel

2.Sourceをダウンロード

そしてtarball解凍まで
http://dns.measurement-factory.com/tools/dnstop/src/より

# wget http://dns.measurement-factory.com/tools/dnstop/src/dnstop-20140915.tar.gz
# tar zxvf dnstop-20140915.tar.gz
dnstop-20140915/
dnstop-20140915/LICENSE
dnstop-20140915/lookup3.c
dnstop-20140915/new_gtlds.h
dnstop-20140915/known_tlds.h
dnstop-20140915/inX_addr.h
dnstop-20140915/inX_addr.c
dnstop-20140915/hashtbl.h
dnstop-20140915/hashtbl.c
dnstop-20140915/dnstop.c
dnstop-20140915/CHANGES
dnstop-20140915/dnstop.8
dnstop-20140915/install-sh
dnstop-20140915/config.h.in
dnstop-20140915/Makefile.in
dnstop-20140915/configure
dnstop-20140915/configure.ac

3.configure&make

今回は特にオプション類は指定せずにmake installまで

# cd dnstop-20140915/
# ./configure
# make
gcc -g -O2 -DUSE_IPV6=1  -o dnstop dnstop.o hashtbl.o inX_addr.o lookup3.o -lresolv -lnsl -lpcap -lncurses
#
# make install
install -m 755 dnstop /usr/local/bin
install -m 644 dnstop.8 /usr/local/share/man/man8
#

4.コマンドを試す

まずは何も付けずに実行
何やらqueryのfilterも一応できるみたいですが
もう少し種類があっても良いような!?

# /usr/local/bin/dnstop
usage: usr/local/bin/dnstop [opts] netdevice|savefile
    -4  Count IPv4 packets
    -6  Count IPv6 packets
    -Q  Count queries
    -R  Count responses
    -a  Anonymize IP Addrs
    -b expr BPF program code
    -i addr Ignore this source IP address
    -n name Count only messages in this domain
    -p  Don't put interface in promiscuous mode
    -P  Print "progress" messages in non-interactive mode
    -r  Redraw interval, in seconds
    -l N    Enable domain stats up to N components
    -X  Don't tabulate the "source + query name" stats
    -f  filter-name

Available filters:
    unknown-tlds
    A-for-A
    rfc1918-ptr
    refused
    qtype-any
#

5.実行例

ちなみに
抜けるときは Ctrl + x
統計データをリセットは Ctrl + R

# dnstop -l3 eth0

今回はローカルにbindを立てた上で
dnsperf(nominum社のdns performance測定ツール)を
まわした状態でdnstopを叩いてみました
http://nominum.com/measurement-tools/

初期実行画面

どこのSourceIPからどのくらいQueryが来てるか確認できます

Queries: 0 new, 200 total                                                                                                            Fri Jan  8 04:52:00 2016

Sources             Count      %   cum%
--------------- --------- ------ ------
XXX.XXX.XXX.XXX       200  100.0  100.0

domainランキング表示

先ほどの実行例のように-l nオプションを付けておくとnのレベルでのランキング表示が可能になります
今回の実行例では最大表示範囲は3rdレベルまで可能になる

dnstopを実行した後の状態でキーボードの3を押してみましょう
問い合わせが来ているdomainの3rdレベルでのランキングに変わります
(dnstopをmanしたところによると、-l nはCPUとmemoryが消費が通常より多くなるみたいなので範囲指定時は注意)

3を押してみる
Queries: 0 new, 282 total                          Fri Jan  8 04:44:29 2016

Query Name                       Count      %   cum%
--------------------------- --------- ------ ------
ak.fbcdn.net                       18    6.4    6.4
a.root-servers.net                 13    4.6   11.0
google.com.mx                       3    1.1   12.1
168.192.in-addr.arpa                3    1.1   13.1
avqs.mcafee.com                     3    1.1   14.2
www.facebook.com                    3    1.1   15.2
www.google.com                      2    0.7   16.0
chttl.com.tw                        2    0.7   16.7
da1.akamai.net                      2    0.7   17.4
dns.msftncsi.com                    2    0.7   18.1
accounts.google.com                 2    0.7   18.8

ちなみに1を押すとトップレベル単位でのランキング

1を押すと
Queries: 0 new, 181 total           Fri Jan  8 04:48:53 2016

Query Name       Count     %   cum%
------------ --------- ------ ------
com                 90   49.7   49.7
net                 34   18.8   68.5
in-addr.arpa        24   13.3   81.8
ru                   4    2.2   84.0
uk                   3    1.7   85.6
org                  3    1.7   87.3
lan                  2    1.1   88.4
ar                   2    1.1   89.5
_tcp                 2    1.1   90.6
ch                   2    1.1   91.7

Queryタイプでも表示できます

qを押すと
Queries: 0 new, 397 total          Fri Jan  8 04:57:01 2016

Query Type     Count      %   cum%
---------- --------- ------ ------
A?               271   68.3   68.3
PTR?              50   12.6   80.9
MX?               39    9.8   90.7
AAAA?             37    9.3  100.0

その他

dnstop実行中に表示されているcum%は
cumulative percentage totals
の事のようです

10
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
9