On Ubuntu 10.04, should /etc/hostname contain the server's fully-qualified domain name?
3 Answers
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.

- 9,190
- 28
- 80
- 128
-
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 04 '11 at 00:11
-
Ubuntu 12.04, which shipped with hostname-3.15ubuntu1, changed the `hostname(1)` man page to say: "`/etc/hostname`: Historically this file was supposed to only contain the hostname and not the full canonical FQDN. Nowadays most software is able to cope with a full FQDN here. This file is read at boot time by the system initialization scripts to set the hostname." – 200_success Jul 05 '19 at 07:24
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.

- 3,867
- 2
- 20
- 16
-
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

- 4,437
- 1
- 24
- 31