Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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:    websrv1    websrv2    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; \

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

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 | awk '{ print $4 " " $1 }' > dnscache.txt

or if you have (as is more likely) IPs

for ip in; do 
    name=`host $ip | cut -d ' ' -f 5`
    if [ X"3(NXDOMAIN)" != X"$name" ]; then
        echo "$ip $name"
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

Your Answer


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.