[openssh-commits] [openssh] 02/02: upstream: hostname is not specified by POSIX but uname -n is, so use

Bob Proulx bob at proulx.com
Mon Feb 8 15:42:09 AEDT 2021

Nico Kadel-Garcia wrote:
> Tim Rice wrote:
> > Bob Proulx wrote:
> > > Getting a FQDN is truly not trivial. :-(
> >
> > True, and some hostname (ubuntu, centos, etc) implimentations have
> > "hostname -f" for the FQDN.

That is a dangerous test that if run as root on say HP-UX definitely
(ask me how I know) will set the hostname to "-f"[1] if it has the
permission to do so instead of querying the hostname.  The traditional
hostname command took no options and when presented with an argument
would set the hostname to that argument.

[1] https://www.freebsd.org/cgi/man.cgi?query=hostname&manpath=HP-UX+11.22

Additionally hostname -f (--fqdn) performs a DNS look up of the IP
address and returns "a" DNS name found.  This is problematic itself in
a number of ways.  One being if the host has multiple IP addresses
which individually have different associated names.  It's a terrible
non-solution IMNHO.

> It's especially aggravated by many configuration tools listing the
> short hostname first, then the full hostname, in /etc/hosts. i.e.:
> short.long.com short localhost.localdomian localhost

I know what you meant to say.  But your example showed the reversed
statement in the normal situation with the long name first and the
short name afterward.  And the above combination is problematic in
ways that are off-topic to the original problem here.

The /etc/hosts format is usually documented like this:

              IP_address canonical_hostname [aliases...]

The first name after the IP address should be the FQDN and is the one
returned when doing a lookup on the IP address.  Short names and
aliases appear afterward in the entry line.

In this case, coupled with, this creates a problem because should map back to localhost.  But adding the long hostname
on that entry causes to map to the long hostname instead of
locahost.  However this discussion would be long and off-topic from
the original issue.


More information about the openssh-unix-dev mailing list