NSS-MYHOSTNAME(8)
๐ NSS-MYHOSTNAME(8) โ like, the whole manual, bestie
okay so real quick, this page is from the nss-myhostname section 8 manual, and it's all about nss-myhostname and libnss_myhostname.so.2. yes girl, that long library name is the whole vibe. let's get into it ๐ซถ
โจ NAME โจ
nss-myhostname, libnss_myhostname.so.2 โ hostname resolution for the locally configured system hostname โจ (yes, that's the whole point, and it slays)
๐ SYNOPSIS ๐
libnss_myhostname.so.2
that's it. that's the synopsis. she's lowkey minimal and I respect it ๐
๐ฆ DESCRIPTION ๐ฆ
so nss-myhostname is a plug-in module for the GNU Name Service Switch (NSS) functionality of the GNU C Library (glibc) โ ngl that's a whole mouthful, but what she actually does is provide hostname resolution for the locally configured system hostname as returned by gethostname(2). main character behavior fr fr ๐
the precise hostnames this module resolves are, and I'm quoting the receipts:
- the local, configured hostname gets resolved to all locally configured IP addresses, ordered by their scope โ or, if literally none are configured, then the IPv4 address
127.0.0.2(which is on the local loopback, cute) and the IPv6 address::1(which is the local host, iconic) - the hostnames
"localhost"and"localhost.localdomain"โ plus any hostname ending in".localhost"or".localhost.localdomain"โ get resolved to the IP addresses127.0.0.1and::1๐ - the hostname
"_gateway"gets resolved to all current default routing gateway addresses, ordered by their metric. so it assigns a stable hostname to the current gateway, which is useful for referencing it independently of the current network configuration state. obsessed with the stability tbh โจ - the hostname
"_outbound"gets resolved to the local IPv4 and IPv6 addresses that are most likely used for communication with other hosts. this is the preferred source addresses of default gateways if specified, or determined by requesting a routing decision to the configured default gateways from the kernel and then using the local IP addresses selected by this decision. heads up though: this hostname is only available if there is at least one local default gateway configured! and yeah, this assigns a stable hostname to the local outbound IP addresses, useful for referencing them independently of the current network configuration state ๐ฆ
okay so side quest, and this part is actually tea โ โ various software relies on an always-resolvable local hostname. when using dynamic hostnames, this is traditionally achieved by patching /etc/hosts at the same time as changing the hostname. and that'sโฆ problematic, bestie ๐ญ it requires a writable /etc/ file system, and it's fragile because the file might get edited by the administrator at the same time. messy. with nss-myhostname enabled though, changing /etc/hosts is unnecessary, and on many systems the file becomes entirely optional. she ate and left no crumbs ๐
to activate the NSS modules, add "myhostname" to the line starting with "hosts:" in /etc/nsswitch.conf.
it is recommended to place "myhostname" after "files" and before "dns". this resolves well-known hostnames like "localhost" and the machine hostnames locally. it's consistent with the behaviour of nss-resolve, and still allows overriding via /etc/hosts. ๐ธ
โ ๏ธ please keep in mind thatnss-myhostname(andnss-resolve) also resolve in the other direction โ from locally attached IP addresses to hostnames. so if you rely on that lookup being provided by DNS, you might want to order things differently. no cap, this one matters ๐
๐ EXAMPLE ๐
here's an example /etc/nsswitch.conf file that enables nss-myhostname correctly โ copy the vibe, not my typos:
passwd: files systemd
group: files [SUCCESS=merge] systemd
shadow: files systemd
gshadow: files systemd
hosts: mymachines resolve [!UNAVAIL=return] files myhostname dns
networks: files
protocols: db files
services: db files
ethers: db files
rpc: db files
netgroup: nis
to test, use glibc's getent(1) tool, it's giving effortless:
$ getent ahosts `hostname`
::1 STREAM omega
::1 DGRAM
::1 RAW
127.0.0.2 STREAM
127.0.0.2 DGRAM
127.0.0.2 RAW
in this case, the local hostname is omega. cute name, honestly ๐
๐ SEE ALSO ๐
systemd(1), nss-systemd(8), nss-resolve(8), nss-mymachines(8), nsswitch.conf(5), getent(1)
okay that's the whole page, you understood it perfectly, I'm so proud ๐ฅน๐ this was brought to you by systemd 259.10 โ mwah, go resolve something, bestie! โญ
๐ฆ where this page comes from
- fedora 44: systemd 259.10-1.fc44 ยท LGPL-2.1-or-later AND MIT AND GPL-2.0-or-later
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms