]>
Commit | Line | Data |
---|---|---|
16eb4da9 TG |
1 | <?xml version='1.0'?> <!--*-nxml-*--> |
2 | <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" | |
12b42c76 | 3 | "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"> |
16eb4da9 TG |
4 | |
5 | <!-- | |
572eb058 ZJS |
6 | SPDX-License-Identifier: LGPL-2.1+ |
7 | ||
16eb4da9 TG |
8 | This file is part of systemd. |
9 | ||
10 | Copyright 2011 Lennart Poettering | |
11 | Copyright 2013 Tom Gundersen | |
12 | ||
13 | systemd is free software; you can redistribute it and/or modify it | |
14 | under the terms of the GNU Lesser General Public License as published by | |
15 | the Free Software Foundation; either version 2.1 of the License, or | |
16 | (at your option) any later version. | |
17 | ||
18 | systemd is distributed in the hope that it will be useful, but | |
19 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
21 | Lesser General Public License for more details. | |
22 | ||
23 | You should have received a copy of the GNU Lesser General Public License | |
24 | along with systemd; If not, see <http://www.gnu.org/licenses/>. | |
25 | --> | |
26 | ||
08cf5b8d | 27 | <refentry id="nss-myhostname" conditional='ENABLE_MYHOSTNAME'> |
16eb4da9 | 28 | |
798d3a52 ZJS |
29 | <refentryinfo> |
30 | <title>nss-myhostname</title> | |
31 | <productname>systemd</productname> | |
32 | ||
33 | <authorgroup> | |
34 | <author> | |
35 | <contrib>Developer</contrib> | |
36 | <firstname>Lennart</firstname> | |
37 | <surname>Poettering</surname> | |
38 | <email>lennart@poettering.net</email> | |
39 | </author> | |
40 | </authorgroup> | |
41 | </refentryinfo> | |
42 | ||
43 | <refmeta> | |
44 | <refentrytitle>nss-myhostname</refentrytitle> | |
45 | <manvolnum>8</manvolnum> | |
46 | </refmeta> | |
47 | ||
48 | <refnamediv> | |
49 | <refname>nss-myhostname</refname> | |
50 | <refname>libnss_myhostname.so.2</refname> | |
51 | <refpurpose>Provide hostname resolution for the locally | |
52 | configured system hostname.</refpurpose> | |
53 | </refnamediv> | |
54 | ||
55 | <refsynopsisdiv> | |
56 | <para><filename>libnss_myhostname.so.2</filename></para> | |
57 | </refsynopsisdiv> | |
58 | ||
59 | <refsect1> | |
60 | <title>Description</title> | |
61 | ||
9053aaad LP |
62 | <para><command>nss-myhostname</command> is a plug-in module for the GNU Name Service Switch (NSS) functionality of |
63 | the GNU C Library (<command>glibc</command>), primarily providing hostname resolution for the locally configured | |
64 | system hostname as returned by | |
65 | <citerefentry><refentrytitle>gethostname</refentrytitle><manvolnum>2</manvolnum></citerefentry>. The precise | |
66 | hostnames resolved by this module are:</para> | |
798d3a52 ZJS |
67 | |
68 | <itemizedlist> | |
69 | <listitem><para>The local, configured hostname is resolved to | |
70 | all locally configured IP addresses ordered by their scope, or | |
71 | — if none are configured — the IPv4 address 127.0.0.2 (which | |
72 | is on the local loopback) and the IPv6 address ::1 (which is the | |
73 | local host).</para></listitem> | |
74 | ||
63003524 DH |
75 | <listitem><para>The hostnames <literal>localhost</literal> and |
76 | <literal>localhost.localdomain</literal> (as well as any hostname | |
77 | ending in <literal>.localhost</literal> or <literal>.localhost.localdomain</literal>) | |
78 | are resolved to the IP addresses 127.0.0.1 and ::1.</para></listitem> | |
798d3a52 | 79 | |
1dc92a06 | 80 | <listitem><para>The hostname <literal>_gateway</literal> is |
798d3a52 ZJS |
81 | resolved to all current default routing gateway addresses, |
82 | ordered by their metric. This assigns a stable hostname to the | |
83 | current gateway, useful for referencing it independently of the | |
84 | current network configuration state.</para></listitem> | |
798d3a52 ZJS |
85 | </itemizedlist> |
86 | ||
87 | <para>Various software relies on an always-resolvable local | |
88 | hostname. When using dynamic hostnames, this is traditionally | |
89 | achieved by patching <filename>/etc/hosts</filename> at the same | |
90 | time as changing the hostname. This is problematic since it | |
91 | requires a writable <filename>/etc</filename> file system and is | |
92 | fragile because the file might be edited by the administrator at | |
b938cb90 | 93 | the same time. With <command>nss-myhostname</command> enabled, |
ff9b60f3 | 94 | changing <filename>/etc/hosts</filename> is unnecessary, and on |
b938cb90 | 95 | many systems, the file becomes entirely optional.</para> |
798d3a52 | 96 | |
9053aaad LP |
97 | <para>To activate the NSS modules, add <literal>myhostname</literal> to the line starting with |
98 | <literal>hosts:</literal> in <filename>/etc/nsswitch.conf</filename>.</para> | |
798d3a52 | 99 | |
9053aaad LP |
100 | <para>It is recommended to place <literal>myhostname</literal> last in the <filename>nsswitch.conf</filename>' |
101 | <literal>hosts:</literal> line to make sure that this mapping is only used as fallback, and that any DNS or | |
102 | <filename>/etc/hosts</filename> based mapping takes precedence.</para> | |
798d3a52 ZJS |
103 | </refsect1> |
104 | ||
105 | <refsect1> | |
106 | <title>Example</title> | |
107 | ||
9053aaad LP |
108 | <para>Here is an example <filename>/etc/nsswitch.conf</filename> file that enables |
109 | <command>nss-myhostname</command> correctly:</para> | |
798d3a52 | 110 | |
409093fe LP |
111 | <programlisting>passwd: compat mymachines systemd |
112 | group: compat mymachines systemd | |
0d6868f9 | 113 | shadow: compat |
798d3a52 | 114 | |
75555c28 | 115 | hosts: files mymachines resolve [!UNAVAIL=return] dns <command>myhostname</command> |
16eb4da9 TG |
116 | networks: files |
117 | ||
118 | protocols: db files | |
119 | services: db files | |
0d6868f9 LP |
120 | ethers: db files |
121 | rpc: db files | |
16eb4da9 | 122 | |
9fccdb0f | 123 | netgroup: nis</programlisting> |
16eb4da9 | 124 | |
798d3a52 | 125 | <para>To test, use <command>glibc</command>'s <command>getent</command> tool:</para> |
16eb4da9 | 126 | |
798d3a52 ZJS |
127 | <programlisting>$ getent ahosts `hostname` |
128 | ::1 STREAM omega | |
129 | ::1 DGRAM | |
130 | ::1 RAW | |
16eb4da9 TG |
131 | 127.0.0.2 STREAM |
132 | 127.0.0.2 DGRAM | |
9fccdb0f | 133 | 127.0.0.2 RAW</programlisting> |
16eb4da9 | 134 | |
b938cb90 | 135 | <para>In this case, the local hostname is <varname>omega</varname>.</para> |
16eb4da9 | 136 | |
798d3a52 | 137 | </refsect1> |
16eb4da9 | 138 | |
798d3a52 ZJS |
139 | <refsect1> |
140 | <title>See Also</title> | |
141 | <para> | |
142 | <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>, | |
409093fe | 143 | <citerefentry><refentrytitle>nss-systemd</refentrytitle><manvolnum>8</manvolnum></citerefentry>, |
0d6868f9 | 144 | <citerefentry><refentrytitle>nss-resolve</refentrytitle><manvolnum>8</manvolnum></citerefentry>, |
798d3a52 ZJS |
145 | <citerefentry><refentrytitle>nss-mymachines</refentrytitle><manvolnum>8</manvolnum></citerefentry>, |
146 | <citerefentry project='man-pages'><refentrytitle>nsswitch.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>, | |
147 | <citerefentry project='man-pages'><refentrytitle>getent</refentrytitle><manvolnum>1</manvolnum></citerefentry> | |
148 | </para> | |
149 | </refsect1> | |
16eb4da9 TG |
150 | |
151 | </refentry> |