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

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
  • 1
    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
  • 1
    sudo also complains if hostname is not in /etc/hosts: sudo: unable to resolve host <hostname> – x-yuri Oct 14 '15 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.


You have to specify fully qualified domain name in the first position after IP address.

As we read in man 5 hosts:

For each host a single line should be present with the following information:

IP_address canonical_hostname [aliases...]

If not following the rule, then some software may break. For example, Puppet configuration management system may start changing your hostname back and forth on each run just because you did not specify domain part or because you put alias without domain on the line before FQDN.


I'm not sure this is really "optional" (as Patrick indicated above). I just finally tracked down a problem with nfs permissions reverting to nobody:nobody. It looks like for permissions to properly work with nfs mounts (using idmapd), the domain name of the server has to match the domain name of the client exactly. From some docs I found -- hostname -f minus the actual hostname has to be identical between client and server OR you have to specify a domain name for the client in /etc/idmapd.conf, which means each client.

Is there an official rule about where to specify domain name? The domainname command doesn't seem to pick it up out of /etc/hosts.. so putting in /etc/hosts bothers me, since it means it's stored in multiple locations on the filesystem..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.