1NSS-MYHOSTNAME(8) nss-myhostname NSS-MYHOSTNAME(8)
2
3
4
6 nss-myhostname, libnss_myhostname.so.2 - Provide hostname resolution
7 for the locally configured system hostname.
8
10 libnss_myhostname.so.2
11
13 nss-myhostname is a plug-in module for the GNU Name Service Switch
14 (NSS) functionality of the GNU C Library (glibc), primarily providing
15 hostname resolution for the locally configured system hostname as
16 returned by gethostname(2). The precise hostnames resolved by this
17 module are:
18
19 · The local, configured hostname is resolved to all locally
20 configured IP addresses ordered by their scope, or — if none are
21 configured — the IPv4 address 127.0.0.2 (which is on the local
22 loopback) and the IPv6 address ::1 (which is the local host).
23
24 · The hostnames "localhost" and "localhost.localdomain" (as well as
25 any hostname ending in ".localhost" or ".localhost.localdomain")
26 are resolved to the IP addresses 127.0.0.1 and ::1.
27
28 · The hostname "_gateway" is resolved to all current default routing
29 gateway addresses, ordered by their metric. This assigns a stable
30 hostname to the current gateway, useful for referencing it
31 independently of the current network configuration state.
32
33 Various software relies on an always-resolvable local hostname. When
34 using dynamic hostnames, this is traditionally achieved by patching
35 /etc/hosts at the same time as changing the hostname. This is
36 problematic since it requires a writable /etc file system and is
37 fragile because the file might be edited by the administrator at the
38 same time. With nss-myhostname enabled, changing /etc/hosts is
39 unnecessary, and on many systems, the file becomes entirely optional.
40
41 To activate the NSS modules, add "myhostname" to the line starting with
42 "hosts:" in /etc/nsswitch.conf.
43
44 It is recommended to place "myhostname" last in the nsswitch.conf'
45 "hosts:" line to make sure that this mapping is only used as fallback,
46 and that any DNS or /etc/hosts based mapping takes precedence.
47
49 Here is an example /etc/nsswitch.conf file that enables nss-myhostname
50 correctly:
51
52 passwd: compat mymachines systemd
53 group: compat mymachines systemd
54 shadow: compat
55
56 hosts: files mymachines resolve [!UNAVAIL=return] dns myhostname
57 networks: files
58
59 protocols: db files
60 services: db files
61 ethers: db files
62 rpc: db files
63
64 netgroup: nis
65
66 To test, use glibc's getent tool:
67
68 $ getent ahosts `hostname`
69 ::1 STREAM omega
70 ::1 DGRAM
71 ::1 RAW
72 127.0.0.2 STREAM
73 127.0.0.2 DGRAM
74 127.0.0.2 RAW
75
76 In this case, the local hostname is omega.
77
79 systemd(1), nss-systemd(8), nss-resolve(8), nss-mymachines(8),
80 nsswitch.conf(5), getent(1)
81
82
83
84systemd 245 NSS-MYHOSTNAME(8)