1NSS-MYHOSTNAME(8)               nss-myhostname               NSS-MYHOSTNAME(8)
2
3
4

NAME

6       nss-myhostname, libnss_myhostname.so.2 - Hostname resolution for the
7       locally configured system hostname
8

SYNOPSIS

10       libnss_myhostname.so.2
11

DESCRIPTION

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 "files" and "dns", or after them. In the
46       first version, well-known names like "localhost" and the machine
47       hostname are given higher priority than the external configuration.
48       This is recommended when the external DNS servers and network are not
49       absolutely trusted. In the second version, external configuration is
50       given higher priority and nss-myhostname only provides a fallback
51       mechanism. This might be suitable in closely controlled networks, for
52       example on a company LAN.
53

EXAMPLE

55       Here is an example /etc/nsswitch.conf file that enables nss-myhostname
56       correctly:
57
58           passwd:         compat systemd
59           group:          compat systemd
60           shadow:         compat
61
62           # Either (untrusted network):
63           hosts:          mymachines resolve [!UNAVAIL=return] myhostname files dns
64           # Or (only trusted networks):
65           hosts:          mymachines resolve [!UNAVAIL=return] files dns myhostname
66           networks:       files
67
68           protocols:      db files
69           services:       db files
70           ethers:         db files
71           rpc:            db files
72
73           netgroup:       nis
74
75       To test, use glibc's getent tool:
76
77           $ getent ahosts `hostname`
78           ::1       STREAM omega
79           ::1       DGRAM
80           ::1       RAW
81           127.0.0.2       STREAM
82           127.0.0.2       DGRAM
83           127.0.0.2       RAW
84
85       In this case, the local hostname is omega.
86

SEE ALSO

88       systemd(1), nss-systemd(8), nss-resolve(8), nss-mymachines(8),
89       nsswitch.conf(5), getent(1)
90
91
92
93systemd 246                                                  NSS-MYHOSTNAME(8)
Impressum