Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

On Ubuntu 10.04, should /etc/hostname contain the server's fully-qualified domain name?

share|improve this question

3 Answers 3

up vote 11 down vote accepted

No, just the hostname portion. According to Ubuntu's man pages, /etc/hostname should contain only the hostname portion of the hostname, not the FQDN:

THE FQDN

You can’t change the FQDN (as returned by hostname --fqdn) or the DNS domain name (as returned by dnsdomainname) with this command. The FQDN of the system is the name that the resolver(3) returns for the host name.

Technically: The FQDN is the name gethostbyname(2) returns for the host name returned by gethostname(2). The DNS domain name is the part after the first dot.

Therefore it depends on the configuration (usually in /etc/host.conf) how you can change it. Usually (if the hosts file is parsed before DNS or NIS) you can change it in /etc/hosts.

NOTES

The address families hostname tries when looking up the FQDN, aliases and network addresses of the host are determined by the configuration of your resolver. For instance, on GNU Libc systems, the resolver can be instructed to try IPv6 lookups first by using the inet6 option in /etc/resolv.conf.

FILES

/etc/hosts /etc/hostname This file should only contain domain name and not the full FQDN.

share|improve this answer
    
I don't think it is as clear from the man page as you make it seem, but I think I will follow the advice on my server. Thanks. –  RyanTM Dec 21 '10 at 17:57
1  
"/etc/hostname This file should only contain domain name and not the full FQDN.", seems clear to me... but I do agree, this can be confusing. –  Josh Dec 21 '10 at 19:26
    
Oh. I think I accidentally did not read that sentence. I thought I was being so careful reading through it multiple times. I would suggest bolding that sentence. –  RyanTM Jan 4 '11 at 0:11

Josh points out what Ubuntu recommends, but I'm not sure it's a hard and fast rule.

/etc/hostname is used to set the system's host name, which is the same thing as printed by hostname or uname -n. That name will be used at login prompts, e.g. on the virtual console or at the Gnome GDM login screen.

As the man page says, it's also used as the input to a DNS query when doing hostname --fqdn or dnsdomainname.

Technically: The FQDN is the name gethostbyname(2) returns for the host name
returned by gethostname(2). The DNS domain name is the part after the first dot.

Which means that if it's a bare word, the resolver will append the domains listed in the search or domain setting in /etc/resolv.conf to try to find the FQDN. If you have an FQDN in /etc/hostname, it means it doesn't have to try appending one or more domains: the name is unambiguous.

So I would say either is valid. I'd be very interested if anyone can demonstrate otherwise.

share|improve this answer
    
You're right, this isn't a hard and fast rule: I switched my answer because some of my servers did have a full hostname in /etc/hostname! Only after I answered and looked for references did I realize that I was going against the official docs. –  Josh Dec 21 '10 at 19:27

With libnss-myhostname installed, you can write the fqdn to /etc/hostname and be done. Otherwise, you need to also edit /etc/hosts to match the short name and map it to the fully qualified name (you can also put it in the dns, but that isn't failsafe). Using a non-default loopback interface, this looks like:

127.0.0.2 hostname.fully.qualified hostname
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.