Sign up ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

I am setting up a VMWare cluster of CentOS nodes. Is it best practice to include a domain name after the machine? What are the potential problems of leaving it out? Does a domain complicate configuration or simplify it?

For example, if my node is at, should I change /etc/hosts from localhost.localdomain localhost

to localhost.cluster localhost computernode1.cluster computenode1

or localhost computenode1


# localhost computenode1

or localhost computenode1
share|improve this question

2 Answers 2

up vote 8 down vote accepted

Putting the domain name in /etc/hosts is optional, and you can run a system without any ill effect at all.

The only downside of leaving it out is that the system's fully qualified hostname won't show up properly. For example, hostname -f.

The way detection of the fully qualified host name works:

  1. It first gets the hostname, or 'shortname'. This is the output of uname -n or hostname.
  2. It then gets the IP address for that hostname by consulting /etc/hosts (or whatever you have in /etc/resolv.conf, and falling back to the latter sources if not found in /etc/hosts).
  3. Once it has the IP it then does a reverse lookup by again consulting /etc/hosts.
  4. Once it has a record in /etc/hosts, the first entry is used as the fully qualified hostname.

In a nutshell, if you want fully qualified hostname to work, you should do either: fully.qualified.hostname hostname localhost.localdomain localhost

or localhost.localdomain localhost fully.qualified.hostname hostname
share|improve this answer
I didn't consider that point. Having a fully qualified hostname is useless for a desktop PC, and can be problematic for a laptop (because a laptop is likely to be brought in different networks) but it's useful for a server. Apache2, for example, complains when it cannot determine its FQDN. – lgeorget Jun 2 '13 at 3:08
@lgeorget You can also just use libnss-myhostname which takes care of resolving your FQDN but doesn't need an entry in /etc/hsots – Ulrich Dangel Jun 2 '13 at 7:34
The configuration above may cause problems, see this discussion on Debian’s current practice of setting up the hosts file, and this one on the usage (or lack thereof) of the localhost.localdomain entry. – Joó Ádám Nov 4 '14 at 15:14
sudo also complains if hostname is not in /etc/hosts: sudo: unable to resolve host <hostname> – x-yuri Oct 14 at 17:24

As long as your host agrees with your domain name, specifying it or not in /etc/hosts won't change anything. Another practice is to have it specified as the domain parameter in /etc/resolv.conf. Not specifying it could simplify your life if, one day, your network administrator changes it. Specifying it doesn't change anything, as far as I know.

You should definitely leave localhost or localhost localhost.localdomain in /etc/hosts. Some applications could start having a really strange behaviour is localhost binds to anything other than your loopback address because this is a really, really, unexpected setting.

share|improve this answer

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.