I have a solution, that works for me; if it works for you, use it.
There are two files, that control how names are looked up: /etc/host.conf and /etc/nsswitch.conf. As far as I can tell, host.conf is old technology, superseded by nsswitch.conf. I do not know whether use of nsswitch.conf is hardwired, or host.conf is used as a fallback when nsswitch.conf is not present.
My /etc/host.conf has , which means /etc/hosts is searched first, then DNS.
My nsswitch.conf has
Code:
hosts: files mdns4_minimal [NOTFOUND=return] dns mdns4
which results in the same behavior: files, than DNS.
Does not matter: we leave both as is.
My /etc/hosts has two relevant lines:
Code:
127.0.0.1 localhost
127.0.0.1 my-hostname
And, of course, /etc/hostname has my-hostname.
So, because files are hit first, cannot get a FQDN, it only gets a short name. And Apache whines.
One way to try to fix this is to replace my-hostname in /etc/hosts with FQDN. This makes Apache happy, but lookups for my-hostname are broken (unless DNS knows how to resolve them) and lookups for FQDN (e.g. my-hostname.my-domain.net)return 127.0.0.1, which sucks.
You can add my-hostname on the same line with the FQDN. If you add it before the FQDN, the FQDN is not seen and Apache whines again. If you add it after the FQDN, things are OK, but both the hostname and the FQDN are resolved to 127.0.0.1 - gack!
The right thing is to have both the short name and the FQDN resolve to the real IP address.
If you do not have a functional DNS server on your network and your IP is static, just put the line with
Code:
123.45.67.89 my-host.my-domain.net my-host
in /etc/hosts (substitute real IP address/names).
If you do not have a functional DNS server and your IP is dynamic, go hack your DHCP scripts, so this gets fixed when your IP address changes. But in this case I suspect you are not running an Apache server, that can be accessed from outside your machine.
If you have a DNS server, then just comment out the line in /etc/hosts, so that the names - both short and long - are resolved via DNS.
This does the right thing for hostname, hostname --fqdn, Apache, etc. for short name, FQDN and localhost.
Bookmarks