2020-04-09 21:42:27 +08:00
<?xml version="1.0"?>
<!-- * - nxml - * -->
< !DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
2023-12-25 22:48:33 +08:00
"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
2020-04-09 21:42:27 +08:00
<!ENTITY % entities SYSTEM "custom-entities.ent" >
%entities;
]>
2020-11-09 12:23:58 +08:00
<!-- SPDX - License - Identifier: LGPL - 2.1 - or - later -->
2020-04-09 21:42:27 +08:00
<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>
2020-04-24 18:08:10 +08:00
<programlisting executable= "systemd-hostnamed" node= "/org/freedesktop/hostname1" interface= "org.freedesktop.hostname1" >
2020-04-09 21:42:27 +08:00
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);
2022-02-04 00:41:04 +08:00
GetHardwareSerial(out s serial);
2021-04-30 03:00:02 +08:00
Describe(out s json);
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 = '...';
2020-12-04 22:16:54 +08:00
@org.freedesktop.DBus.Property.EmitsChangedSignal("const")
2021-02-21 01:54:24 +08:00
readonly s DefaultHostname = '...';
hostnamed,shared/hostname-setup: expose the origin of the current hostname
In hostnamed this is exposed as a dbus property, and in the logs in both
places.
This is of interest to network management software and such: if the fallback
hostname is used, it's not as useful as the real configured thing. Right now
various programs try to guess the source of hostname by looking at the string.
E.g. "localhost" is assumed to be not the real hostname, but "fedora" is. Any
such attempts are bound to fail, because we cannot distinguish "fedora" (a
fallback value set by a distro), from "fedora" (received from reverse dns),
from "fedora" read from /etc/hostname.
/run/systemd/fallback-hostname is written with the fallback hostname when
either pid1 or hostnamed sets the kernel hostname to the fallback value. Why
remember the fallback value and not the transient hostname in /run/hostname
instead?
We have three hostname types: "static", "transient", fallback".
– Distinguishing "static" is easy: the hostname that is set matches what
is in /etc/hostname.
– Distingiushing "transient" and "fallback" is not easy. And the
"transient" hostname may be set outside of pid1+hostnamed. In particular,
it may be set by container manager, some non-systemd tool in the initramfs,
or even by a direct call. All those mechanisms count as "transient". Trying
to get those cases to write /run/hostname is futile. It is much easier to
isolate the "fallback" case which is mostly under our control.
And since the file is only used as a flag to mark the hostname as fallback,
it can be hidden inside of our /run/systemd directory.
For https://bugzilla.redhat.com/show_bug.cgi?id=1892235.
2020-12-05 02:40:34 +08:00
readonly s HostnameSource = '...';
2020-04-10 21:07:03 +08:00
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")
2023-01-23 20:16:52 +08:00
readonly t OperatingSystemSupportEnd = ...;
@org.freedesktop.DBus.Property.EmitsChangedSignal("const")
2020-04-10 21:07:03 +08:00
readonly s HomeURL = '...';
2020-12-18 22:25:43 +08:00
@org.freedesktop.DBus.Property.EmitsChangedSignal("const")
readonly s HardwareVendor = '...';
@org.freedesktop.DBus.Property.EmitsChangedSignal("const")
readonly s HardwareModel = '...';
2022-04-19 02:47:50 +08:00
@org.freedesktop.DBus.Property.EmitsChangedSignal("const")
readonly s FirmwareVersion = '...';
2022-12-07 01:23:18 +08:00
@org.freedesktop.DBus.Property.EmitsChangedSignal("const")
readonly s FirmwareVendor = '...';
2022-12-08 00:33:50 +08:00
@org.freedesktop.DBus.Property.EmitsChangedSignal("const")
2023-01-14 00:33:12 +08:00
readonly t FirmwareDate = ...;
2023-12-02 18:26:29 +08:00
@org.freedesktop.DBus.Property.EmitsChangedSignal("const")
readonly ay MachineID = [...];
@org.freedesktop.DBus.Property.EmitsChangedSignal("const")
readonly ay BootID = [...];
2024-01-05 23:34:33 +08:00
@org.freedesktop.DBus.Property.EmitsChangedSignal("const")
readonly u VSockCID = ...;
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
};
2024-11-07 23:47:48 +08:00
</programlisting>
2020-04-09 21:42:27 +08:00
2020-04-21 16:29:09 +08:00
<!-- Autogenerated cross - references for systemd.directives, do not edit -->
<variablelist class= "dbus-interface" generated= "True" extra-ref= "org.freedesktop.hostname1" />
<variablelist class= "dbus-interface" generated= "True" extra-ref= "org.freedesktop.hostname1" />
<variablelist class= "dbus-method" generated= "True" extra-ref= "SetHostname()" />
<variablelist class= "dbus-method" generated= "True" extra-ref= "SetStaticHostname()" />
<variablelist class= "dbus-method" generated= "True" extra-ref= "SetPrettyHostname()" />
<variablelist class= "dbus-method" generated= "True" extra-ref= "SetIconName()" />
<variablelist class= "dbus-method" generated= "True" extra-ref= "SetChassis()" />
<variablelist class= "dbus-method" generated= "True" extra-ref= "SetDeployment()" />
<variablelist class= "dbus-method" generated= "True" extra-ref= "SetLocation()" />
<variablelist class= "dbus-method" generated= "True" extra-ref= "GetProductUUID()" />
2022-01-23 02:12:35 +08:00
<variablelist class= "dbus-method" generated= "True" extra-ref= "GetHardwareSerial()" />
2021-04-28 21:59:13 +08:00
<variablelist class= "dbus-method" generated= "True" extra-ref= "Describe()" />
2020-04-21 16:29:09 +08:00
<variablelist class= "dbus-property" generated= "True" extra-ref= "Hostname" />
<variablelist class= "dbus-property" generated= "True" extra-ref= "StaticHostname" />
<variablelist class= "dbus-property" generated= "True" extra-ref= "PrettyHostname" />
2021-02-21 01:54:24 +08:00
<variablelist class= "dbus-property" generated= "True" extra-ref= "DefaultHostname" />
2020-12-04 22:16:54 +08:00
hostnamed,shared/hostname-setup: expose the origin of the current hostname
In hostnamed this is exposed as a dbus property, and in the logs in both
places.
This is of interest to network management software and such: if the fallback
hostname is used, it's not as useful as the real configured thing. Right now
various programs try to guess the source of hostname by looking at the string.
E.g. "localhost" is assumed to be not the real hostname, but "fedora" is. Any
such attempts are bound to fail, because we cannot distinguish "fedora" (a
fallback value set by a distro), from "fedora" (received from reverse dns),
from "fedora" read from /etc/hostname.
/run/systemd/fallback-hostname is written with the fallback hostname when
either pid1 or hostnamed sets the kernel hostname to the fallback value. Why
remember the fallback value and not the transient hostname in /run/hostname
instead?
We have three hostname types: "static", "transient", fallback".
– Distinguishing "static" is easy: the hostname that is set matches what
is in /etc/hostname.
– Distingiushing "transient" and "fallback" is not easy. And the
"transient" hostname may be set outside of pid1+hostnamed. In particular,
it may be set by container manager, some non-systemd tool in the initramfs,
or even by a direct call. All those mechanisms count as "transient". Trying
to get those cases to write /run/hostname is futile. It is much easier to
isolate the "fallback" case which is mostly under our control.
And since the file is only used as a flag to mark the hostname as fallback,
it can be hidden inside of our /run/systemd directory.
For https://bugzilla.redhat.com/show_bug.cgi?id=1892235.
2020-12-05 02:40:34 +08:00
<variablelist class= "dbus-property" generated= "True" extra-ref= "HostnameSource" />
2020-04-21 16:29:09 +08:00
<variablelist class= "dbus-property" generated= "True" extra-ref= "IconName" />
<variablelist class= "dbus-property" generated= "True" extra-ref= "Chassis" />
<variablelist class= "dbus-property" generated= "True" extra-ref= "Deployment" />
<variablelist class= "dbus-property" generated= "True" extra-ref= "Location" />
<variablelist class= "dbus-property" generated= "True" extra-ref= "KernelName" />
<variablelist class= "dbus-property" generated= "True" extra-ref= "KernelRelease" />
<variablelist class= "dbus-property" generated= "True" extra-ref= "KernelVersion" />
<variablelist class= "dbus-property" generated= "True" extra-ref= "OperatingSystemPrettyName" />
<variablelist class= "dbus-property" generated= "True" extra-ref= "OperatingSystemCPEName" />
2023-01-23 20:16:52 +08:00
<variablelist class= "dbus-property" generated= "True" extra-ref= "OperatingSystemSupportEnd" />
2020-04-21 16:29:09 +08:00
<variablelist class= "dbus-property" generated= "True" extra-ref= "HomeURL" />
2020-12-18 22:25:43 +08:00
<variablelist class= "dbus-property" generated= "True" extra-ref= "HardwareVendor" />
<variablelist class= "dbus-property" generated= "True" extra-ref= "HardwareModel" />
2022-04-19 02:47:50 +08:00
<variablelist class= "dbus-property" generated= "True" extra-ref= "FirmwareVersion" />
2022-12-07 01:23:18 +08:00
<variablelist class= "dbus-property" generated= "True" extra-ref= "FirmwareVendor" />
2022-12-08 00:33:50 +08:00
<variablelist class= "dbus-property" generated= "True" extra-ref= "FirmwareDate" />
2023-12-02 18:26:29 +08:00
<variablelist class= "dbus-property" generated= "True" extra-ref= "MachineID" />
<variablelist class= "dbus-property" generated= "True" extra-ref= "BootID" />
2024-01-05 23:34:33 +08:00
<variablelist class= "dbus-property" generated= "True" extra-ref= "VSockCID" />
2020-04-21 16:29:09 +08:00
<!-- End of Autogenerated section -->
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
2020-04-18 23:47:51 +08:00
using this interface is authenticated via
<ulink url= "https://www.freedesktop.org/software/polkit/docs/latest/" > polkit</ulink> .</para>
2020-04-09 21:42:27 +08:00
</refsect1>
<refsect1 >
<title > Semantics</title>
2020-12-04 22:16:24 +08:00
<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
2020-04-10 21:07:03 +08:00
<citerefentry project= "man-pages" > <refentrytitle > gethostname</refentrytitle> <manvolnum > 3</manvolnum> </citerefentry>
2020-12-04 22:16:24 +08:00
system call. If no static hostname is configured this property will be the empty string.</para>
2020-04-09 21:42:27 +08:00
2020-12-04 22:16:24 +08:00
<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
2023-06-23 22:34:55 +08:00
<citerefentry project= "man-pages" > <refentrytitle > sethostname</refentrytitle> <manvolnum > 2</manvolnum> </citerefentry> .
2020-12-04 22:16:24 +08:00
It can be different from the static hostname. This property is never empty.</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 > Lennart’ s
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>
2021-02-21 01:54:24 +08:00
<para > The <varname > DefaultHostname</varname> property exposes the default hostname (configured through
<citerefentry > <refentrytitle > os-release</refentrytitle> <manvolnum > 5</manvolnum> </citerefentry> , or a
fallback set at compilation time).</para>
2020-12-04 22:16:54 +08:00
hostnamed,shared/hostname-setup: expose the origin of the current hostname
In hostnamed this is exposed as a dbus property, and in the logs in both
places.
This is of interest to network management software and such: if the fallback
hostname is used, it's not as useful as the real configured thing. Right now
various programs try to guess the source of hostname by looking at the string.
E.g. "localhost" is assumed to be not the real hostname, but "fedora" is. Any
such attempts are bound to fail, because we cannot distinguish "fedora" (a
fallback value set by a distro), from "fedora" (received from reverse dns),
from "fedora" read from /etc/hostname.
/run/systemd/fallback-hostname is written with the fallback hostname when
either pid1 or hostnamed sets the kernel hostname to the fallback value. Why
remember the fallback value and not the transient hostname in /run/hostname
instead?
We have three hostname types: "static", "transient", fallback".
– Distinguishing "static" is easy: the hostname that is set matches what
is in /etc/hostname.
– Distingiushing "transient" and "fallback" is not easy. And the
"transient" hostname may be set outside of pid1+hostnamed. In particular,
it may be set by container manager, some non-systemd tool in the initramfs,
or even by a direct call. All those mechanisms count as "transient". Trying
to get those cases to write /run/hostname is futile. It is much easier to
isolate the "fallback" case which is mostly under our control.
And since the file is only used as a flag to mark the hostname as fallback,
it can be hidden inside of our /run/systemd directory.
For https://bugzilla.redhat.com/show_bug.cgi?id=1892235.
2020-12-05 02:40:34 +08:00
<para > The <varname > HostnameSource</varname> property exposes the origin of the currently configured
hostname. One of <literal > static</literal> (set from <filename > /etc/hostname</filename> ),
<literal > transient</literal> (a non-permanent hostname from an external source),
2021-06-30 19:53:14 +08:00
<literal > default</literal> (the value from <filename > os-release</filename> or the compiled-in
2021-02-21 01:54:24 +08:00
fallback).</para>
hostnamed,shared/hostname-setup: expose the origin of the current hostname
In hostnamed this is exposed as a dbus property, and in the logs in both
places.
This is of interest to network management software and such: if the fallback
hostname is used, it's not as useful as the real configured thing. Right now
various programs try to guess the source of hostname by looking at the string.
E.g. "localhost" is assumed to be not the real hostname, but "fedora" is. Any
such attempts are bound to fail, because we cannot distinguish "fedora" (a
fallback value set by a distro), from "fedora" (received from reverse dns),
from "fedora" read from /etc/hostname.
/run/systemd/fallback-hostname is written with the fallback hostname when
either pid1 or hostnamed sets the kernel hostname to the fallback value. Why
remember the fallback value and not the transient hostname in /run/hostname
instead?
We have three hostname types: "static", "transient", fallback".
– Distinguishing "static" is easy: the hostname that is set matches what
is in /etc/hostname.
– Distingiushing "transient" and "fallback" is not easy. And the
"transient" hostname may be set outside of pid1+hostnamed. In particular,
it may be set by container manager, some non-systemd tool in the initramfs,
or even by a direct call. All those mechanisms count as "transient". Trying
to get those cases to write /run/hostname is futile. It is much easier to
isolate the "fallback" case which is mostly under our control.
And since the file is only used as a flag to mark the hostname as fallback,
it can be hidden inside of our /run/systemd directory.
For https://bugzilla.redhat.com/show_bug.cgi?id=1892235.
2020-12-05 02:40:34 +08:00
2020-12-04 22:16:24 +08:00
<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 <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>
2020-04-09 21:42:27 +08:00
<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-12-04 22:16:24 +08:00
<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
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
2023-06-23 22:34:55 +08:00
<citerefentry project= "man-pages" > <refentrytitle > gethostname</refentrytitle> <manvolnum > 2</manvolnum> </citerefentry> ,
2020-04-09 21:42:27 +08:00
<filename > /etc/hostname</filename> (possibly with per-distribution fallbacks), and
2024-11-12 03:10:00 +08:00
<citerefentry > <refentrytitle > machine-info</refentrytitle> <manvolnum > 5</manvolnum> </citerefentry>
2020-04-09 21:42:27 +08:00
for that. For more information on these files and syscalls see the respective man pages.</para>
2021-04-28 21:59:13 +08:00
<para > <varname > KernelName</varname> , <varname > KernelRelease</varname> , and
<varname > KernelVersion</varname> expose the kernel name (e.g. <literal > Linux</literal> ), release
(e.g. <literal > 5.0.0-11</literal> ), and version (i.e. the build number, e.g. <literal > #11</literal> ) as
reported by <citerefentry project= "man-pages" > <refentrytitle > uname</refentrytitle> <manvolnum > 2</manvolnum> </citerefentry> .
<varname > OperatingSystemPrettyName</varname> , <varname > OperatingSystemCPEName</varname> , and
<varname > HomeURL</varname> expose the <varname > PRETTY_NAME=</varname> , <varname > CPE_NAME=</varname> and
<varname > HOME_URL=</varname> fields from
<citerefentry > <refentrytitle > os-release</refentrytitle> <manvolnum > 5</manvolnum> </citerefentry> . The
purpose of those properties is to allow remote clients to access this information over D-Bus. Local
clients can access the information directly.</para>
2024-01-05 23:34:33 +08:00
<para > <varname > MachineID</varname> expose the 128bit machine ID, see
<citerefentry > <refentrytitle > machine-id</refentrytitle> <manvolnum > 5</manvolnum> </citerefentry> for
details.</para>
<para > <varname > BootID</varname> expose the 128bit boot ID, as per
<filename > /proc/sys/kernel/random/boot_id</filename> .</para>
<para > <varname > VSockCID</varname> exposes the system's local <constant > AF_VSOCK</constant> CID (Context
Identifier, i.e. address) for the system, if one is available in the virtual machine environment. Set to
<constant > UINT32_MAX</constant> otherwise. See <citerefentry project= "man-pages" > <refentrytitle > vsock</refentrytitle> <manvolnum > 7</manvolnum> </citerefentry> for
details.</para>
2024-04-19 21:25:43 +08:00
<para > <varname > OperatingSystemSupportEnd</varname> exposes when the OS' vendor support ends, if this
information is known. It's an unsigned 64bit value, in µs since the UNIX epoch, UTC. If this information
is not known carries the value 2^64-1, i.e. <constant > UINT64_MAX</constant> .</para>
<para > <varname > HardwareVendor</varname> and <varname > HardwareModel</varname> expose information about the
vendor of the hardware of the system. If no such information can be determined these properties are set
to empty strings.</para>
<para > <varname > FirmwareVersion</varname> and <varname > FirmwareVendor</varname> expose information about
the system's firmware, i.e. a version string and a vendor name. If no such information can be determined
these properties are set to empty strings.</para>
<para > <varname > FirmwareDate</varname> exposes the firmware build date, if that information is known. It's
an unsigned 64bit value, in µs since the UNIX epoch, UTC. If not known
<constant > UNIT64_MAX</constant> .</para>
2020-04-14 17:07:35 +08:00
<refsect2 >
2020-12-04 22:16:24 +08:00
<title > Methods</title>
2020-04-14 17:07:35 +08:00
2020-12-04 22:16:24 +08:00
<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>
2020-04-14 17:07:35 +08:00
<para > <function > SetStaticHostname()</function> sets the static hostname which is exposed by the
2020-12-04 22:16:24 +08:00
<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>
2020-04-14 17:07:35 +08:00
<para > <function > SetPrettyHostname()</function> sets the pretty hostname which is exposed by the
<varname > PrettyHostname</varname> property.</para>
<para > <function > SetIconName()</function> , <function > SetChassis()</function> ,
<function > SetDeployment()</function> , and <function > SetLocation()</function> set the properties
<varname > IconName</varname> (the name of the icon representing for the machine),
<varname > Chassis</varname> (the machine form factor), <varname > Deployment</varname> (the system
deployment environment), and <varname > Location</varname> (physical system location), respectively.
</para>
<para > <varname > PrettyHostname</varname> , <varname > IconName</varname> , <varname > Chassis</varname> ,
<varname > Deployment</varname> , and <varname > Location</varname> are stored in
<filename > /etc/machine-info</filename> . See
<citerefentry > <refentrytitle > machine-info</refentrytitle> <manvolnum > 5</manvolnum> </citerefentry> for
the semantics of those settings.</para>
2021-04-28 21:59:13 +08:00
<para > <function > GetProductUUID()</function> returns the "product UUID" as exposed by the kernel based
2020-04-14 17:07:35 +08:00
on DMI information in <filename > /sys/class/dmi/id/product_uuid</filename> . Reading the file directly
2020-04-18 23:47:51 +08:00
requires root privileges, and this method allows access to unprivileged clients through the polkit
2020-04-14 17:07:35 +08:00
framework.</para>
2024-04-19 21:25:43 +08:00
<para > <function > GetHardwareSerial()</function> returns the "hardware serial" as exposed by the kernel
based on DMI information. Reading the file directly requires root privileges, and this method allows
access to unprivileged clients through the polkit framework.</para>
2021-04-28 21:59:13 +08:00
<para > <function > Describe()</function> returns a JSON representation of all properties in one.</para>
2020-04-14 17:07:35 +08:00
</refsect2>
2020-04-14 16:28:50 +08:00
<refsect2 >
<title > Security</title>
2020-04-18 23:47:51 +08:00
<para > The <varname > interactive</varname> boolean parameters can be used to control whether polkit
2020-04-14 16:28:50 +08:00
should interactively ask the user for authentication credentials if required.</para>
2020-04-18 23:47:51 +08:00
<para > The polkit action for <function > SetHostname()</function> is
2020-04-14 16:28:50 +08:00
<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
2020-10-29 05:11:23 +08:00
<function > SetIconName()</function> , <function > SetChassis()</function> , <function > SetDeployment()</function>
and <function > SetLocation()</function> it is
2020-04-14 16:28:50 +08:00
<interfacename > org.freedesktop.hostname1.set-machine-info</interfacename> .</para>
</refsect2>
</refsect1>
2020-04-09 21:42:27 +08:00
2020-04-14 16:28:50 +08:00
<refsect1 >
<title > Recommendations</title>
2020-04-09 21:42:27 +08:00
2020-04-14 16:28:50 +08:00
<para > Here are three examples that show how the pretty hostname and the icon name should be used:
2020-04-09 21:42:27 +08:00
<itemizedlist >
2020-04-14 16:28:50 +08:00
<listitem > <para > When registering DNS-SD services: use the pretty hostname in the service name, and pass
the icon name in the TXT data, if there is an icon name. Browsing clients can then show the server icon
on each service. This is especially useful for WebDAV applications or UPnP media sharing.
2020-04-11 23:08:04 +08:00
</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
2020-04-14 16:28:50 +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>
2020-04-09 21:42:27 +08:00
</itemizedlist> </para>
<para > To properly handle name lookups with changing local hostnames without having to edit
2020-04-14 16:28:50 +08:00
<filename > /etc/hosts</filename> , we recommend using <filename > systemd-hostnamed</filename> in combination
2024-11-12 03:10:00 +08:00
with <citerefentry > <refentrytitle > nss-myhostname</refentrytitle> <manvolnum > 8</manvolnum> </citerefentry> .
2020-04-09 21:42:27 +08:00
</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
2021-02-21 01:54:24 +08:00
as-is to <filename > systemd-hostnamed</filename> in which case it will automatically use a suitable
fallback.</para> </listitem>
2020-04-09 21:42:27 +08:00
2023-02-12 07:54:07 +08:00
<listitem > <para > Uppercase characters should be replaced with their lowercase equivalents.
2020-04-11 23:08:04 +08:00
</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-14 16:28:50 +08:00
conversion should stay unmodified, so that users have direct control of it, if they want — by simply
2020-04-09 21:42:27 +08:00
ignoring the fact that the pretty hostname is pretty and just edit it as if it was the normal internet
name.</para>
</refsect1>
2020-04-24 18:08:10 +08:00
<refsect1 >
<title > Examples</title>
<example >
<title > Introspect <interfacename > org.freedesktop.hostname1</interfacename> on the bus</title>
<programlisting > $ gdbus introspect --system \
--dest org.freedesktop.hostname1 \
--object-path /org/freedesktop/hostname1
2024-11-07 23:47:48 +08:00
</programlisting>
2020-04-24 18:08:10 +08:00
</example>
</refsect1>
2024-11-05 21:20:01 +08:00
<xi:include href= "org.freedesktop.locale1.xml" xpointer= "versioning" />
2023-09-10 21:40:03 +08:00
<refsect1 >
<title > History</title>
<refsect2 >
<title > The D-Bus API</title>
<para > <varname > FirmwareVersion</varname> and
<function > GetHardwareSerial()</function> were added in version 251.</para>
<para > <varname > OperatingSystemSupportEnd</varname> ,
<varname > FirmwareVendor</varname> , and
<varname > FirmwareDate</varname> were added in version 253.</para>
2024-01-05 23:34:33 +08:00
<para > <varname > MachineID</varname> , <varname > BootID</varname> and
<varname > VSockCID</varname> were added in version 256.</para>
2023-09-10 21:40:03 +08:00
</refsect2>
</refsect1>
2024-11-05 21:20:01 +08:00
<refsect1 >
<title > See Also</title>
<para > <simplelist type= "inline" >
<member > <citerefentry > <refentrytitle > systemd</refentrytitle> <manvolnum > 1</manvolnum> </citerefentry> </member>
<member > <citerefentry > <refentrytitle > systemd-hostnamed.service</refentrytitle> <manvolnum > 8</manvolnum> </citerefentry> </member>
<member > <citerefentry > <refentrytitle > hostnamectl</refentrytitle> <manvolnum > 1</manvolnum> </citerefentry> </member>
<member > David Zeuthen's original Fedora
<ulink url= "https://fedoraproject.org/wiki/Features/BetterHostname" > Feature page about xdg-hostname</ulink> </member>
</simplelist> </para>
</refsect1>
2020-04-09 21:42:27 +08:00
</refentry>