Wednesday, June 19, 2013

Official host name and nicknames

This post is related to /etc/hosts and the official host name.
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?
 
  1. 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.
     
  2. If using DNS, then prefer the domain as the official host name.
     
Option 1 is not recommended with DNS (and for relying services and applications) because just the host name (not the domain) is returned by both getipnodebyaddr(3SOCKET) and getipnodebyname(3SOCKET), even if the latter is explicitly queried with a domain 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