]> git.ipfire.org Git - thirdparty/systemd.git/blame - man/org.freedesktop.hostname1.xml
update-dbus-docs: use executables in build/
[thirdparty/systemd.git] / man / org.freedesktop.hostname1.xml
CommitLineData
e09a36bd
ZJS
1<?xml version="1.0"?>
2<!--*-nxml-*-->
3<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
4 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd" [
5<!ENTITY % entities SYSTEM "custom-entities.ent" >
6%entities;
7]>
8<!-- SPDX-License-Identifier: LGPL-2.1+ -->
9
10<refentry id="org.freedesktop.hostname1" conditional='ENABLE_HOSTNAMED'
11 xmlns:xi="http://www.w3.org/2001/XInclude">
12 <refentryinfo>
13 <title>org.freedesktop.hostname1</title>
14 <productname>systemd</productname>
15 </refentryinfo>
16
17 <refmeta>
18 <refentrytitle>org.freedesktop.hostname1</refentrytitle>
19 <manvolnum>5</manvolnum>
20 </refmeta>
21
22 <refnamediv>
23 <refname>org.freedesktop.hostname1</refname>
24 <refpurpose>The D-Bus interface of systemd-hostnamed</refpurpose>
25 </refnamediv>
26
27 <refsect1>
28 <title>Introduction</title>
29
30 <para>
31 <citerefentry><refentrytitle>systemd-hostnamed.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>
8024ac43 32 is a system service that can be used to control the hostname and related machine metadata from user
e09a36bd
ZJS
33 programs. This page describes the hostname semantics and the D-Bus interface.</para>
34 </refsect1>
35
36 <refsect1>
37 <title>The D-Bus API</title>
38
39 <para>The service exposes the following interfaces on the bus:</para>
40
41 <programlisting>
42$ gdbus introspect --system \
43 --dest org.freedesktop.hostname1 \
44 --object-path /org/freedesktop/hostname1
45
46node /org/freedesktop/hostname1 {
47 interface org.freedesktop.hostname1 {
48 methods:
4fb222c4
ZJS
49 SetHostname(in s hostname,
50 in b interactive);
51 SetStaticHostname(in s hostname,
52 in b interactive);
53 SetPrettyHostname(in s hostname,
54 in b interactive);
55 SetIconName(in s icon,
56 in b interactive);
57 SetChassis(in s chassis,
58 in b interactive);
59 SetDeployment(in s deployment,
60 in b interactive);
61 SetLocation(in s location,
62 in b interactive);
63 GetProductUUID(in b interactive,
64 out ay uuid);
e09a36bd 65 properties:
4fb222c4
ZJS
66 readonly s Hostname = '...';
67 readonly s StaticHostname = '...';
68 readonly s PrettyHostname = '...';
69 readonly s IconName = '...';
70 readonly s Chassis = '...';
71 readonly s Deployment = '...';
72 readonly s Location = '...';
73 @org.freedesktop.DBus.Property.EmitsChangedSignal("const")
74 readonly s KernelName = '...';
75 @org.freedesktop.DBus.Property.EmitsChangedSignal("const")
76 readonly s KernelRelease = '...';
77 @org.freedesktop.DBus.Property.EmitsChangedSignal("const")
78 readonly s KernelVersion = '...';
79 @org.freedesktop.DBus.Property.EmitsChangedSignal("const")
80 readonly s OperatingSystemPrettyName = '...';
81 @org.freedesktop.DBus.Property.EmitsChangedSignal("const")
82 readonly s OperatingSystemCPEName = '...';
83 @org.freedesktop.DBus.Property.EmitsChangedSignal("const")
84 readonly s HomeURL = '...';
e09a36bd 85 };
4fb222c4
ZJS
86 interface org.freedesktop.DBus.Peer { ... };
87 interface org.freedesktop.DBus.Introspectable { ... };
88 interface org.freedesktop.DBus.Properties { ... };
e09a36bd
ZJS
89};
90 </programlisting>
91
00bb75d7
ZJS
92 <!--Autogenerated cross-references for systemd.directives, do not edit-->
93
94 <variablelist class="dbus-interface" generated="True" extra-ref="org.freedesktop.hostname1"/>
95
96 <variablelist class="dbus-interface" generated="True" extra-ref="org.freedesktop.hostname1"/>
97
98 <variablelist class="dbus-method" generated="True" extra-ref="SetHostname()"/>
99
100 <variablelist class="dbus-method" generated="True" extra-ref="SetStaticHostname()"/>
101
102 <variablelist class="dbus-method" generated="True" extra-ref="SetPrettyHostname()"/>
103
104 <variablelist class="dbus-method" generated="True" extra-ref="SetIconName()"/>
105
106 <variablelist class="dbus-method" generated="True" extra-ref="SetChassis()"/>
107
108 <variablelist class="dbus-method" generated="True" extra-ref="SetDeployment()"/>
109
110 <variablelist class="dbus-method" generated="True" extra-ref="SetLocation()"/>
111
112 <variablelist class="dbus-method" generated="True" extra-ref="GetProductUUID()"/>
113
114 <variablelist class="dbus-property" generated="True" extra-ref="Hostname"/>
115
116 <variablelist class="dbus-property" generated="True" extra-ref="StaticHostname"/>
117
118 <variablelist class="dbus-property" generated="True" extra-ref="PrettyHostname"/>
119
120 <variablelist class="dbus-property" generated="True" extra-ref="IconName"/>
121
122 <variablelist class="dbus-property" generated="True" extra-ref="Chassis"/>
123
124 <variablelist class="dbus-property" generated="True" extra-ref="Deployment"/>
125
126 <variablelist class="dbus-property" generated="True" extra-ref="Location"/>
127
128 <variablelist class="dbus-property" generated="True" extra-ref="KernelName"/>
129
130 <variablelist class="dbus-property" generated="True" extra-ref="KernelRelease"/>
131
132 <variablelist class="dbus-property" generated="True" extra-ref="KernelVersion"/>
133
134 <variablelist class="dbus-property" generated="True" extra-ref="OperatingSystemPrettyName"/>
135
136 <variablelist class="dbus-property" generated="True" extra-ref="OperatingSystemCPEName"/>
137
138 <variablelist class="dbus-property" generated="True" extra-ref="HomeURL"/>
139
140 <!--End of Autogenerated section-->
141
8024ac43 142 <para>Whenever the hostname or other metadata is changed via the daemon,
e09a36bd 143 <function>PropertyChanged</function> signals are sent out to subscribed clients. Changing a hostname
98ab0dae
ZJS
144 using this interface is authenticated via
145 <ulink url="https://www.freedesktop.org/software/polkit/docs/latest/">polkit</ulink>.</para>
e09a36bd
ZJS
146 </refsect1>
147
148 <refsect1>
149 <title>Semantics</title>
150
8024ac43 151 <para>The <emphasis>static (configured) hostname</emphasis> is the one configured in
e09a36bd
ZJS
152 <filename>/etc/hostname</filename>. It is chosen by the local user. It is not always in sync with the
153 current hostname as returned by the
4fb222c4 154 <citerefentry project="man-pages"><refentrytitle>gethostname</refentrytitle><manvolnum>3</manvolnum></citerefentry>
8024ac43
ZJS
155 system call. If no hostname is configured this property will be the empty string. Setting this property
156 to the empty string will remove <filename>/etc/hostname</filename>. This property should be an
e09a36bd
ZJS
157 internet-style hostname, 7-bit lowercase ASCII, no special chars/spaces.</para>
158
8024ac43 159 <para>The <emphasis>transient (dynamic) hostname</emphasis> is the one configured via the kernel's
4fb222c4 160 <citerefentry project="man-pages"><refentrytitle>sethostname</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
8024ac43 161 It can be different from the static hostname if DHCP or mDNS have been configured to change the name
e09a36bd
ZJS
162 based on network information. <!-- FIXME: it's not DHCP that configures this... -->
163 This property is never empty. If no hostname is set this will default to
164 <literal>&FALLBACK_HOSTNAME;</literal> (configurable at compilation time). Setting this property to the
8024ac43
ZJS
165 empty string will reset the dynamic hostname to the static hostname. If no static hostname is
166 configured the dynamic hostname will be reset to <literal>&FALLBACK_HOSTNAME;</literal>. This property
e09a36bd
ZJS
167 should be an internet-style hostname, 7-bit lowercase ASCII, no special chars/spaces.</para>
168
8024ac43 169 <para>The <emphasis>pretty hostname</emphasis> is a free-form UTF-8 hostname for presentation to the
e09a36bd
ZJS
170 user. User interfaces should ensure that the pretty hostname and the static hostname stay in sync.
171 I.e. when the former is <literal>Lennart’s Computer</literal> the latter should be
8024ac43 172 <literal>lennarts-computer</literal>. If no pretty hostname is set this setting will be the empty
e09a36bd
ZJS
173 string. Applications should then find a suitable fallback, such as the dynamic hostname.</para>
174
175 <para>The <emphasis>icon name</emphasis> is a name following the XDG icon naming spec. If not set,
176 information such as the chassis type (see below) is used to find a suitable fallback icon name
177 (i.e. <literal>computer-laptop</literal> vs. <literal>computer-desktop</literal> is picked based on the
8024ac43 178 chassis information). If no such data is available, the empty string is returned. In that case an application
e09a36bd 179 should fall back to a replacement icon, for example <literal>computer</literal>. If this property is set
8024ac43 180 to the empty string, the automatic fallback name selection is enabled again.</para>
e09a36bd 181
8024ac43 182 <para>The <emphasis>chassis type</emphasis> should be one of the currently defined chassis types:
e09a36bd
ZJS
183 <literal>desktop</literal>, <literal>laptop</literal>, <literal>server</literal>,
184 <literal>tablet</literal>, <literal>handset</literal>, as well as the special chassis types
185 <literal>vm</literal> and <literal>container</literal> for virtualized systems. Note that in most cases
186 the chassis type will be determined automatically from DMI/SMBIOS/ACPI firmware information. Writing to
8024ac43
ZJS
187 this setting is hence useful only to override misdetected chassis types, or to configure the chassis type if
188 it could not be auto-detected. Set this property to the empty string to reenable the automatic detection of
e09a36bd
ZJS
189 the chassis type from firmware information.</para>
190
e09a36bd
ZJS
191 <para>Note that <filename>systemd-hostnamed</filename> starts only on request and terminates after a
192 short idle period. This effectively means that <function>PropertyChanged</function> messages are not sent
193 out for changes made directly on the files (as in: administrator edits the files with vi). This is
8024ac43 194 the intended behavior: manual configuration changes should require manual reloading.</para>
e09a36bd 195
8024ac43
ZJS
196 <para>The transient (dynamic) hostname maps directly to the kernel hostname. This hostname should be
197 assumed to be highly dynamic, and hence should be watched directly, without depending on
198 <function>PropertyChanged</function> messages from <filename>systemd-hostnamed</filename>. To accomplish
199 this, open <filename>/proc/sys/kernel/hostname</filename> and
4fb222c4 200 <citerefentry project="man-pages"><refentrytitle>poll</refentrytitle><manvolnum>3</manvolnum></citerefentry>
e09a36bd
ZJS
201 for <constant>SIGHUP</constant> which is triggered by the kernel every time the hostname changes. Again:
202 this is special for the transient (dynamic) hostname, and does not apply to the configured (fixed)
203 hostname.</para>
204
8024ac43 205 <para>Applications may read the hostname data directly if hostname change notifications
e09a36bd 206 are not necessary. Use
4fb222c4 207 <citerefentry project="man-pages"><refentrytitle>gethostname</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
e09a36bd
ZJS
208 <filename>/etc/hostname</filename> (possibly with per-distribution fallbacks), and
209 <citerefentry><refentrytitle>machine-info</refentrytitle><manvolnum>3</manvolnum></citerefentry>
210 for that. For more information on these files and syscalls see the respective man pages.</para>
211
5d2262d7
ZJS
212 <refsect2>
213 <title>Methods and Properties</title>
214
215 <para><function>SetHostname()</function> sets the transient (dynamic) hostname which is exposed by the
216 <varname>Hostname</varname> property. If empty, the transient hostname is set to the static hostname.
217 </para>
218
219 <para><function>SetStaticHostname()</function> sets the static hostname which is exposed by the
220 <varname>StaticHostname</varname> property. If empty, the built-in default of
221 <literal>&FALLBACK_HOSTNAME;</literal> is used.</para>
222
223 <para><function>SetPrettyHostname()</function> sets the pretty hostname which is exposed by the
224 <varname>PrettyHostname</varname> property.</para>
225
226 <para><function>SetIconName()</function>, <function>SetChassis()</function>,
227 <function>SetDeployment()</function>, and <function>SetLocation()</function> set the properties
228 <varname>IconName</varname> (the name of the icon representing for the machine),
229 <varname>Chassis</varname> (the machine form factor), <varname>Deployment</varname> (the system
230 deployment environment), and <varname>Location</varname> (physical system location), respectively.
231 </para>
232
233 <para><varname>PrettyHostname</varname>, <varname>IconName</varname>, <varname>Chassis</varname>,
234 <varname>Deployment</varname>, and <varname>Location</varname> are stored in
235 <filename>/etc/machine-info</filename>. See
236 <citerefentry><refentrytitle>machine-info</refentrytitle><manvolnum>5</manvolnum></citerefentry> for
237 the semantics of those settings.</para>
238
239 <para><function>GetProductUUID()</function> returns the "product uuid" as exposed by the kernel based
240 on DMI information in <filename>/sys/class/dmi/id/product_uuid</filename>. Reading the file directly
98ab0dae 241 requires root privileges, and this method allows access to unprivileged clients through the polkit
5d2262d7
ZJS
242 framework.</para>
243
244 <para><varname>KernelName</varname>, <varname>KernelRelease</varname>, and
245 <varname>KernelVersion</varname> expose the kernel name (e.g. <literal>Linux</literal>), release
246 (e.g. <literal>5.0.0-11</literal>, and version (i.e. the build number, e.g. <literal>#11</literal>) as
247 reported by
248 <citerefentry project="man-pages"><refentrytitle>uname</refentrytitle><manvolnum>2</manvolnum></citerefentry>.
249 <varname>OperatingSystemPrettyName</varname>, <varname>OperatingSystemCPEName</varname>, and
250 <varname>HomeURL</varname> expose the <varname>PRETTY_NAME=</varname>, <varname>CPE_NAME=</varname> and
251 <varname>HOME_URL=</varname> fields from
252 <citerefentry><refentrytitle>os-release</refentrytitle><manvolnum>5</manvolnum></citerefentry>. The
253 purpose of those properties is to allow remote clients to access this information over D-Bus. Local
254 clients can access the information directly.</para>
255 </refsect2>
256
debf2ddd
ZJS
257 <refsect2>
258 <title>Security</title>
259
98ab0dae 260 <para>The <varname>interactive</varname> boolean parameters can be used to control whether polkit
debf2ddd
ZJS
261 should interactively ask the user for authentication credentials if required.</para>
262
98ab0dae 263 <para>The polkit action for <function>SetHostname()</function> is
debf2ddd
ZJS
264 <interfacename>org.freedesktop.hostname1.set-hostname</interfacename>. For
265 <function>SetStaticHostname()</function> and <function>SetPrettyHostname()</function> it is
266 <interfacename>org.freedesktop.hostname1.set-static-hostname</interfacename>. For
267 <function>SetIconName()</function> and <function>SetChassis()</function> it is
268 <interfacename>org.freedesktop.hostname1.set-machine-info</interfacename>.</para>
269 </refsect2>
270 </refsect1>
e09a36bd 271
debf2ddd
ZJS
272 <refsect1>
273 <title>Recommendations</title>
e09a36bd 274
debf2ddd 275 <para>Here are three examples that show how the pretty hostname and the icon name should be used:
e09a36bd 276 <itemizedlist>
debf2ddd
ZJS
277 <listitem><para>When registering DNS-SD services: use the pretty hostname in the service name, and pass
278 the icon name in the TXT data, if there is an icon name. Browsing clients can then show the server icon
279 on each service. This is especially useful for WebDAV applications or UPnP media sharing.
8024ac43 280 </para></listitem>
e09a36bd 281
8024ac43 282 <listitem><para>Set the bluetooth name to the pretty hostname.</para></listitem>
e09a36bd 283
debf2ddd
ZJS
284 <listitem><para>When your file browser has a "Computer" icon, replace the name with the pretty hostname
285 if set, and the icon with the icon name, if it is set.</para></listitem>
e09a36bd
ZJS
286 </itemizedlist></para>
287
288 <para>To properly handle name lookups with changing local hostnames without having to edit
debf2ddd
ZJS
289 <filename>/etc/hosts</filename>, we recommend using <filename>systemd-hostnamed</filename> in combination
290 with <citerefentry><refentrytitle>nss-myhostname</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
e09a36bd
ZJS
291 </para>
292
debf2ddd
ZJS
293 <para>A client that wants to change the local hostname for DHCP/mDNS should invoke
294 <code>SetHostname("newname", false)</code> as soon as the name is available and afterwards reset it via
295 <code>SetHostname("")</code>.</para>
296
e09a36bd
ZJS
297 <para>Here are some recommendations to follow when generating a static (internet) hostname from a pretty
298 name:
299 <itemizedlist>
300 <listitem><para>Generate a single DNS label only, not an FQDN. That means no dots allowed. Strip them,
8024ac43 301 or replace them with <literal>-</literal>.</para></listitem>
e09a36bd 302
8024ac43 303 <listitem><para>It's probably safer to not use any non-ASCII chars, even if DNS allows this in some way
e09a36bd
ZJS
304 these days. In fact, restrict your charset to <literal>a-zA-Z0-9</literal> and <literal>-</literal>.
305 Strip other chars, or try to replace them in some smart way with chars from this set, for example
8024ac43
ZJS
306 <literal>ä</literal> → <literal>ae</literal>, and use <literal>-</literal> as the replacement for all
307 punctuation characters and whitespace.</para></listitem>
e09a36bd
ZJS
308
309 <listitem><para>Try to avoid creating repeated <literal>-</literal>, as well as <literal>-</literal> as
310 the first or last char.</para></listitem>
311
312 <listitem><para>Limit the hostname to 63 chars, which is the length of a DNS label.</para></listitem>
313
314 <listitem><para>If after stripping special chars the empty string is the result, you can pass this
8024ac43
ZJS
315 as-is to <filename>systemd-hostnamed</filename> in which case it will automatically use
316 <literal>&FALLBACK_HOSTNAME;</literal>.</para></listitem>
e09a36bd 317
8024ac43
ZJS
318 <listitem><para>Uppercase charaacters should be replaced with their lowercase equivalents.
319 </para></listitem>
e09a36bd
ZJS
320 </itemizedlist></para>
321
322 <para>Note that while <filename>systemd-hostnamed</filename> applies some checks to the hostname you pass
323 they are much looser than the recommendations above. For example, <filename>systemd-hostnamed</filename>
8024ac43 324 will also accept <literal>_</literal> in the hostname, but we recommend not using this to avoid clashes
e09a36bd 325 with DNS-SD service types. Also <filename>systemd-hostnamed</filename> allows longer hostnames, but
8024ac43 326 because of the DNS label limitations, we recommend not making use of this.</para>
e09a36bd
ZJS
327
328 <para>Here are a couple of example conversions:
329 <itemizedlist>
330 <listitem><para><literal>Lennart's PC</literal> → <literal>lennarts-pc</literal></para></listitem>
331 <listitem><para><literal>Müllers Computer</literal> → <literal>muellers-computer</literal></para></listitem>
332 <listitem><para><literal>Voran!</literal> → <literal>voran</literal></para></listitem>
333 <listitem><para><literal>Es war einmal ein Männlein</literal> → <literal>es-war-einmal-ein-maennlein</literal></para></listitem>
334 <listitem><para><literal>Jawoll. Ist doch wahr!</literal> → <literal>jawoll-ist-doch-wahr</literal></para></listitem>
335 <listitem><para><literal>レナート</literal> → <literal>localhost</literal></para></listitem>
336 <listitem><para><literal>...zack!!! zack!...</literal> → <literal>zack-zack</literal></para></listitem>
337 </itemizedlist></para>
338
8024ac43 339 <para>Of course, an already valid internet hostname label you enter and pass through this
debf2ddd 340 conversion should stay unmodified, so that users have direct control of it, if they want — by simply
e09a36bd
ZJS
341 ignoring the fact that the pretty hostname is pretty and just edit it as if it was the normal internet
342 name.</para>
343 </refsect1>
344
345 <refsect1>
346 <title>Versioning</title>
347
348 <para>These D-Bus interfaces follow <ulink url="http://0pointer.de/blog/projects/versioning-dbus.html">
349 the usual interface versioning guidelines</ulink>.</para>
350 </refsect1>
351
352 <refsect1>
353 <title>See also</title>
354
355 <para>David Zeuthen's original Fedora
356 <ulink url="https://fedoraproject.org/wiki/Features/BetterHostname">Feature page about xdg-hostname</ulink></para>
357 </refsect1>
358</refentry>