Apache Mod_Unique_ID – Unable to Find IPv4 Address of FQDN

apache-2.2hosts-filemod-securityselinux

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

Best Answer

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 
scontext=user_u:system_r:httpd_t:s0 
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