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