1NSS-MYHOSTNAME(8) nss-myhostname NSS-MYHOSTNAME(8)
2
3
4
6 nss-myhostname, libnss_myhostname.so.2 - Hostname resolution for the
7 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" either between "resolve" and
45 "traditional" modules like "dns", or after them. In the first version,
46 well-known names like "localhost" and the machine hostname are given
47 higher priority than the external configuration. This is recommended
48 when the external DNS servers and network are not absolutely trusted.
49 In the second version, external configuration is given higher priority
50 and nss-myhostname only provides a fallback mechanism. This might be
51 suitable in closely controlled networks, for example on a company LAN.
52
54 Here is an example /etc/nsswitch.conf file that enables nss-myhostname
55 correctly:
56
57 passwd: compat systemd
58 group: compat [SUCCESS=merge] systemd
59 shadow: compat
60
61 # Either (untrusted network, see above):
62 hosts: mymachines resolve [!UNAVAIL=return] files myhostname dns
63 # Or (only trusted networks):
64 hosts: mymachines resolve [!UNAVAIL=return] files dns myhostname
65 networks: files
66
67 protocols: db files
68 services: db files
69 ethers: db files
70 rpc: db files
71
72 netgroup: nis
73
74 To test, use glibc's getent tool:
75
76 $ getent ahosts `hostname`
77 ::1 STREAM omega
78 ::1 DGRAM
79 ::1 RAW
80 127.0.0.2 STREAM
81 127.0.0.2 DGRAM
82 127.0.0.2 RAW
83
84 In this case, the local hostname is omega.
85
87 systemd(1), nss-systemd(8), nss-resolve(8), nss-mymachines(8),
88 nsswitch.conf(5), getent(1)
89
90
91
92systemd 248 NSS-MYHOSTNAME(8)