== Linux's _hostname -s_ switch is now safe for many people, but the situation is messy Slightly over a decade ago I wrote an entry about [[our discovery that '_hostname -s_' sometimes did DNS lookups HostnameSwitchWarning]], depending on the exact version involved. We discovered this the hard way, when our DNS lookups failed at one point and suddenly '_hostname -s_' itself started failing unexpectedly. We recently had a reason to use '_hostname -s_' again, which caused me to remember this old issue and check the current situation. The good news is that ~~common versions of _hostname_ now don't do DNS lookups~~. Well, probably, because it turns out that the Linux situation with _hostname_ is much more complicated and tangled than I had any idea before I started looking. It appears that there are no less than four sources for _hostname_, and which version you wind up using can depend on your Linux. On top of that, the source you're probably using is distributed in an unusual way that makes it hard for me to say exactly when its '_hostname -s_' became safe. So let's start with the basics. If you check with '_rpm -qf /usr/bin/hostname_' or '_dpkg -S /usr/bin/hostname_' on appropriate systems (Fedora, CentOS, Debian, and Ubuntu), you will probably find that the version of _hostname_ you're using comes from a 'hostname' package. This package has no upstream as such, and no source repository; [[the canonical source seems to be the Debian package https://packages.qa.debian.org/h/hostname.html]]. Old versions of its source can be found in [[its part of debsources https://sources.debian.org/src/hostname/]]. This version has handled '_hostname -s_' correctly since somewhere between 2.95 (which doesn't) and 3.04 (which does). (Based on the information shown in [[its part of debsources]], hostname 2.95 was part of Debian 5.0 (Lenny), released in 2009, and hostname 3.04 was part of Debian 6.0 (Squeeze), released in 2011.) Arch Linux seems to use a [[_hostname_ https://jlk.fjfi.cvut.cz/arch/manpages/man/hostname.1]] that comes from the [[GNU inetutils https://www.gnu.org/software/inetutils/]] project. The [[relevant code https://git.savannah.gnu.org/cgit/inetutils.git/tree/src/hostname.c]] currently appears to do a DNS lookup if you use '_-s_', but it will proceed if the DNS lookup fails instead of erroring out (the way the decade ago _hostname_ behaved). This does mean that under some conditions your '_hostname -s_' command may stall for some time while its DNS lookup times out, instead of running essentially instantly. The [[Linux manpages project https://www.kernel.org/doc/man-pages/]] has two manpages online for _hostname_ ([[1 https://man7.org/linux/man-pages/man1/hostname.1.html]], [[2 https://man7.org/linux/man-pages/man1/hostname.1@@coreutils.html]]). The default one is from [[net-tools http://net-tools.sourceforge.net/]], and the other one is from [[GNU coreutils https://www.gnu.org/software/coreutils/]]. The GNU Coreutils version has no '_-s_' option (or other commonly supported ones), and as a result I would be surprised if many Linuxes used it. The net-tools version is apparently the original upstream of the plain _hostname_ package version. Based on [[the Fedora 11 bug report about this https://bugzilla.redhat.com/show_bug.cgi?id=531702]], back a decade ago Fedora was using the net-tools version of _hostname_ (I don't know about Debian). The current net-tools version of [[hostname.c https://sourceforge.net/p/net-tools/code/ci/master/tree/hostname.c]] now bypasses DNS lookups when used with '_-s_', a change that was made in 2015. (While Fedora still packages net-tools, their package only has a few of its binaries. And apparently net-tools as a whole may be basically unmaintained; the last commits in the repository seem to be from 2018, and it was 2016 when it was particularly actively developed.)