3

According to the docs for AWStats:

AWStats can do reverse DNS lookups through a static DNS cache file that was previously created manually.

Searching through the docs, as well as a fair bit of Googling, leaves me with one question. How do I manually create the DNS cache file? Is there a Linux command to do this that I've yet to find? This is on a Centos 5.5 machine.

John Gardeniers
  • 27,262
  • 12
  • 53
  • 108

2 Answers2

3

As it said underneath, you can use any text editor you want to create a text file with format ipaddress resolved_hostname, something like this:

192.168.1.11    websrv1
192.168.1.12    websrv2
192.168.1.13    websrv3

Don't forget to set DNSLookup=2.


I had expected to be able to create the file from existing information, such as the Apache logs.

Sure, you can do it by getting IP address from the Apache's access_log and use some tools such as: dig, host, resolveip, ... to resolve to host name, something like this:

$ awk '{ print $1 }' access_log | sort | uniq | \
while read ip; do \
    if [ `dig +short -x $ip | sed 's/\(.*\)\./\1/' | wc -l` -eq 1 ]; then \
        echo -e $ip\\t$(dig +short -x $ip | sed 's/\(.*\)\./\1/') >> dnscache.txt; \
    fi; \
done

To continue updating this file, you can run the above command as a cron job and filter only logs in a specific time range (equal to cron interval).

quanta
  • 50,327
  • 19
  • 152
  • 213
2

From the same manual that it says here

Note: DNS cache file format is 'minsince1970 ipaddress resolved_hostname' or just 'ipaddress resolved_hostname'

So you could generate it by doing something like:

host -t a google.com | awk '{ print $4 " " $1 }' > dnscache.txt

or if you have (as is more likely) IPs

for ip in 8.8.8.8; do 
    name=`host $ip | cut -d ' ' -f 5`
    if [ X"3(NXDOMAIN)" != X"$name" ]; then
        echo "$ip $name"
    fi
done > dnscache.txt

Really though you would want to do something with more error checking and something that works faster than awstats would.

AFresh1
  • 166
  • 3