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">
6 This file is part of systemd.
8 Copyright 2011 Lennart Poettering
9 Copyright 2013 Tom Gundersen
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.
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.
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/>.
25 <refentry id="nss-myhostname" conditional='HAVE_MYHOSTNAME'>
28 <title>nss-myhostname</title>
29 <productname>systemd</productname>
33 <contrib>Developer</contrib>
34 <firstname>Lennart</firstname>
35 <surname>Poettering</surname>
36 <email>lennart@poettering.net</email>
42 <refentrytitle>nss-myhostname</refentrytitle>
43 <manvolnum>8</manvolnum>
47 <refname>nss-myhostname</refname>
48 <refpurpose>Provide hostname resolution for the locally
49 configured system hostname.</refpurpose>
53 <para><filename>nss-myhostname.la</filename></para>
57 <title>Description</title>
59 <para><command>nss-myhostname</command> is a plugin for the GNU Name Service Switch
60 (NSS) functionality of the GNU C Library (<command>glibc</command>)
61 providing hostname resolution for the locally configured system
62 hostname as returned by
63 <citerefentry><refentrytitle>gethostname</refentrytitle><manvolnum>2</manvolnum></citerefentry>.
64 Various software relies on an always-resolvable local hostname. When
65 using dynamic hostnames, this is usually achieved by patching
66 <filename>/etc/hosts</filename> at the same time as changing the host
67 name. This however is not ideal since it requires a writable
68 <filename>/etc</filename> file system and is fragile because the file
69 might be edited by the administrator at the same time. <command>nss-myhostname</command>
70 simply returns all locally configured public IP addresses, or, if none
71 are configured, the IPv4 address 127.0.0.2 (which is on the local
72 loopback) and the IPv6 address ::1 (which is the local host) for
73 whatever system hostname is configured locally. Patching
74 <filename>/etc/hosts</filename> is thus no longer necessary.</para>
76 <para>To activate the NSS modules, <option>myhostname</option>
77 has to be added to the line starting with "<varname>hosts:</varname>" in
78 <filename>/etc/nsswitch.conf</filename></para>
80 <para>It is recommended to put <option>myhostname</option>
81 last in the <filename>nsswitch.conf</filename> line to make
82 sure that this mapping is only used as fallback, and any DNS
83 or <filename>/etc/hosts</filename> based mapping takes precedence.</para>
87 <title>Example</title>
96 hosts: files dns <varname>myhostname</varname>
107 <para>To test, use <command>glibc</command>'s <command>getent</command> tool:</para>
110 $ getent ahosts `hostname`
119 <para>In this case the local hostname is <varname>omega</varname>.</para>
124 <title>See Also</title>
126 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
127 <citerefentry><refentrytitle>systemd-logind.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
128 <citerefentry><refentrytitle>logind.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
129 <citerefentry><refentrytitle>loginctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
130 <citerefentry><refentrytitle>pam.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
131 <citerefentry><refentrytitle>pam.d</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
132 <citerefentry><refentrytitle>pam</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
133 <citerefentry><refentrytitle>pam_loginuid</refentrytitle><manvolnum>8</manvolnum></citerefentry>