]>
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 | |
16eb4da9 TG |
12 | --> |
13 | ||
08cf5b8d | 14 | <refentry id="nss-myhostname" conditional='ENABLE_MYHOSTNAME'> |
16eb4da9 | 15 | |
798d3a52 ZJS |
16 | <refentryinfo> |
17 | <title>nss-myhostname</title> | |
18 | <productname>systemd</productname> | |
19 | ||
20 | <authorgroup> | |
21 | <author> | |
22 | <contrib>Developer</contrib> | |
23 | <firstname>Lennart</firstname> | |
24 | <surname>Poettering</surname> | |
25 | <email>lennart@poettering.net</email> | |
26 | </author> | |
27 | </authorgroup> | |
28 | </refentryinfo> | |
29 | ||
30 | <refmeta> | |
31 | <refentrytitle>nss-myhostname</refentrytitle> | |
32 | <manvolnum>8</manvolnum> | |
33 | </refmeta> | |
34 | ||
35 | <refnamediv> | |
36 | <refname>nss-myhostname</refname> | |
37 | <refname>libnss_myhostname.so.2</refname> | |
38 | <refpurpose>Provide hostname resolution for the locally | |
39 | configured system hostname.</refpurpose> | |
40 | </refnamediv> | |
41 | ||
42 | <refsynopsisdiv> | |
43 | <para><filename>libnss_myhostname.so.2</filename></para> | |
44 | </refsynopsisdiv> | |
45 | ||
46 | <refsect1> | |
47 | <title>Description</title> | |
48 | ||
9053aaad LP |
49 | <para><command>nss-myhostname</command> is a plug-in module for the GNU Name Service Switch (NSS) functionality of |
50 | the GNU C Library (<command>glibc</command>), primarily providing hostname resolution for the locally configured | |
51 | system hostname as returned by | |
52 | <citerefentry><refentrytitle>gethostname</refentrytitle><manvolnum>2</manvolnum></citerefentry>. The precise | |
53 | hostnames resolved by this module are:</para> | |
798d3a52 ZJS |
54 | |
55 | <itemizedlist> | |
56 | <listitem><para>The local, configured hostname is resolved to | |
57 | all locally configured IP addresses ordered by their scope, or | |
58 | — if none are configured — the IPv4 address 127.0.0.2 (which | |
59 | is on the local loopback) and the IPv6 address ::1 (which is the | |
60 | local host).</para></listitem> | |
61 | ||
63003524 DH |
62 | <listitem><para>The hostnames <literal>localhost</literal> and |
63 | <literal>localhost.localdomain</literal> (as well as any hostname | |
64 | ending in <literal>.localhost</literal> or <literal>.localhost.localdomain</literal>) | |
65 | are resolved to the IP addresses 127.0.0.1 and ::1.</para></listitem> | |
798d3a52 | 66 | |
1dc92a06 | 67 | <listitem><para>The hostname <literal>_gateway</literal> is |
798d3a52 ZJS |
68 | resolved to all current default routing gateway addresses, |
69 | ordered by their metric. This assigns a stable hostname to the | |
70 | current gateway, useful for referencing it independently of the | |
71 | current network configuration state.</para></listitem> | |
798d3a52 ZJS |
72 | </itemizedlist> |
73 | ||
74 | <para>Various software relies on an always-resolvable local | |
75 | hostname. When using dynamic hostnames, this is traditionally | |
76 | achieved by patching <filename>/etc/hosts</filename> at the same | |
77 | time as changing the hostname. This is problematic since it | |
78 | requires a writable <filename>/etc</filename> file system and is | |
79 | fragile because the file might be edited by the administrator at | |
b938cb90 | 80 | the same time. With <command>nss-myhostname</command> enabled, |
ff9b60f3 | 81 | changing <filename>/etc/hosts</filename> is unnecessary, and on |
b938cb90 | 82 | many systems, the file becomes entirely optional.</para> |
798d3a52 | 83 | |
9053aaad LP |
84 | <para>To activate the NSS modules, add <literal>myhostname</literal> to the line starting with |
85 | <literal>hosts:</literal> in <filename>/etc/nsswitch.conf</filename>.</para> | |
798d3a52 | 86 | |
9053aaad LP |
87 | <para>It is recommended to place <literal>myhostname</literal> last in the <filename>nsswitch.conf</filename>' |
88 | <literal>hosts:</literal> line to make sure that this mapping is only used as fallback, and that any DNS or | |
89 | <filename>/etc/hosts</filename> based mapping takes precedence.</para> | |
798d3a52 ZJS |
90 | </refsect1> |
91 | ||
92 | <refsect1> | |
93 | <title>Example</title> | |
94 | ||
9053aaad LP |
95 | <para>Here is an example <filename>/etc/nsswitch.conf</filename> file that enables |
96 | <command>nss-myhostname</command> correctly:</para> | |
798d3a52 | 97 | |
409093fe LP |
98 | <programlisting>passwd: compat mymachines systemd |
99 | group: compat mymachines systemd | |
0d6868f9 | 100 | shadow: compat |
798d3a52 | 101 | |
75555c28 | 102 | hosts: files mymachines resolve [!UNAVAIL=return] dns <command>myhostname</command> |
16eb4da9 TG |
103 | networks: files |
104 | ||
105 | protocols: db files | |
106 | services: db files | |
0d6868f9 LP |
107 | ethers: db files |
108 | rpc: db files | |
16eb4da9 | 109 | |
9fccdb0f | 110 | netgroup: nis</programlisting> |
16eb4da9 | 111 | |
798d3a52 | 112 | <para>To test, use <command>glibc</command>'s <command>getent</command> tool:</para> |
16eb4da9 | 113 | |
798d3a52 ZJS |
114 | <programlisting>$ getent ahosts `hostname` |
115 | ::1 STREAM omega | |
116 | ::1 DGRAM | |
117 | ::1 RAW | |
16eb4da9 TG |
118 | 127.0.0.2 STREAM |
119 | 127.0.0.2 DGRAM | |
9fccdb0f | 120 | 127.0.0.2 RAW</programlisting> |
16eb4da9 | 121 | |
b938cb90 | 122 | <para>In this case, the local hostname is <varname>omega</varname>.</para> |
16eb4da9 | 123 | |
798d3a52 | 124 | </refsect1> |
16eb4da9 | 125 | |
798d3a52 ZJS |
126 | <refsect1> |
127 | <title>See Also</title> | |
128 | <para> | |
129 | <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>, | |
409093fe | 130 | <citerefentry><refentrytitle>nss-systemd</refentrytitle><manvolnum>8</manvolnum></citerefentry>, |
0d6868f9 | 131 | <citerefentry><refentrytitle>nss-resolve</refentrytitle><manvolnum>8</manvolnum></citerefentry>, |
798d3a52 ZJS |
132 | <citerefentry><refentrytitle>nss-mymachines</refentrytitle><manvolnum>8</manvolnum></citerefentry>, |
133 | <citerefentry project='man-pages'><refentrytitle>nsswitch.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>, | |
134 | <citerefentry project='man-pages'><refentrytitle>getent</refentrytitle><manvolnum>1</manvolnum></citerefentry> | |
135 | </para> | |
136 | </refsect1> | |
16eb4da9 TG |
137 | |
138 | </refentry> |