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