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 "computername.domain.com"
This normally means an entry is required in the hosts file. However I have tried all combinations for the hostname; localhost (127.0.0.1), local IP address (192.168....) and public IP address ("122.56.11.156"). 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.
127.0.0.1 computername.domain.com computername localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6
192.168.0.102 computername.domain.com computername
#192.168.0.102 computername.hostingprovider.local computername # NIC <eth0>
#122.56.11.156 computername.domain.com computername
Ping works, also hostname shows
[root@computername~]# hostname
computername.domain.com
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
The problem was SELinux
In my case the following solved it:
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.