]>
Commit | Line | Data |
---|---|---|
663996b3 | 1 | <?xml version='1.0'?> <!--*-nxml-*--> |
bb4f798a | 2 | <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" |
e735f4d4 | 3 | "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"> |
a032b68d | 4 | <!-- SPDX-License-Identifier: LGPL-2.1-or-later --> |
663996b3 | 5 | |
6e866b33 | 6 | <refentry id="nss-myhostname" conditional='ENABLE_NSS_MYHOSTNAME'> |
663996b3 | 7 | |
e735f4d4 MP |
8 | <refentryinfo> |
9 | <title>nss-myhostname</title> | |
10 | <productname>systemd</productname> | |
e735f4d4 MP |
11 | </refentryinfo> |
12 | ||
13 | <refmeta> | |
14 | <refentrytitle>nss-myhostname</refentrytitle> | |
15 | <manvolnum>8</manvolnum> | |
16 | </refmeta> | |
17 | ||
18 | <refnamediv> | |
19 | <refname>nss-myhostname</refname> | |
20 | <refname>libnss_myhostname.so.2</refname> | |
a10f5d05 | 21 | <refpurpose>Hostname resolution for the locally configured system hostname</refpurpose> |
e735f4d4 MP |
22 | </refnamediv> |
23 | ||
24 | <refsynopsisdiv> | |
25 | <para><filename>libnss_myhostname.so.2</filename></para> | |
26 | </refsynopsisdiv> | |
27 | ||
28 | <refsect1> | |
29 | <title>Description</title> | |
30 | ||
aa27b158 MP |
31 | <para><command>nss-myhostname</command> is a plug-in module for the GNU Name Service Switch (NSS) functionality of |
32 | the GNU C Library (<command>glibc</command>), primarily providing hostname resolution for the locally configured | |
33 | system hostname as returned by | |
34 | <citerefentry><refentrytitle>gethostname</refentrytitle><manvolnum>2</manvolnum></citerefentry>. The precise | |
35 | hostnames resolved by this module are:</para> | |
e735f4d4 MP |
36 | |
37 | <itemizedlist> | |
38 | <listitem><para>The local, configured hostname is resolved to | |
39 | all locally configured IP addresses ordered by their scope, or | |
40 | — if none are configured — the IPv4 address 127.0.0.2 (which | |
41 | is on the local loopback) and the IPv6 address ::1 (which is the | |
42 | local host).</para></listitem> | |
43 | ||
aa27b158 MP |
44 | <listitem><para>The hostnames <literal>localhost</literal> and |
45 | <literal>localhost.localdomain</literal> (as well as any hostname | |
46 | ending in <literal>.localhost</literal> or <literal>.localhost.localdomain</literal>) | |
47 | are resolved to the IP addresses 127.0.0.1 and ::1.</para></listitem> | |
e735f4d4 | 48 | |
52ad194e | 49 | <listitem><para>The hostname <literal>_gateway</literal> is |
e735f4d4 MP |
50 | resolved to all current default routing gateway addresses, |
51 | ordered by their metric. This assigns a stable hostname to the | |
52 | current gateway, useful for referencing it independently of the | |
53 | current network configuration state.</para></listitem> | |
8b3d4ff0 MB |
54 | |
55 | <listitem><para>The hostname <literal>_outbound</literal> is resolved to the local IPv4 and IPv6 | |
56 | addresses that are most likely used for communication with other hosts. This is determined by | |
57 | requesting a routing decision to the configured default gateways from the kernel and then using the | |
58 | local IP addresses selected by this decision. This hostname is only available if there is at least one | |
59 | local default gateway configured. This assigns a stable hostname to the local outbound IP addresses, | |
60 | useful for referencing them independently of the current network configuration state.</para></listitem> | |
e735f4d4 MP |
61 | </itemizedlist> |
62 | ||
63 | <para>Various software relies on an always-resolvable local | |
64 | hostname. When using dynamic hostnames, this is traditionally | |
65 | achieved by patching <filename>/etc/hosts</filename> at the same | |
66 | time as changing the hostname. This is problematic since it | |
a032b68d | 67 | requires a writable <filename>/etc/</filename> file system and is |
e735f4d4 | 68 | fragile because the file might be edited by the administrator at |
db2df898 | 69 | the same time. With <command>nss-myhostname</command> enabled, |
e3bff60a | 70 | changing <filename>/etc/hosts</filename> is unnecessary, and on |
db2df898 | 71 | many systems, the file becomes entirely optional.</para> |
e735f4d4 | 72 | |
aa27b158 MP |
73 | <para>To activate the NSS modules, add <literal>myhostname</literal> to the line starting with |
74 | <literal>hosts:</literal> in <filename>/etc/nsswitch.conf</filename>.</para> | |
e735f4d4 | 75 | |
a10f5d05 | 76 | <para>It is recommended to place <literal>myhostname</literal> either between <literal>resolve</literal> |
a032b68d MB |
77 | and "traditional" modules like <literal>dns</literal>, or after them. In the first version, well-known |
78 | names like <literal>localhost</literal> and the machine hostname are given higher priority than the | |
79 | external configuration. This is recommended when the external DNS servers and network are not absolutely | |
80 | trusted. In the second version, external configuration is given higher priority and | |
81 | <command>nss-myhostname</command> only provides a fallback mechanism. This might be suitable in closely | |
82 | controlled networks, for example on a company LAN.</para> | |
e735f4d4 MP |
83 | </refsect1> |
84 | ||
85 | <refsect1> | |
86 | <title>Example</title> | |
87 | ||
aa27b158 MP |
88 | <para>Here is an example <filename>/etc/nsswitch.conf</filename> file that enables |
89 | <command>nss-myhostname</command> correctly:</para> | |
e735f4d4 | 90 | |
6e866b33 | 91 | <!-- synchronize with other nss-* man pages and factory/etc/nsswitch.conf --> |
a10f5d05 | 92 | <programlisting>passwd: compat systemd |
a032b68d | 93 | group: compat [SUCCESS=merge] systemd |
8b3d4ff0 MB |
94 | shadow: compat systemd |
95 | gshadow: files systemd | |
96 | ||
e735f4d4 | 97 | |
a032b68d MB |
98 | # Either (untrusted network, see above): |
99 | hosts: mymachines resolve [!UNAVAIL=return] files <command>myhostname</command> dns | |
a10f5d05 MB |
100 | # Or (only trusted networks): |
101 | hosts: mymachines resolve [!UNAVAIL=return] files dns <command>myhostname</command> | |
663996b3 MS |
102 | networks: files |
103 | ||
104 | protocols: db files | |
105 | services: db files | |
13d276d0 MP |
106 | ethers: db files |
107 | rpc: db files | |
663996b3 | 108 | |
60f067b4 | 109 | netgroup: nis</programlisting> |
663996b3 | 110 | |
e735f4d4 | 111 | <para>To test, use <command>glibc</command>'s <command>getent</command> tool:</para> |
663996b3 | 112 | |
e735f4d4 MP |
113 | <programlisting>$ getent ahosts `hostname` |
114 | ::1 STREAM omega | |
115 | ::1 DGRAM | |
116 | ::1 RAW | |
663996b3 MS |
117 | 127.0.0.2 STREAM |
118 | 127.0.0.2 DGRAM | |
60f067b4 | 119 | 127.0.0.2 RAW</programlisting> |
663996b3 | 120 | |
db2df898 | 121 | <para>In this case, the local hostname is <varname>omega</varname>.</para> |
e735f4d4 MP |
122 | |
123 | </refsect1> | |
124 | ||
125 | <refsect1> | |
126 | <title>See Also</title> | |
127 | <para> | |
128 | <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>, | |
8a584da2 | 129 | <citerefentry><refentrytitle>nss-systemd</refentrytitle><manvolnum>8</manvolnum></citerefentry>, |
13d276d0 | 130 | <citerefentry><refentrytitle>nss-resolve</refentrytitle><manvolnum>8</manvolnum></citerefentry>, |
e735f4d4 MP |
131 | <citerefentry><refentrytitle>nss-mymachines</refentrytitle><manvolnum>8</manvolnum></citerefentry>, |
132 | <citerefentry project='man-pages'><refentrytitle>nsswitch.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>, | |
133 | <citerefentry project='man-pages'><refentrytitle>getent</refentrytitle><manvolnum>1</manvolnum></citerefentry> | |
134 | </para> | |
135 | </refsect1> | |
663996b3 MS |
136 | |
137 | </refentry> |