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

I'm trying to get mod_security and hit the very common hostname error of

[alert] (EAI 2)Name or service not known: mod_unique_id: unable to find IPv4 address of ""

This normally means an entry is required in the hosts file. However I have tried all combinations for the hostname; localhost (, local IP address (192.168....) and public IP address (""). I have also tried all combinations for Apache's ServerName; computer.domain, domain, IP addresses and not setting it at all. Nothing seems to work for me.

Currently my /etc/hosts file looks like:

# Do not remove the following line, or various programs
# that require network functionality will fail.     computername localhost.localdomain localhost    
::1             localhost6.localdomain6 localhost6  computername

#          computername.hostingprovider.local  computername  # NIC <eth0>
# computername

Ping works, also hostname shows

[root@computername~]# hostname

The public dns doesn't have computername as a subdomain so what is the correct IP address / ServerName combo to use? What happens with duplicate entries on hosts? What does mod_unqiue_id check that could cause it to fail?

Thanks for any help you can provide

The underlying problem

Thanks for the strace suggestion. On starting apache I got the following.

1377  open("/etc/hosts", O_RDONLY)      = -1 EACCES (Permission denied)

So quickly sanity check permissions and:

# ll /etc/hosts
-rw-r--r-- 2 root root 608 Jul 22 16:01 /etc/hosts

But turned out be SELinux, see below

share|improve this question

2 Answers 2

up vote 4 down vote accepted

The problem was SELinux

#less /var/log/audit/audit.log

type=AVC msg=audit(1311546944.235:1040): avc:  denied  { read } for  pid=1396 comm="httpd" 
name="hosts" dev=dm-0 ino=262931 
tcontext=system_u:object_r:initrc_tmp_t:s0 tclass=file

In my case the following solved it:

# ls -lZ /etc/hosts
-rw-r--r--  root root system_u:object_r:initrc_tmp_t   /etc/hosts
# setenforce 0
# restorecon -R -F -v /etc/hosts
# setenforce 1
# ls -lZ /etc/hosts
-rw-r--r--  root root system_u:object_r:etc_t          /etc/hosts
share|improve this answer

I'd be looking for typos and other "stupidly simple" mistakes we all make from time to time (I use my wife as a proof-reader), but if that doesn't work I'd just fire up strace to see what mod_security is trying to do. It might not be reading /etc/hosts -- perhaps it's taking a failure to resolve the name via DNS as some sort of hard failure instead, or something else.

At any rate, I'd be putting the machine's name in DNS anyway. It just saves so many hassles.

share|improve this answer
Yes I've been struggling to rule out problems existing between the keyboard and the chair. Asking our hosting provider to add the computer name to the DNS would help but it would be nice to know why apache doesn't seem to process the hosts file – KCD Jul 24 '11 at 23:24
Awarded this as the solution because strace identified the true problem and a DNS entry would've solved it either way – KCD Jul 25 '11 at 1:11
It'd be worth putting the reason you found in as an answer, for future searchers who come across your question and would like to know exactly what the answer was. I'm curious too, now. – womble Jul 25 '11 at 5:27
I'm one step ahead of you, see the third section added to the question. SELinux was the problem, I'll edit it to make it clearer. Thanks again for your help! – KCD Jul 25 '11 at 22:03
I'm saying make it an answer, not part of your question -- self-answering is explicitly encouraged, as not everyone who finds the question will read the whole question, they'll skim just enough to see that it fits their problem and then skip straight to the answers. – womble Jul 25 '11 at 22:25

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.