2020-04-09 21:42:27 +08:00
<?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" [
<!ENTITY % entities SYSTEM "custom-entities.ent" >
%entities;
]>
<!-- SPDX - License - Identifier: LGPL - 2.1+ -->
<refentry id= "org.freedesktop.hostname1" conditional= 'ENABLE_HOSTNAMED'
xmlns:xi="http://www.w3.org/2001/XInclude">
<refentryinfo >
<title > org.freedesktop.hostname1</title>
<productname > systemd</productname>
</refentryinfo>
<refmeta >
<refentrytitle > org.freedesktop.hostname1</refentrytitle>
<manvolnum > 5</manvolnum>
</refmeta>
<refnamediv >
<refname > org.freedesktop.hostname1</refname>
<refpurpose > The D-Bus interface of systemd-hostnamed</refpurpose>
</refnamediv>
<refsect1 >
<title > Introduction</title>
<para >
<citerefentry > <refentrytitle > systemd-hostnamed.service</refentrytitle> <manvolnum > 8</manvolnum> </citerefentry>
2020-04-11 23:08:04 +08:00
is a system service that can be used to control the hostname and related machine metadata from user
2020-04-09 21:42:27 +08:00
programs. This page describes the hostname semantics and the D-Bus interface.</para>
</refsect1>
<refsect1 >
<title > The D-Bus API</title>
<para > The service exposes the following interfaces on the bus:</para>
<programlisting >
$ gdbus introspect --system \
--dest org.freedesktop.hostname1 \
--object-path /org/freedesktop/hostname1
node /org/freedesktop/hostname1 {
interface org.freedesktop.hostname1 {
methods:
2020-04-10 21:07:03 +08:00
SetHostname(in s hostname,
in b interactive);
SetStaticHostname(in s hostname,
in b interactive);
SetPrettyHostname(in s hostname,
in b interactive);
SetIconName(in s icon,
in b interactive);
SetChassis(in s chassis,
in b interactive);
SetDeployment(in s deployment,
in b interactive);
SetLocation(in s location,
in b interactive);
GetProductUUID(in b interactive,
out ay uuid);
2020-04-09 21:42:27 +08:00
properties:
2020-04-10 21:07:03 +08:00
readonly s Hostname = '...';
readonly s StaticHostname = '...';
readonly s PrettyHostname = '...';
readonly s IconName = '...';
readonly s Chassis = '...';
readonly s Deployment = '...';
readonly s Location = '...';
@org.freedesktop.DBus.Property.EmitsChangedSignal("const")
readonly s KernelName = '...';
@org.freedesktop.DBus.Property.EmitsChangedSignal("const")
readonly s KernelRelease = '...';
@org.freedesktop.DBus.Property.EmitsChangedSignal("const")
readonly s KernelVersion = '...';
@org.freedesktop.DBus.Property.EmitsChangedSignal("const")
readonly s OperatingSystemPrettyName = '...';
@org.freedesktop.DBus.Property.EmitsChangedSignal("const")
readonly s OperatingSystemCPEName = '...';
@org.freedesktop.DBus.Property.EmitsChangedSignal("const")
readonly s HomeURL = '...';
2020-04-09 21:42:27 +08:00
};
2020-04-10 21:07:03 +08:00
interface org.freedesktop.DBus.Peer { ... };
interface org.freedesktop.DBus.Introspectable { ... };
interface org.freedesktop.DBus.Properties { ... };
2020-04-09 21:42:27 +08:00
};
</programlisting>
2020-04-10 21:07:03 +08:00
<!-- method SetDeployment is not documented! -->
<!-- method SetLocation is not documented! -->
<!-- method GetProductUUID is not documented! -->
<!-- property Hostname is not documented! -->
<!-- property StaticHostname is not documented! -->
<!-- property PrettyHostname is not documented! -->
<!-- property IconName is not documented! -->
<!-- property Chassis is not documented! -->
<!-- property Deployment is not documented! -->
<!-- property Location is not documented! -->
<!-- property KernelName is not documented! -->
<!-- property KernelRelease is not documented! -->
<!-- property KernelVersion is not documented! -->
<!-- property OperatingSystemPrettyName is not documented! -->
<!-- property OperatingSystemCPEName is not documented! -->
<!-- property HomeURL is not documented! -->
2020-04-11 23:08:04 +08:00
<para > Whenever the hostname or other metadata is changed via the daemon,
2020-04-09 21:42:27 +08:00
<function > PropertyChanged</function> signals are sent out to subscribed clients. Changing a hostname
using this interface is authenticated via PolicyKit.</para>
</refsect1>
<refsect1 >
<title > Semantics</title>
2020-04-11 23:08:04 +08:00
<para > The <emphasis > static (configured) hostname</emphasis> is the one configured in
2020-04-09 21:42:27 +08:00
<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
2020-04-10 21:07:03 +08:00
<citerefentry project= "man-pages" > <refentrytitle > gethostname</refentrytitle> <manvolnum > 3</manvolnum> </citerefentry>
2020-04-11 23:08:04 +08:00
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
2020-04-09 21:42:27 +08:00
internet-style hostname, 7-bit lowercase ASCII, no special chars/spaces.</para>
2020-04-11 23:08:04 +08:00
<para > The <emphasis > transient (dynamic) hostname</emphasis> is the one configured via the kernel's
2020-04-10 21:07:03 +08:00
<citerefentry project= "man-pages" > <refentrytitle > sethostname</refentrytitle> <manvolnum > 3</manvolnum> </citerefentry> .
2020-04-11 23:08:04 +08:00
It can be different from the static hostname if DHCP or mDNS have been configured to change the name
2020-04-09 21:42:27 +08:00
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
2020-04-11 23:08:04 +08:00
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
2020-04-09 21:42:27 +08:00
should be an internet-style hostname, 7-bit lowercase ASCII, no special chars/spaces.</para>
2020-04-11 23:08:04 +08:00
<para > The <emphasis > pretty hostname</emphasis> is a free-form UTF-8 hostname for presentation to the
2020-04-09 21:42:27 +08:00
user. User interfaces should ensure that the pretty hostname and the static hostname stay in sync.
I.e. when the former is <literal > Lennart’ s Computer</literal> the latter should be
2020-04-11 23:08:04 +08:00
<literal > lennarts-computer</literal> . If no pretty hostname is set this setting will be the empty
2020-04-09 21:42:27 +08:00
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
2020-04-11 23:08:04 +08:00
chassis information). If no such data is available, the empty string is returned. In that case an application
2020-04-09 21:42:27 +08:00
should fall back to a replacement icon, for example <literal > computer</literal> . If this property is set
2020-04-11 23:08:04 +08:00
to the empty string, the automatic fallback name selection is enabled again.</para>
2020-04-09 21:42:27 +08:00
2020-04-11 23:08:04 +08:00
<para > The <emphasis > chassis type</emphasis> should be one of the currently defined chassis types:
2020-04-09 21:42:27 +08:00
<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
2020-04-11 23:08:04 +08:00
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
2020-04-09 21:42:27 +08:00
the chassis type from firmware information.</para>
2020-04-11 23:08:04 +08:00
<para > A client that wants to change the local hostname for DHCP/mDNS should invoke
2020-04-09 21:42:27 +08:00
<code > SetHostname("newname", false)</code> as soon as the name is available and afterwards reset it via
<code > SetHostname("")</code> .</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
2020-04-11 23:08:04 +08:00
the intended behavior: manual configuration changes should require manual reloading.</para>
2020-04-09 21:42:27 +08:00
2020-04-11 23:08:04 +08:00
<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
2020-04-10 21:07:03 +08:00
<citerefentry project= "man-pages" > <refentrytitle > poll</refentrytitle> <manvolnum > 3</manvolnum> </citerefentry>
2020-04-09 21:42:27 +08:00
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)
hostname.</para>
2020-04-11 23:08:04 +08:00
<para > Applications may read the hostname data directly if hostname change notifications
2020-04-09 21:42:27 +08:00
are not necessary. Use
2020-04-10 21:07:03 +08:00
<citerefentry project= "man-pages" > <refentrytitle > gethostname</refentrytitle> <manvolnum > 3</manvolnum> </citerefentry> ,
2020-04-09 21:42:27 +08:00
<filename > /etc/hostname</filename> (possibly with per-distribution fallbacks), and
<citerefentry > <refentrytitle > machine-info</refentrytitle> <manvolnum > 3</manvolnum> </citerefentry>
for that. For more information on these files and syscalls see the respective man pages.</para>
2020-04-11 23:08:04 +08:00
<para > The <varname > user_interaction</varname> boolean parameters can be used to control whether PolicyKit
should interactively ask the user for authentication credentials if required.</para>
2020-04-09 21:42:27 +08:00
<para > The PolicyKit action for <function > SetHostname()</function> is
<interfacename > org.freedesktop.hostname1.set-hostname</interfacename> . For
<function > SetStaticHostname()</function> and <function > SetPrettyHostname()</function> it is
<interfacename > org.freedesktop.hostname1.set-static-hostname</interfacename> . For
<function > SetIconName()</function> and <function > SetChassis()</function> it is
<interfacename > org.freedesktop.hostname1.set-machine-info</interfacename> .</para>
2020-04-11 23:08:04 +08:00
<para > Here are three examples show how the pretty hostname and the icon name should be used:
2020-04-09 21:42:27 +08:00
<itemizedlist >
2020-04-11 23:08:04 +08:00
<listitem > <para > When registering DNS-SD services: use the pretty hostname in the service name, and
2020-04-09 21:42:27 +08:00
pass the icon name in the TXT data, if there is an icon name. Browsing clients can then show the server
2020-04-11 23:08:04 +08:00
icon on each service. This is especially useful for WebDAV applications or UPnP media sharing.
</para> </listitem>
2020-04-09 21:42:27 +08:00
2020-04-11 23:08:04 +08:00
<listitem > <para > Set the bluetooth name to the pretty hostname.</para> </listitem>
2020-04-09 21:42:27 +08:00
<listitem > <para > When your file browser has a "Computer" icon, replace the name with the pretty hostname if set, and the icon with the icon name, if it is set.</para> </listitem>
</itemizedlist> </para>
<para > To properly handle name lookups with changing local hostnames without having to edit
2020-04-11 23:08:04 +08:00
<filename > /etc/hosts</filename> , we recommend using <filename > systemd-hostnamed</filename> in
2020-04-09 21:42:27 +08:00
combination with <citerefentry > <refentrytitle > nss-myhostname</refentrytitle> <manvolnum > 3</manvolnum> </citerefentry> .
</para>
<para > Here are some recommendations to follow when generating a static (internet) hostname from a pretty
name:
<itemizedlist >
<listitem > <para > Generate a single DNS label only, not an FQDN. That means no dots allowed. Strip them,
2020-04-11 23:08:04 +08:00
or replace them with <literal > -</literal> .</para> </listitem>
2020-04-09 21:42:27 +08:00
2020-04-11 23:08:04 +08:00
<listitem > <para > It's probably safer to not use any non-ASCII chars, even if DNS allows this in some way
2020-04-09 21:42:27 +08:00
these days. In fact, restrict your charset to <literal > a-zA-Z0-9</literal> and <literal > -</literal> .
Strip other chars, or try to replace them in some smart way with chars from this set, for example
2020-04-11 23:08:04 +08:00
<literal > ä</literal> → <literal > ae</literal> , and use <literal > -</literal> as the replacement for all
punctuation characters and whitespace.</para> </listitem>
2020-04-09 21:42:27 +08:00
<listitem > <para > Try to avoid creating repeated <literal > -</literal> , as well as <literal > -</literal> as
the first or last char.</para> </listitem>
<listitem > <para > Limit the hostname to 63 chars, which is the length of a DNS label.</para> </listitem>
<listitem > <para > If after stripping special chars the empty string is the result, you can pass this
2020-04-11 23:08:04 +08:00
as-is to <filename > systemd-hostnamed</filename> in which case it will automatically use
<literal > &FALLBACK_HOSTNAME; </literal> .</para> </listitem>
2020-04-09 21:42:27 +08:00
2020-04-11 23:08:04 +08:00
<listitem > <para > Uppercase charaacters should be replaced with their lowercase equivalents.
</para> </listitem>
2020-04-09 21:42:27 +08:00
</itemizedlist> </para>
<para > Note that while <filename > systemd-hostnamed</filename> applies some checks to the hostname you pass
they are much looser than the recommendations above. For example, <filename > systemd-hostnamed</filename>
2020-04-11 23:08:04 +08:00
will also accept <literal > _</literal> in the hostname, but we recommend not using this to avoid clashes
2020-04-09 21:42:27 +08:00
with DNS-SD service types. Also <filename > systemd-hostnamed</filename> allows longer hostnames, but
2020-04-11 23:08:04 +08:00
because of the DNS label limitations, we recommend not making use of this.</para>
2020-04-09 21:42:27 +08:00
<para > Here are a couple of example conversions:
<itemizedlist >
<listitem > <para > <literal > Lennart's PC</literal> → <literal > lennarts-pc</literal> </para> </listitem>
<listitem > <para > <literal > Müllers Computer</literal> → <literal > muellers-computer</literal> </para> </listitem>
<listitem > <para > <literal > Voran!</literal> → <literal > voran</literal> </para> </listitem>
<listitem > <para > <literal > Es war einmal ein Männlein</literal> → <literal > es-war-einmal-ein-maennlein</literal> </para> </listitem>
<listitem > <para > <literal > Jawoll. Ist doch wahr!</literal> → <literal > jawoll-ist-doch-wahr</literal> </para> </listitem>
<listitem > <para > <literal > レナート</literal> → <literal > localhost</literal> </para> </listitem>
<listitem > <para > <literal > ...zack!!! zack!...</literal> → <literal > zack-zack</literal> </para> </listitem>
</itemizedlist> </para>
2020-04-11 23:08:04 +08:00
<para > Of course, an already valid internet hostname label you enter and pass through this
2020-04-09 21:42:27 +08:00
conversion should stay unmodified, so that users have direct control of it, if they want -- by simply
ignoring the fact that the pretty hostname is pretty and just edit it as if it was the normal internet
name.</para>
</refsect1>
<refsect1 >
<title > Versioning</title>
<para > These D-Bus interfaces follow <ulink url= "http://0pointer.de/blog/projects/versioning-dbus.html" >
the usual interface versioning guidelines</ulink> .</para>
</refsect1>
<refsect1 >
<title > See also</title>
<para > David Zeuthen's original Fedora
<ulink url= "https://fedoraproject.org/wiki/Features/BetterHostname" > Feature page about xdg-hostname</ulink> </para>
</refsect1>
</refentry>