| 1 |
'\" t |
| 2 |
.TH "NSS\-MYHOSTNAME" "8" "" "systemd 261~rc3" "nss-myhostname" |
| 3 |
.\" ----------------------------------------------------------------- |
| 4 |
.\" * Define some portability stuff |
| 5 |
.\" ----------------------------------------------------------------- |
| 6 |
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 7 |
.\" http://bugs.debian.org/507673 |
| 8 |
.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html |
| 9 |
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 10 |
.ie \n(.g .ds Aq \(aq |
| 11 |
.el .ds Aq ' |
| 12 |
.\" ----------------------------------------------------------------- |
| 13 |
.\" * set default formatting |
| 14 |
.\" ----------------------------------------------------------------- |
| 15 |
.\" disable hyphenation |
| 16 |
.nh |
| 17 |
.\" disable justification (adjust text to left margin only) |
| 18 |
.ad l |
| 19 |
.\" ----------------------------------------------------------------- |
| 20 |
.\" * MAIN CONTENT STARTS HERE * |
| 21 |
.\" ----------------------------------------------------------------- |
| 22 |
.SH "NAME" |
| 23 |
nss-myhostname, libnss_myhostname.so.2 \- Hostname resolution for the locally configured system hostname |
| 24 |
.SH "SYNOPSIS" |
| 25 |
.PP |
| 26 |
libnss_myhostname\&.so\&.2 |
| 27 |
.SH "DESCRIPTION" |
| 28 |
.PP |
| 29 |
\fBnss\-myhostname\fR |
| 30 |
is a plug\-in module for the GNU Name Service Switch (NSS) functionality of the GNU C Library (\fBglibc\fR), primarily providing hostname resolution for the locally configured system hostname as returned by |
| 31 |
\fBgethostname\fR(2)\&. The precise hostnames resolved by this module are: |
| 32 |
.sp |
| 33 |
.RS 4 |
| 34 |
.ie n \{\ |
| 35 |
\h'-04'\(bu\h'+03'\c |
| 36 |
.\} |
| 37 |
.el \{\ |
| 38 |
.sp -1 |
| 39 |
.IP \(bu 2.3 |
| 40 |
.\} |
| 41 |
The local, configured hostname is resolved to all locally configured IP addresses ordered by their scope, or \(em if none are configured \(em the IPv4 address 127\&.0\&.0\&.2 (which is on the local loopback) and the IPv6 address ::1 (which is the local host)\&. |
| 42 |
.RE |
| 43 |
.sp |
| 44 |
.RS 4 |
| 45 |
.ie n \{\ |
| 46 |
\h'-04'\(bu\h'+03'\c |
| 47 |
.\} |
| 48 |
.el \{\ |
| 49 |
.sp -1 |
| 50 |
.IP \(bu 2.3 |
| 51 |
.\} |
| 52 |
The hostnames |
| 53 |
"localhost" |
| 54 |
and |
| 55 |
"localhost\&.localdomain" |
| 56 |
(as well as any hostname ending in |
| 57 |
"\&.localhost" |
| 58 |
or |
| 59 |
"\&.localhost\&.localdomain") are resolved to the IP addresses 127\&.0\&.0\&.1 and ::1\&. |
| 60 |
.RE |
| 61 |
.sp |
| 62 |
.RS 4 |
| 63 |
.ie n \{\ |
| 64 |
\h'-04'\(bu\h'+03'\c |
| 65 |
.\} |
| 66 |
.el \{\ |
| 67 |
.sp -1 |
| 68 |
.IP \(bu 2.3 |
| 69 |
.\} |
| 70 |
The hostname |
| 71 |
"_gateway" |
| 72 |
is resolved to all current default routing gateway addresses, ordered by their metric\&. This assigns a stable hostname to the current gateway, useful for referencing it independently of the current network configuration state\&. |
| 73 |
.RE |
| 74 |
.sp |
| 75 |
.RS 4 |
| 76 |
.ie n \{\ |
| 77 |
\h'-04'\(bu\h'+03'\c |
| 78 |
.\} |
| 79 |
.el \{\ |
| 80 |
.sp -1 |
| 81 |
.IP \(bu 2.3 |
| 82 |
.\} |
| 83 |
The hostname |
| 84 |
"_outbound" |
| 85 |
is resolved to the local IPv4 and IPv6 addresses that are most likely used for communication with other hosts\&. This is the preferred source addresses of default gateways if specified, or determined by requesting a routing decision to the configured default gateways from the kernel and then using the local IP addresses selected by this decision\&. This hostname is only available if there is at least one local default gateway configured\&. This assigns a stable hostname to the local outbound IP addresses, useful for referencing them independently of the current network configuration state\&. |
| 86 |
.RE |
| 87 |
.PP |
| 88 |
Various software relies on an always\-resolvable local hostname\&. When using dynamic hostnames, this is traditionally achieved by patching |
| 89 |
/etc/hosts |
| 90 |
at the same time as changing the hostname\&. This is problematic since it requires a writable |
| 91 |
/etc/ |
| 92 |
file system and is fragile because the file might be edited by the administrator at the same time\&. With |
| 93 |
\fBnss\-myhostname\fR |
| 94 |
enabled, changing |
| 95 |
/etc/hosts |
| 96 |
is unnecessary, and on many systems, the file becomes entirely optional\&. |
| 97 |
.PP |
| 98 |
To activate the NSS modules, add |
| 99 |
"myhostname" |
| 100 |
to the line starting with |
| 101 |
"hosts:" |
| 102 |
in |
| 103 |
/etc/nsswitch\&.conf\&. |
| 104 |
.PP |
| 105 |
It is recommended to place |
| 106 |
"myhostname" |
| 107 |
after |
| 108 |
"files" |
| 109 |
and before |
| 110 |
"dns"\&. This resolves well\-known hostnames like |
| 111 |
"localhost" |
| 112 |
and the machine hostnames locally\&. It is consistent with the behaviour of |
| 113 |
\fBnss\-resolve\fR, and still allows overriding via |
| 114 |
/etc/hosts\&. |
| 115 |
.PP |
| 116 |
Please keep in mind that |
| 117 |
\fBnss\-myhostname\fR |
| 118 |
(and |
| 119 |
\fBnss\-resolve\fR) also resolve in the other direction \(em from locally attached IP addresses to hostnames\&. If you rely on that lookup being provided by DNS, you might want to order things differently\&. |
| 120 |
.SH "EXAMPLE" |
| 121 |
.PP |
| 122 |
Here is an example |
| 123 |
/etc/nsswitch\&.conf |
| 124 |
file that enables |
| 125 |
\fBnss\-myhostname\fR |
| 126 |
correctly: |
| 127 |
.sp |
| 128 |
.if n \{\ |
| 129 |
.RS 4 |
| 130 |
.\} |
| 131 |
.nf |
| 132 |
passwd: files systemd |
| 133 |
group: files [SUCCESS=merge] systemd |
| 134 |
shadow: files systemd |
| 135 |
gshadow: files systemd |
| 136 |
|
| 137 |
hosts: mymachines resolve [!UNAVAIL=return] files \fBmyhostname\fR dns |
| 138 |
networks: files |
| 139 |
|
| 140 |
protocols: db files |
| 141 |
services: db files |
| 142 |
ethers: db files |
| 143 |
rpc: db files |
| 144 |
|
| 145 |
netgroup: nis |
| 146 |
.fi |
| 147 |
.if n \{\ |
| 148 |
.RE |
| 149 |
.\} |
| 150 |
.PP |
| 151 |
To test, use |
| 152 |
\fBglibc\fR\*(Aqs |
| 153 |
\fBgetent\fR(1) |
| 154 |
tool: |
| 155 |
.sp |
| 156 |
.if n \{\ |
| 157 |
.RS 4 |
| 158 |
.\} |
| 159 |
.nf |
| 160 |
$ getent ahosts `hostname` |
| 161 |
::1 STREAM omega |
| 162 |
::1 DGRAM |
| 163 |
::1 RAW |
| 164 |
127\&.0\&.0\&.2 STREAM |
| 165 |
127\&.0\&.0\&.2 DGRAM |
| 166 |
127\&.0\&.0\&.2 RAW |
| 167 |
.fi |
| 168 |
.if n \{\ |
| 169 |
.RE |
| 170 |
.\} |
| 171 |
.PP |
| 172 |
In this case, the local hostname is |
| 173 |
\fIomega\fR\&. |
| 174 |
.SH "SEE ALSO" |
| 175 |
.PP |
| 176 |
\fBsystemd\fR(1), \fBnss-systemd\fR(8), \fBnss-resolve\fR(8), \fBnss-mymachines\fR(8), \fBnsswitch.conf\fR(5), \fBgetent\fR(1) |