The official host name is the 2nd field on an /etc/hosts entry.
I assume that /etc/nsswitch.conf specifies files as the 1st host database.
According to hosts(4) names in /etc/hosts can be a few things.
I'm interested on just two kinds:
- Host
- Domain
The problem is:
Which kind of name to use as the official host name?
- Nowadays I'd say that the only reason to use just the host name as the official host name is if you are not using DNS at all, which may be rather unlike.
- If using DNS, then prefer the domain as the official host name.
Here's the proof:
Considering the official host name as a host name:
#
# Copyright 2009 Sun Microsystems, Inc. ...
# Use is subject to license terms.
#
# Internet host table
#
::1 server localhost
127.0.0.1 server localhost loghost
#
10.0.0.1 server server.domain.com
Here's the output:
server $ ./getipnode_byname server
10.0.0.1 server
server $ ./getipnode_byname server.domain.com
10.0.0.1 server
server $ ./getipnode_byaddr 10.0.0.1
10.0.0.1 server
Considering the official host name as a domain name:
#
# Copyright 2009 Sun Microsystems, Inc. ...
# Use is subject to license terms.
#
# Internet host table
#
::1 server localhost
127.0.0.1 server localhost loghost
#
10.0.0.1 server.domain.com server
Here's the output:
server $ ./getipnode_byname server
10.0.0.1 server
server $ ./getipnode_byname server.domain.com
10.0.0.1 server.domain.com
server $ ./getipnode_byaddr 10.0.0.1
10.0.0.1 server.domain.com