Tell me more ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I've noticed that the "preferred" method of setting the system hostname is fundamentally different between Red Hat/CentOS and Debian/Ubuntu systems.

CentOS documentation and the RHEL deployment guide say the hostname should be the FQDN:

HOSTNAME=<value>, where should be the Fully Qualified Domain Name (FQDN), such as hostname.expample.com, but can be whatever hostname is necessary.

The RHEL install guide is slightly more ambiguous:

Setup prompts you to supply a host name for this computer, either as a fully-qualified domain name (FQDN) in the format hostname.domainname or as a short host name in the format hostname.

The Debian reference says the hostname should not use the FQDN:

3.5.5. The hostname

The kernel maintains the system hostname. The init script in runlevel S which is symlinked to "/etc/init.d/hostname.sh" sets the system hostname at boot time (using the hostname command) to the name stored in "/etc/hostname". This file should contain only the system hostname, not a fully qualified domain name.

I haven't seen any specific recommendations from IBM about which to use, but some software seems to have a preference.

My questions:

  • In a heterogeneous environment, is it better to use the vendor recommendation, or choose one and be consistent across all hosts?
  • What software have you encountered which is sensitive to whether the hostname is set to the FQDN or short name?
share|improve this question

5 Answers

up vote 29 down vote accepted

I would choose a consistent approach across the entire environment. Both solutions work fine and will remain compatible with most applications. There is a difference in manageability, though.

I go with the short name as the HOSTNAME setting, and set the FQDN as the first column in /etc/hosts for the server's IP, followed by the short name.

I have not encountered many software packages that enforce or display a preference between the two. I find the short name to be cleaner for some applications, specifically logging. Maybe I've been unlucky in seeing internal domains like server.northside.chicago.rizzomanufacturing.com. Who wants to see that in the logs or a shell prompt?

Sometimes, I'm involved in company acquisitions or restructuring where internal domains and/or subdomains change. I like using the short hostname in these cases because logging, kickstarts, printing, systems monitoring, etc. do not need full reconfiguration to account for the new domain names.

A typical RHEL/CentOS server setup for a server named "Rizzo" with internal domain "ifp.com", would look like:

/etc/sysconfig/network:
Rizzo

-

/etc/hosts:
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

172.16.100.13   Rizzo.ifp.com rizzo

-

[root@Rizzo ~]# hostname 
Rizzo

-

/var/log/messages snippet:
Dec 15 10:10:13 Rizzo proftpd[19675]: 172.16.100.13 (::ffff:206.15.236.182[::ffff:206.15.236.182]) - Preparing to               
 chroot to directory '/app/upload/GREEK'
Dec 15 10:10:51 Rizzo proftpd[20660]: 172.16.100.13 (::ffff:12.28.170.2[::ffff:12.28.170.2]) - FTP session opened.
Dec 15 10:10:51 Rizzo proftpd[20660]: 172.16.100.13 (::ffff:12.28.170.2[::ffff:12.28.170.2]) - Preparing to chroot                
to directory '/app/upload/ftp/SRRID'
share|improve this answer
6  
Like you, I prefer the short name, however I discovered recently that some Oracle applications require the output of hostname to be the FQDN. Just having it in /etc/hosts isn't good enough. That messed with my consistency. – James O'Gorman Dec 20 '11 at 18:36

Pretty much all software is sensitive to correctly setting the hostname. While I was working at Digg I once brought the entire site down for 2 hours due to making a seemingly innocent change in /etc/hosts that affected the system's notion of hostname. Tread lightly. That said, you may be slightly confused here. I don't think the HOSTNAME= setting is directly equivalent to how Debian-based distributions use /etc/hostname.

What works for me in a heterogeneous environment is:

1. Set the hostname in the vendor-recommended manner, using a conditional in your config management software.
2. Use the "hostname" command to set the hostname used by the kernel, etc.
3. In /etc/hosts:

127.0.0.1    localhost
10.0.0.1     hostname.example.com     hostname

This configuration has not failed me yet.

share|improve this answer
This is pretty much the setup I use at work. The shortname should be fine as long as the domain name is in the DNA search path (/etc/resolv.conf) for the relevant machines in your environment – gWaldo Nov 25 '11 at 12:11

You will certainly have no problem finding references online which will tell you to definitely do it one way or another. It seems to me however that having a short name as the hostname, and have the fully qualified name in /etc/hosts is certainly much more prevalent. It seems like the more sensible way, as then services which need a fully qualified name can be adapted to call hostname --fqdn instead.

I've only come across one piece of software recently which rigidly requires a fqdn to be returned by hostname, which was ganeti. They document this here. I don't see any reason they cannot adapt to hostname --fqdn, however.

share|improve this answer
Bonus for providing an example! Thanks. – Cakemox Dec 21 '11 at 14:53

The /etc/hosts options works well.

But you want to make sure that all the proper files are updated run the setup tool

share|improve this answer
My distribution doesn't have a "setup" tool; which distribution are you using that has one? – nickgrim Nov 25 '11 at 14:33
any redhat based OS has the setup tool rhel/centos/fedora whar OS are you using? – QXT Nov 25 '11 at 17:10
1  
Since the question talks about differences between RHEL-based and Debian-based distros, we must assume the asker uses both. There is no 'setup' tool on Debian-based distros. – Martijn Heemels Apr 30 '12 at 14:15

Hm... In the linux hosts, if you want change HOSTNAME and FQDN, you should solved 3 steps (for example, new host is rizzo.ifp.com):

Step #1 Change HOST value in the NETWORK properties config:

sudo vi /etc/sysconfig/network

Change or add string:

HOSTNAME=rizzo.ifp.com

Step #2 Edit your hosts config

sudo vim /etc/hosts
#IPv4
127.0.0.1       localhost localhost.localdomain localhost4 localhost4.localdomain4
[External IP]   rizzo rizzo.ifp.com

Step #3 Reboot your host Well done, just check new configuration

[rizzo@rizzo]# hostname -f
rizzo.ifp.com
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.