]> git.ipfire.org Git - thirdparty/systemd.git/blame - man/nss-myhostname.xml
travis: add more ASan options
[thirdparty/systemd.git] / man / nss-myhostname.xml
CommitLineData
16eb4da9 1<?xml version='1.0'?> <!--*-nxml-*-->
3a54a157 2<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
12b42c76 3 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
0307f791 4<!-- SPDX-License-Identifier: LGPL-2.1+ -->
16eb4da9 5
08540a95 6<refentry id="nss-myhostname" conditional='ENABLE_NSS_MYHOSTNAME'>
16eb4da9 7
798d3a52
ZJS
8 <refentryinfo>
9 <title>nss-myhostname</title>
10 <productname>systemd</productname>
798d3a52
ZJS
11 </refentryinfo>
12
13 <refmeta>
14 <refentrytitle>nss-myhostname</refentrytitle>
15 <manvolnum>8</manvolnum>
16 </refmeta>
17
18 <refnamediv>
19 <refname>nss-myhostname</refname>
20 <refname>libnss_myhostname.so.2</refname>
21 <refpurpose>Provide hostname resolution for the locally
22 configured system hostname.</refpurpose>
23 </refnamediv>
24
25 <refsynopsisdiv>
26 <para><filename>libnss_myhostname.so.2</filename></para>
27 </refsynopsisdiv>
28
29 <refsect1>
30 <title>Description</title>
31
9053aaad
LP
32 <para><command>nss-myhostname</command> is a plug-in module for the GNU Name Service Switch (NSS) functionality of
33 the GNU C Library (<command>glibc</command>), primarily providing hostname resolution for the locally configured
34 system hostname as returned by
35 <citerefentry><refentrytitle>gethostname</refentrytitle><manvolnum>2</manvolnum></citerefentry>. The precise
36 hostnames resolved by this module are:</para>
798d3a52
ZJS
37
38 <itemizedlist>
39 <listitem><para>The local, configured hostname is resolved to
40 all locally configured IP addresses ordered by their scope, or
41 — if none are configured — the IPv4 address 127.0.0.2 (which
42 is on the local loopback) and the IPv6 address ::1 (which is the
43 local host).</para></listitem>
44
63003524
DH
45 <listitem><para>The hostnames <literal>localhost</literal> and
46 <literal>localhost.localdomain</literal> (as well as any hostname
47 ending in <literal>.localhost</literal> or <literal>.localhost.localdomain</literal>)
48 are resolved to the IP addresses 127.0.0.1 and ::1.</para></listitem>
798d3a52 49
1dc92a06 50 <listitem><para>The hostname <literal>_gateway</literal> is
798d3a52
ZJS
51 resolved to all current default routing gateway addresses,
52 ordered by their metric. This assigns a stable hostname to the
53 current gateway, useful for referencing it independently of the
54 current network configuration state.</para></listitem>
798d3a52
ZJS
55 </itemizedlist>
56
57 <para>Various software relies on an always-resolvable local
58 hostname. When using dynamic hostnames, this is traditionally
59 achieved by patching <filename>/etc/hosts</filename> at the same
60 time as changing the hostname. This is problematic since it
61 requires a writable <filename>/etc</filename> file system and is
62 fragile because the file might be edited by the administrator at
b938cb90 63 the same time. With <command>nss-myhostname</command> enabled,
ff9b60f3 64 changing <filename>/etc/hosts</filename> is unnecessary, and on
b938cb90 65 many systems, the file becomes entirely optional.</para>
798d3a52 66
9053aaad
LP
67 <para>To activate the NSS modules, add <literal>myhostname</literal> to the line starting with
68 <literal>hosts:</literal> in <filename>/etc/nsswitch.conf</filename>.</para>
798d3a52 69
9053aaad
LP
70 <para>It is recommended to place <literal>myhostname</literal> last in the <filename>nsswitch.conf</filename>'
71 <literal>hosts:</literal> line to make sure that this mapping is only used as fallback, and that any DNS or
72 <filename>/etc/hosts</filename> based mapping takes precedence.</para>
798d3a52
ZJS
73 </refsect1>
74
75 <refsect1>
76 <title>Example</title>
77
9053aaad
LP
78 <para>Here is an example <filename>/etc/nsswitch.conf</filename> file that enables
79 <command>nss-myhostname</command> correctly:</para>
798d3a52 80
94f760ec 81 <!-- synchronize with other nss-* man pages and factory/etc/nsswitch.conf -->
409093fe
LP
82<programlisting>passwd: compat mymachines systemd
83group: compat mymachines systemd
0d6868f9 84shadow: compat
798d3a52 85
75555c28 86hosts: files mymachines resolve [!UNAVAIL=return] dns <command>myhostname</command>
16eb4da9
TG
87networks: files
88
89protocols: db files
90services: db files
0d6868f9
LP
91ethers: db files
92rpc: db files
16eb4da9 93
9fccdb0f 94netgroup: nis</programlisting>
16eb4da9 95
798d3a52 96 <para>To test, use <command>glibc</command>'s <command>getent</command> tool:</para>
16eb4da9 97
798d3a52
ZJS
98 <programlisting>$ getent ahosts `hostname`
99::1 STREAM omega
100::1 DGRAM
101::1 RAW
16eb4da9
TG
102127.0.0.2 STREAM
103127.0.0.2 DGRAM
9fccdb0f 104127.0.0.2 RAW</programlisting>
16eb4da9 105
b938cb90 106 <para>In this case, the local hostname is <varname>omega</varname>.</para>
16eb4da9 107
798d3a52 108 </refsect1>
16eb4da9 109
798d3a52
ZJS
110 <refsect1>
111 <title>See Also</title>
112 <para>
113 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
409093fe 114 <citerefentry><refentrytitle>nss-systemd</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
0d6868f9 115 <citerefentry><refentrytitle>nss-resolve</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
798d3a52
ZJS
116 <citerefentry><refentrytitle>nss-mymachines</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
117 <citerefentry project='man-pages'><refentrytitle>nsswitch.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
118 <citerefentry project='man-pages'><refentrytitle>getent</refentrytitle><manvolnum>1</manvolnum></citerefentry>
119 </para>
120 </refsect1>
16eb4da9
TG
121
122</refentry>