Scenario / Questions

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

Find below all possible solutions or suggestions for the above questions..

Suggestion: 1

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.

Suggestion: 2

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.

Suggestion: 3

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