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