Shell Script To Build dnstop Utility To Displays Various Tables Of DNS Server Traffic

#!/bin/bash
# A shell script to build dnstop utility to displays various tables 
# of DNS traffic on your network including bind 9 server stats.
# -------------------------------------------------------------------------
# Tested under CentOS / RHEL / Fedora Linux only.
# -------------------------------------------------------------------------
# Copyright (c) 2008 nixCraft project <http://cyberciti.biz/fb/>
# This script is licensed under GNU GPL version 2.0 or above
# -------------------------------------------------------------------------
# This script is part of nixCraft shell script collection (NSSC)
# Visit http://bash.cyberciti.biz/ for more information.
# -------------------------------------------------------------------------
# Last updated on Mar/05/2010
# -------------------------------------------------------------------------
# Home page: http://dns.measurement-factory.com/tools/dnstop/
VERSION="-20090128"
URL="http://dns.measurement-factory.com/tools/dnstop/src/dnstop${VERSION}.tar.gz"
FILE="${URL##*/}"
DLHOME="/opt"
SOFTWARE="dnstop"
DEST="${FILE%.tar.gz}"
ETH="eth0"
 
[[ "$2" != "" ]] && ETH="$2"
 
[[ `id -u` -ne 0 ]] && { echo "$0: You must be root user to run this script. Run it as 'sudo $0'"; exit 1; }
 
case "$1" in
    download) 
        wget $URL -O "${DLHOME}/$FILE"
        ;;
    build) 
        echo "Building ${SOFTWARE}...."
        # this needs some improvements, bur right now I am just gonna try to install it ;( 
	yum -y install libpcap-devel ncurses-devel &>/dev/null
        [[ ! -f "${DLHOME}/$FILE" ]] &&  wget $URL -O "${DLHOME}/$FILE"
        cd "${DLHOME}"
        tar -zxvf $FILE
        cd "$DEST"
        ./configure
        make
        make install
        grep -q 'alias dnstop' $HOME/.bashrc        
        [ $? -ne 0 ] && echo "alias dnstop='/usr/local/bin/dnstop -l 6 ${ETH}'" >> $HOME/.bashrc
        ;;
    *) echo "Usage: $0 {download|build} [eth0|eth1]"
esac

dnstop

From the man page:

dnstop is a small tool to listen on device or to parse the file savefile and collect and print statistics on the local network’s DNS traffic. You must have read access to /dev/bpf*.

How Do I Use This Script?

Download type the following command:
./script.sh build
/usr/local/bin/dnstop -l 6 eth0

Get the latest tutorials on SysAdmin, Linux/Unix, Open Source, and DevOps topics:
CategoryList of Unix and Linux commands
File Management cat
Firewall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilities dig host ip nmap
OpenVPN CentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Manager apk apt
Processes Management bg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searching grep whereis which
User Information groups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPN CentOS 8 Debian 10 Firewall Ubuntu 20.04
4 comments… add one
  • Indie May 20, 2011 @ 0:24

    For Ubuntu you can simply do

    sudo apt-get install dnstop
  • Alex Apr 28, 2011 @ 8:43

    The script surely would work only on rpm-based Linuxes, as it uses the “yum” command.
    Maybe if you changed this one line to equivalent apt command…?

  • oussama larhmich Sep 6, 2010 @ 10:44

    hi,

    thinks for this articles but,will it work in Ubuntu Server ??

  • vivek Mar 24, 2010 @ 8:44

    hi,
    Tthis article is nic, will it work in debian & use linux?

Leave a Reply

Your email address will not be published. Required fields are marked *

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.