]> git.ipfire.org Git - thirdparty/systemd.git/blame - man/nss-myhostname.xml
journal-remote: remove unnecessary gnutls includes (#3895)
[thirdparty/systemd.git] / man / nss-myhostname.xml
CommitLineData
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<!--
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
56ba3c78 25<refentry id="nss-myhostname" conditional='HAVE_MYHOSTNAME'>
16eb4da9 26
798d3a52
ZJS
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
9053aaad
LP
60 <para><command>nss-myhostname</command> is a plug-in module for the GNU Name Service Switch (NSS) functionality of
61 the GNU C Library (<command>glibc</command>), primarily providing hostname resolution for the locally configured
62 system hostname as returned by
63 <citerefentry><refentrytitle>gethostname</refentrytitle><manvolnum>2</manvolnum></citerefentry>. The precise
64 hostnames resolved by this module are:</para>
798d3a52
ZJS
65
66 <itemizedlist>
67 <listitem><para>The local, configured hostname is resolved to
68 all locally configured IP addresses ordered by their scope, or
69 — if none are configured — the IPv4 address 127.0.0.2 (which
70 is on the local loopback) and the IPv6 address ::1 (which is the
71 local host).</para></listitem>
72
63003524
DH
73 <listitem><para>The hostnames <literal>localhost</literal> and
74 <literal>localhost.localdomain</literal> (as well as any hostname
75 ending in <literal>.localhost</literal> or <literal>.localhost.localdomain</literal>)
76 are resolved to the IP addresses 127.0.0.1 and ::1.</para></listitem>
798d3a52
ZJS
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>
798d3a52
ZJS
83 </itemizedlist>
84
85 <para>Various software relies on an always-resolvable local
86 hostname. When using dynamic hostnames, this is traditionally
87 achieved by patching <filename>/etc/hosts</filename> at the same
88 time as changing the hostname. This is problematic since it
89 requires a writable <filename>/etc</filename> file system and is
90 fragile because the file might be edited by the administrator at
b938cb90 91 the same time. With <command>nss-myhostname</command> enabled,
ff9b60f3 92 changing <filename>/etc/hosts</filename> is unnecessary, and on
b938cb90 93 many systems, the file becomes entirely optional.</para>
798d3a52 94
9053aaad
LP
95 <para>To activate the NSS modules, add <literal>myhostname</literal> to the line starting with
96 <literal>hosts:</literal> in <filename>/etc/nsswitch.conf</filename>.</para>
798d3a52 97
9053aaad
LP
98 <para>It is recommended to place <literal>myhostname</literal> last in the <filename>nsswitch.conf</filename>'
99 <literal>hosts:</literal> line to make sure that this mapping is only used as fallback, and that any DNS or
100 <filename>/etc/hosts</filename> based mapping takes precedence.</para>
798d3a52
ZJS
101 </refsect1>
102
103 <refsect1>
104 <title>Example</title>
105
9053aaad
LP
106 <para>Here is an example <filename>/etc/nsswitch.conf</filename> file that enables
107 <command>nss-myhostname</command> correctly:</para>
798d3a52 108
409093fe
LP
109<programlisting>passwd: compat mymachines systemd
110group: compat mymachines systemd
0d6868f9 111shadow: compat
798d3a52 112
9053aaad 113hosts: files mymachines resolve <command>myhostname</command>
16eb4da9
TG
114networks: files
115
116protocols: db files
117services: db files
0d6868f9
LP
118ethers: db files
119rpc: db files
16eb4da9 120
9fccdb0f 121netgroup: nis</programlisting>
16eb4da9 122
798d3a52 123 <para>To test, use <command>glibc</command>'s <command>getent</command> tool:</para>
16eb4da9 124
798d3a52
ZJS
125 <programlisting>$ getent ahosts `hostname`
126::1 STREAM omega
127::1 DGRAM
128::1 RAW
16eb4da9
TG
129127.0.0.2 STREAM
130127.0.0.2 DGRAM
9fccdb0f 131127.0.0.2 RAW</programlisting>
16eb4da9 132
b938cb90 133 <para>In this case, the local hostname is <varname>omega</varname>.</para>
16eb4da9 134
798d3a52 135 </refsect1>
16eb4da9 136
798d3a52
ZJS
137 <refsect1>
138 <title>See Also</title>
139 <para>
140 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
409093fe 141 <citerefentry><refentrytitle>nss-systemd</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
0d6868f9 142 <citerefentry><refentrytitle>nss-resolve</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
798d3a52
ZJS
143 <citerefentry><refentrytitle>nss-mymachines</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
144 <citerefentry project='man-pages'><refentrytitle>nsswitch.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
145 <citerefentry project='man-pages'><refentrytitle>getent</refentrytitle><manvolnum>1</manvolnum></citerefentry>
146 </para>
147 </refsect1>
16eb4da9
TG
148
149</refentry>