30 May 2012

On local name resolving on Linux

Local name resolving in Linux distros can get confusing.
Case in point: man hostname(1)

Anyways, our fictional situation for today is this:

hostname: what you've named your machine
domainname: which domain you're on.
FDQN: hostname+domainname
You've probably named your machine something but didn't include the record into the domain's DNS.
Then you're trying to use hostname -a or hostname -f and get this error:

hostname: Name or service not known

You need to check 2 files if that happens: /etc/hostname and /etc/hosts.
This is what you should have (provided, of course, you're not running a NIS/YP and you're using a hostname which isn't configured domain's DNS):

/etc/hostname should contain 1 line: the hostname of the host.
If you do write the FDQN in there, no problem, it gets parsed anyhow.
I found out about this just about half an hour ago when looking into a problem together with a colleague.
/etc/hosts should contain at least 1 line with:   FQDN hostname

The order is /etc/hosts is important.
 The hostname in /etc/hosts and the hostname in /etc/hostname must be identical.

No comments:

Post a Comment