Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

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).

share|improve this answer
    
Looks like I may have misunderstood things a bit. I had expected to be able to create the file from existing information, such as the Apache logs. –  John Gardeniers Oct 3 '11 at 2:49
    
I've updated my answer. –  quanta Oct 3 '11 at 3:47
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.