2

I know that the first one is said to be canonical, but I don't fully understand the practical implications. This question was triggered by the man page for hostname -f, specifically when it says:

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.

Let's assume that the computer hostname is foo.

With the following configuration:

127.0.0.1       localhost
127.0.1.1       foo.example.com    foo

The command hostname -f returns foo.example.com.

While, with the following configuration:

127.0.0.1       localhost
127.0.1.1       foo    foo.example.com

The command hostname -f returns foo.

Specifically, is the first hostname what man calls 'the official name of the host' when talking about hostent.h_name?

Note: I'm on Debian but hopefully these concepts are of general *nix interest.

Link: A possibly related question.

Link: This question suggests that the second style is wrong, nevertheless I've seen it applied several times around the web.

1
  • It's somewhat unclear to me what is actually left to be answered. You seem to have already noted that the first name is the canonical/official name, how it is used and what effect it has. Apr 16, 2015 at 18:36

1 Answer 1

1

As you suspected, the first entry is the canonical (official) name, where all subsequent names are just aliases to the first. In my experience (in a typical prod environment), /etc/hosts looks like this:

127.0.0.1    localhost.localdomain localhost
10.0.0.1    myhostname.domain.tld myhostname

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .