hostname(7) manual page states: If the name consists of a single component, that is, contains no dot, and if the environment variable HOSTALIASES is set to the name of a file, that file is searched for any string matching the input hostname. The file should consist of lines made up of two white-space separated strings, the first of which is the hostname alias, and the second of which is the complete hostname to be substi‐ tuted for that alias. If a case-insensitive match is found between the hostname to be resolved and the first field of a line in the file, the substituted name is looked up with no further processing. This does not work for me: $ cat /tmp/aliases foo localhost $ HOSTALIASES=/tmp/aliases getent hosts foo $ echo $? 2 It seems the file is read, but the content is not honored: $ HOSTALIASES=/tmp/aliases strace -e openat getent hosts foo [...] openat(AT_FDCWD, "/lib64/libnss_files.so.2", O_RDONLY|O_CLOEXEC) = 3 openat(AT_FDCWD, "/etc/hosts", O_RDONLY|O_CLOEXEC) = 3 openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3 openat(AT_FDCWD, "/lib64/libnss_dns.so.2", O_RDONLY|O_CLOEXEC) = 3 openat(AT_FDCWD, "/lib64/libresolv.so.2", O_RDONLY|O_CLOEXEC) = 3 openat(AT_FDCWD, "/tmp/aliases", O_RDONLY|O_CLOEXEC) = 3 openat(AT_FDCWD, "/tmp/aliases", O_RDONLY|O_CLOEXEC) = 3 openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3 openat(AT_FDCWD, "/lib64/libnss_myhostname.so.2", O_RDONLY|O_CLOEXEC) = 3 openat(AT_FDCWD, "/lib64/librt.so.1", O_RDONLY|O_CLOEXEC) = 3 openat(AT_FDCWD, "/lib64/libmount.so.1", O_RDONLY|O_CLOEXEC) = 3 openat(AT_FDCWD, "/lib64/libgcc_s.so.1", O_RDONLY|O_CLOEXEC) = 3 openat(AT_FDCWD, "/lib64/libpthread.so.0", O_RDONLY|O_CLOEXEC) = 3 openat(AT_FDCWD, "/lib64/libblkid.so.1", O_RDONLY|O_CLOEXEC) = 3 openat(AT_FDCWD, "/lib64/libuuid.so.1", O_RDONLY|O_CLOEXEC) = 3 openat(AT_FDCWD, "/lib64/libselinux.so.1", O_RDONLY|O_CLOEXEC) = 3 openat(AT_FDCWD, "/lib64/libpcre2-8.so.0", O_RDONLY|O_CLOEXEC) = 3 openat(AT_FDCWD, "/lib64/libdl.so.2", O_RDONLY|O_CLOEXEC) = 3 openat(AT_FDCWD, "/etc/hosts", O_RDONLY|O_CLOEXEC) = 3 openat(AT_FDCWD, "/tmp/aliases", O_RDONLY|O_CLOEXEC) = 3 openat(AT_FDCWD, "/tmp/aliases", O_RDONLY|O_CLOEXEC) = 3 My /etc/nsswitch.conf is: hosts: files dns myhostname I have glibc-2.28-27.fc29.x86_64.
HOSTALIASES only applies to the DNS resolver. I assume that you have “localhost” defined in /etc/hosts, and not available in DNS. Does this answer your question?
Yes, I have localhost entry in /etc/hosts. So is that a bug in hostname(7) documentation, or is glibc going to support HOSTALIASES processing with hosts "files" resolver?
(In reply to Petr Pisar from comment #2) > Yes, I have localhost entry in /etc/hosts. > > So is that a bug in hostname(7) documentation, or is glibc going to support > HOSTALIASES processing with hosts "files" resolver? The documentation is misleading. The search path processing applies to the “Internet name resolver” (which really means DNS) only, and I really don't think we can change that. I submitted a patch here: https://marc.info/?l=linux-man&m=155601078704361&w=2