Take the 2-minute tour ×
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 192.168.1.93, should I change /etc/hosts from

127.0.0.1 localhost.localdomain localhost

to

127.0.0.1 localhost.cluster localhost
192.168.1.93 computernode1.cluster computenode1

or

127.0.0.1 localhost
192.168.1.93 computenode1

or

#127.0.0.1 localhost
192.168.1.93 computenode1

or

192.168.1.93 localhost
192.168.1.93 computenode1
share|improve this question

2 Answers 2

up vote 6 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:

127.0.0.1 fully.qualified.hostname hostname localhost.localdomain localhost

or

127.0.0.1 localhost.localdomain localhost
1.2.3.4 fully.qualified.hostname hostname
share|improve this answer
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

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 127.0.0.1 localhost or 127.0.0.1 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

 
discard

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.