man/hostnamectl,hostaned,hostname1: adjust the docs to match reality

The semantics were significantly changed in c779a44222
("hostnamed: Fix the way that static and transient host names interact", Feb. 2014),
but when the dbus api documentation was imported much later, it wasn't properly
adjusted to describe those new semantics.

34293dfafd which added systemd.hostname= also
added new behaviour.

Let's ove various bits and pieces around so that they are in more appropriate
places. Drop recommendations to set the hostname for DHCP or mDNS purposes.
Nowadays we expect tools that want to expose some different hostname to the
outside to manage that internally without affecting visible state. Also drop
mentions of DHCP or mDNS directly setting the hostname, since nowadays network
management software is expected to (and does) go through hostnamed.

Also, add a high-level description of semantics. It glosses over the details of
handling of localhost-style names. Later commits will remove this special handling
anyway.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2020-12-04 15:16:24 +01:00
parent a2be8be2cf
commit de31bbc6b1
4 changed files with 122 additions and 85 deletions

View File

@ -1,6 +1,9 @@
<?xml version='1.0'?> <!--*-nxml-*-->
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd" [
<!ENTITY % entities SYSTEM "custom-entities.ent" >
%entities;
]>
<!-- SPDX-License-Identifier: LGPL-2.1-or-later -->
<refentry id="hostname">
@ -26,23 +29,65 @@
<refsect1>
<title>Description</title>
<para>The <filename>/etc/hostname</filename> file configures the
name of the local system that is set during boot using the
<citerefentry><refentrytitle>sethostname</refentrytitle><manvolnum>2</manvolnum></citerefentry>
system call. It should contain a single newline-terminated
hostname string. Comments (lines starting with a `#') are ignored.
The hostname may be a free-form string up to 64 characters in length;
however, it is recommended that it consists only of 7-bit ASCII lower-case
characters and no spaces or dots, and limits itself to the format allowed
for DNS domain name labels, even though this is not a strict
requirement.</para>
<para>The <filename>/etc/hostname</filename> file configures the name of the local system. Unless
overridden as described in the next section,
<citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry> will set this
hostname during boot using the
<citerefentry><refentrytitle>sethostname</refentrytitle><manvolnum>2</manvolnum></citerefentry> system
call.</para>
<para>The file should contain a single newline-terminated hostname string. Comments (lines starting with
a <literal>#</literal>) are ignored. The hostname should be composed of up to 64 7-bit ASCII lower-case
alphanumeric characters or hyphens forming a valid DNS domain name. It is recommended that this name
contains only a single label, i.e. without any dots. Invalid characters will be filtered out in an
attempt to make the name valid, but obviously it is recommended to use a valid name and not rely on this
filtering.</para>
<para>You may use
<citerefentry><refentrytitle>hostnamectl</refentrytitle><manvolnum>1</manvolnum></citerefentry>
to change the value of this file during runtime from the command
line. Use
<citerefentry><refentrytitle>systemd-firstboot</refentrytitle><manvolnum>1</manvolnum></citerefentry>
to initialize it on mounted (but not booted) system images.</para>
<citerefentry><refentrytitle>hostnamectl</refentrytitle><manvolnum>1</manvolnum></citerefentry> to change
the value of this file during runtime from the command line. Use
<citerefentry><refentrytitle>systemd-firstboot</refentrytitle><manvolnum>1</manvolnum></citerefentry> to
initialize it on mounted (but not booted) system images.</para>
</refsect1>
<refsect1>
<title>Hostname semantics</title>
<para><citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry> and the
associated tools will obtain the hostname in the following ways:</para>
<itemizedlist>
<listitem><para>If the kernel commandline parameter <varname>systemd.hostname=</varname> specifies a
valid hostname,
<citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry> will use it
to set the hostname during early boot, see
<citerefentry><refentrytitle>kernel-command-line</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
</para></listitem>
<listitem><para>Otherwise, the "static" hostname specified by <filename>/etc/hostname</filename> as
described above will be used.</para></listitem>
<listitem><para>Otherwise, a transient hostname may be set during runtime, for example based on
information in a DHCP lease, see
<citerefentry><refentrytitle>systemd-hostnamed.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>.
Both <ulink url="https://developer.gnome.org/NetworkManager/stable/">NetworkManager</ulink> and
<citerefentry><refentrytitle>systemd-networkd.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>
allow this. Note that
<citerefentry><refentrytitle>systemd-hostnamed.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>
gives higher priority to the static hostname, so the transient hostname will only be used if the static
hostname is not configured.</para></listitem>
<listitem><para>Otherwise, a fallback hostname configured at compilation time will be used
(<literal>&FALLBACK_HOSTNAME;</literal>).</para></listitem>
<!-- what about the "linux" fallback fallback? -->
</itemizedlist>
<para>Effectively, the static hostname has higher priority than a transient hostname, which has higher
priority than the fallback hostname. Transient hostnames are equivalent, so setting a new transient
hostname causes the previous transient hostname to be forgotten. The hostname specified on the kernel
command line is like a transient hostname, with the exception that it has higher priority when the
machine boots. Also note that those are the semantics implemented by systemd tools, but other programs
may also set the hostname.</para>
</refsect1>
<refsect1>

View File

@ -32,33 +32,23 @@
<refsect1>
<title>Description</title>
<para><command>hostnamectl</command> may be used to query and
change the system hostname and related settings.</para>
<para><command>hostnamectl</command> may be used to query and change the system hostname and related
settings.</para>
<para>This tool distinguishes three different hostnames: the
high-level "pretty" hostname which might include all kinds of
special characters (e.g. "Lennart's Laptop"), the static hostname
which is used to initialize the kernel hostname at boot (e.g.
"lennarts-laptop"), and the transient hostname which is a fallback
value received from network configuration. If a static hostname is
set, and is valid (something other than localhost), then the
transient hostname is not used.</para>
<para><citerefentry><refentrytitle>systemd-hostnamed.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>
and this tool distinguish three different hostnames: the high-level "pretty" hostname which might include
all kinds of special characters (e.g. "Lennart's Laptop"), the "static" hostname which is the
user-configured hostname (e.g. "lennarts-laptop"), and the transient hostname which is a fallback value
received from network configuration (e.g. "node12345678"). If a static hostname is set, and is valid
(something other than localhost), then the transient hostname is not used.</para>
<para>Note that the pretty hostname has little restrictions on the characters and length used, while the static and
transient hostnames are limited to the usually accepted characters of Internet domain names, and 64 characters at
maximum (the latter being a Linux limitation).</para>
<para>The static hostname is stored in
<filename>/etc/hostname</filename>, see
<citerefentry><refentrytitle>hostname</refentrytitle><manvolnum>5</manvolnum></citerefentry>
for more information. The pretty hostname, chassis type, and icon
name are stored in <filename>/etc/machine-info</filename>, see
<citerefentry><refentrytitle>machine-info</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</para>
<para>Use
<citerefentry><refentrytitle>systemd-firstboot</refentrytitle><manvolnum>1</manvolnum></citerefentry>
to initialize the system hostname for mounted (but not booted)
system images.</para>
<citerefentry><refentrytitle>systemd-firstboot</refentrytitle><manvolnum>1</manvolnum></citerefentry> to
initialize the system hostname for mounted (but not booted) system images.</para>
</refsect1>
<refsect1>

View File

@ -144,55 +144,53 @@ node /org/freedesktop/hostname1 {
<refsect1>
<title>Semantics</title>
<para>The <emphasis>static (configured) hostname</emphasis> is the one configured in
<filename>/etc/hostname</filename>. It is chosen by the local user. It is not always in sync with the
current hostname as returned by the
<para>The <varname>StaticHostname</varname> property exposes the "static" hostname configured in
<filename>/etc/hostname</filename>. It is not always in sync with the current hostname as returned by the
<citerefentry project="man-pages"><refentrytitle>gethostname</refentrytitle><manvolnum>3</manvolnum></citerefentry>
system call. If no hostname is configured this property will be the empty string. Setting this property
to the empty string will remove <filename>/etc/hostname</filename>. This property should be an
internet-style hostname, 7-bit lowercase ASCII, no special chars/spaces.</para>
system call. If no static hostname is configured this property will be the empty string.</para>
<para>The <emphasis>transient (dynamic) hostname</emphasis> is the one configured via the kernel's
<para>When <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry> or
<citerefentry><refentrytitle>systemd-hostnamed.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>
set the hostname, this static hostname <emphasis>has the highest priority</emphasis>.</para>
<para>The <varname>Hostname</varname> property exposes the actual hostname configured in the kernel via
<citerefentry project="man-pages"><refentrytitle>sethostname</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
It can be different from the static hostname if DHCP or mDNS have been configured to change the name
based on network information. <!-- FIXME: it's not DHCP that configures this... -->
This property is never empty. If no hostname is set this will default to
<literal>&FALLBACK_HOSTNAME;</literal> (configurable at compilation time). Setting this property to the
empty string will reset the dynamic hostname to the static hostname. If no static hostname is
configured the dynamic hostname will be reset to <literal>&FALLBACK_HOSTNAME;</literal>. This property
should be an internet-style hostname, 7-bit lowercase ASCII, no special chars/spaces.</para>
It can be different from the static hostname. This property is never empty.</para>
<para>The <emphasis>pretty hostname</emphasis> is a free-form UTF-8 hostname for presentation to the
user. User interfaces should ensure that the pretty hostname and the static hostname stay in sync.
I.e. when the former is <literal>Lennarts Computer</literal> the latter should be
<literal>lennarts-computer</literal>. If no pretty hostname is set this setting will be the empty
string. Applications should then find a suitable fallback, such as the dynamic hostname.</para>
<para>The <varname>PrettyHostname</varname> property exposes the <emphasis>pretty hostname</emphasis>
which is a free-form UTF-8 hostname for presentation to the user. User interfaces should ensure that the
pretty hostname and the static hostname stay in sync. E.g. when the former is <literal>Lennarts
Computer</literal> the latter should be <literal>lennarts-computer</literal>. If no pretty hostname is
set this setting will be the empty string. Applications should then find a suitable fallback, such as the
dynamic hostname.</para>
<para>The <emphasis>icon name</emphasis> is a name following the XDG icon naming spec. If not set,
information such as the chassis type (see below) is used to find a suitable fallback icon name
(i.e. <literal>computer-laptop</literal> vs. <literal>computer-desktop</literal> is picked based on the
chassis information). If no such data is available, the empty string is returned. In that case an application
should fall back to a replacement icon, for example <literal>computer</literal>. If this property is set
to the empty string, the automatic fallback name selection is enabled again.</para>
<para>The <varname>IconName</varname> property exposes the <emphasis>icon name</emphasis> following the
XDG icon naming spec. If not set, information such as the chassis type (see below) is used to find a
suitable fallback icon name (i.e. <literal>computer-laptop</literal>
vs. <literal>computer-desktop</literal> is picked based on the chassis information). If no such data is
available, the empty string is returned. In that case an application should fall back to a replacement
icon, for example <literal>computer</literal>. If this property is set to the empty string, the automatic
fallback name selection is enabled again.</para>
<para>The <emphasis>chassis type</emphasis> should be one of the currently defined chassis types:
<literal>desktop</literal>, <literal>laptop</literal>, <literal>server</literal>,
<literal>tablet</literal>, <literal>handset</literal>, as well as the special chassis types
<literal>vm</literal> and <literal>container</literal> for virtualized systems. Note that in most cases
the chassis type will be determined automatically from DMI/SMBIOS/ACPI firmware information. Writing to
this setting is hence useful only to override misdetected chassis types, or to configure the chassis type if
it could not be auto-detected. Set this property to the empty string to reenable the automatic detection of
the chassis type from firmware information.</para>
<para>The <varname>Chassis</varname> property exposes a <emphasis>chassis type</emphasis>, one of the
currently defined chassis types: <literal>desktop</literal>, <literal>laptop</literal>,
<literal>server</literal>, <literal>tablet</literal>, <literal>handset</literal>, as well as the special
chassis types <literal>vm</literal> and <literal>container</literal> for virtualized systems. Note that
in most cases the chassis type will be determined automatically from DMI/SMBIOS/ACPI firmware
information. Writing to this setting is hence useful only to override misdetected chassis types, or to
configure the chassis type if it could not be auto-detected. Set this property to the empty string to
reenable the automatic detection of the chassis type from firmware information.</para>
<para>Note that <filename>systemd-hostnamed</filename> starts only on request and terminates after a
short idle period. This effectively means that <function>PropertyChanged</function> messages are not sent
out for changes made directly on the files (as in: administrator edits the files with vi). This is
the intended behavior: manual configuration changes should require manual reloading.</para>
<para>The transient (dynamic) hostname maps directly to the kernel hostname. This hostname should be
assumed to be highly dynamic, and hence should be watched directly, without depending on
<function>PropertyChanged</function> messages from <filename>systemd-hostnamed</filename>. To accomplish
this, open <filename>/proc/sys/kernel/hostname</filename> and
<para>The transient (dynamic) hostname exposed by the <varname>Hostname</varname> property maps directly
to the kernel hostname. This hostname should be assumed to be highly dynamic, and hence should be watched
directly, without depending on <function>PropertyChanged</function> messages from
<filename>systemd-hostnamed</filename>. To accomplish this, open
<filename>/proc/sys/kernel/hostname</filename> and
<citerefentry project="man-pages"><refentrytitle>poll</refentrytitle><manvolnum>3</manvolnum></citerefentry>
for <constant>SIGHUP</constant> which is triggered by the kernel every time the hostname changes. Again:
this is special for the transient (dynamic) hostname, and does not apply to the configured (fixed)
@ -206,15 +204,17 @@ node /org/freedesktop/hostname1 {
for that. For more information on these files and syscalls see the respective man pages.</para>
<refsect2>
<title>Methods and Properties</title>
<title>Methods</title>
<para><function>SetHostname()</function> sets the transient (dynamic) hostname which is exposed by the
<varname>Hostname</varname> property. If empty, the transient hostname is set to the static hostname.
</para>
<para><function>SetHostname()</function> sets the transient (dynamic) hostname, which is used if no
static hostname is set. This value must be an internet-style hostname, 7-bit lowercase ASCII, no
special chars/spaces. An empty string will unset the transient hostname.</para>
<para><function>SetStaticHostname()</function> sets the static hostname which is exposed by the
<varname>StaticHostname</varname> property. If empty, the built-in default of
<literal>&FALLBACK_HOSTNAME;</literal> is used.</para>
<varname>StaticHostname</varname> property. When called with an empty argument, the static
configuration in <filename>/etc/hostname</filename> is removed. Since the static hostname has the
highest priority, calling this function usually affects also the <varname>Hostname</varname> property
and the effective hostname configured in the kernel.</para>
<para><function>SetPrettyHostname()</function> sets the pretty hostname which is exposed by the
<varname>PrettyHostname</varname> property.</para>
@ -287,10 +287,6 @@ node /org/freedesktop/hostname1 {
with <citerefentry><refentrytitle>nss-myhostname</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
</para>
<para>A client that wants to change the local hostname for DHCP/mDNS should invoke
<code>SetHostname("newname", false)</code> as soon as the name is available and afterwards reset it via
<code>SetHostname("")</code>.</para>
<para>Here are some recommendations to follow when generating a static (internet) hostname from a pretty
name:
<itemizedlist>

View File

@ -51,9 +51,15 @@
</listitem>
</itemizedlist></para>
<para>The static hostname is stored in <filename>/etc/hostname</filename>, see
<citerefentry><refentrytitle>hostname</refentrytitle><manvolnum>5</manvolnum></citerefentry> for more
information. The pretty hostname, chassis type, and icon name are stored in
<filename>/etc/machine-info</filename>, see
<citerefentry><refentrytitle>machine-info</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</para>
<para>The tool
<citerefentry><refentrytitle>hostnamectl</refentrytitle><manvolnum>1</manvolnum></citerefentry>
is a command line client to this service.</para>
<citerefentry><refentrytitle>hostnamectl</refentrytitle><manvolnum>1</manvolnum></citerefentry> is a
command line client to this service.</para>
<para>See
<citerefentry><refentrytitle>org.freedesktop.hostname1</refentrytitle><manvolnum>5</manvolnum></citerefentry>