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