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       •   The hostname "_outbound" is resolved to the local IPv4 and IPv6
34           addresses that are most likely used for communication with other
35           hosts. This is determined by requesting a routing decision to the
36           configured default gateways from the kernel and then using the
37           local IP addresses selected by this decision. This hostname is only
38           available if there is at least one local default gateway
39           configured. This assigns a stable hostname to the local outbound IP
40           addresses, useful for referencing them independently of the current
41           network configuration state.
42
43       Various software relies on an always-resolvable local hostname. When
44       using dynamic hostnames, this is traditionally achieved by patching
45       /etc/hosts at the same time as changing the hostname. This is
46       problematic since it requires a writable /etc/ file system and is
47       fragile because the file might be edited by the administrator at the
48       same time. With nss-myhostname enabled, changing /etc/hosts is
49       unnecessary, and on many systems, the file becomes entirely optional.
50
51       To activate the NSS modules, add "myhostname" to the line starting with
52       "hosts:" in /etc/nsswitch.conf.
53
54       It is recommended to place "myhostname" after "file" and before "dns".
55       This resolves well-known hostnames like "localhost" and the machine
56       hostnames locally. It is consistent with the behaviour of nss-resolve,
57       and still allows overriding via /etc/hosts.
58
59       Please keep in mind that nss-myhostname (and nss-resolve) also resolve
60       in the other direction — from locally attached IP addresses to
61       hostnames. If you rely on that lookup being provided by DNS, you might
62       want to order things differently.
63

EXAMPLE

65       Here is an example /etc/nsswitch.conf file that enables nss-myhostname
66       correctly:
67
68           passwd:         compat systemd
69           group:          compat [SUCCESS=merge] systemd
70           shadow:         compat systemd
71           gshadow:        files systemd
72
73
74           hosts:          mymachines resolve [!UNAVAIL=return] files myhostname dns
75           networks:       files
76
77           protocols:      db files
78           services:       db files
79           ethers:         db files
80           rpc:            db files
81
82           netgroup:       nis
83
84       To test, use glibc's getent tool:
85
86           $ getent ahosts `hostname`
87           ::1       STREAM omega
88           ::1       DGRAM
89           ::1       RAW
90           127.0.0.2       STREAM
91           127.0.0.2       DGRAM
92           127.0.0.2       RAW
93
94       In this case, the local hostname is omega.
95

SEE ALSO

97       systemd(1), nss-systemd(8), nss-resolve(8), nss-mymachines(8),
98       nsswitch.conf(5), getent(1)
99
100
101
102systemd 250                                                  NSS-MYHOSTNAME(8)
Impressum