In one of our projects we had a problem with a host taking to long to respond. During our investigation the problem appeared to be in the DNS name resolving. The DNS server took to long to respond to the query. This happened not every time, but occasionally. To pinpoint the problem we made the following bash script to test the response times of the DNS server. The script is called from the Cron every hour, the response times are recorded in a CSV file.


#First check internet connection, when no connection exit.
ping -c 1 -t 100 1>/dev/null 2>/dev/null 
  rc=`echo $?`
#  echo $rc
  if [[ $rc == 1 ]]

#If the logfile is not present, write a first line with domains
if [[ ! -f $logfile ]]
    echo -n "date/time " >>$logfile
    for dm in `cat $configfile`
      echo -n ", $dm"    >>$logfile
    echo "; " >>$logfile

# Write the date to the logfile.
echo -n "$ra ">>$logfile
# Measure the DNS time for each domain name and write to the 
# logfile 
for dm in `cat $configfile`
   ra=`dig $dm |grep Query|awk '{print $4}'`
   echo -n ", $ra">>$logfile
echo "; ">>$logfile

The domainlist file shall look like this:

The cron tab shall contain a line like this: To edit the crontab enter crontab -e

47 * * * *  ~/nstime>>/dev/null

The script is named nstime. Make sure the script has execution rights.

chmod +x nstime

After some days we found the problem was with the name-server, it was not reachable occasionally. To solve the problem we installed a caching name-server at the PC which initiated the queries and set the TTL value in the DNS record to 84400 (24 hrs) The caching name server stores the IP address which is connected to the host. When the name server is unreachable, the caching name-server will resolve the host.