On Ubuntu 10.04, should /etc/hostname contain the server's FQDN?

11,426

Solution 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.

Solution 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.

Solution 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
Share:
11,426

Related videos on Youtube

RyanTM
Author by

RyanTM

I am a programmer and engineer.

Updated on September 17, 2022

Comments

  • RyanTM
    RyanTM almost 2 years

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

  • Josh
    Josh over 13 years
    "/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
    Josh over 13 years
    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.
  • RyanTM
    RyanTM over 13 years
    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.
  • Icebreaker
    Icebreaker almost 5 years
    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."