Debian Codegraph @

man/org.freedesktop.hostname1.xml

raw
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.5/docbookx.dtd" [
5 <!ENTITY % entities SYSTEM "custom-entities.ent" >
6 %entities;
7 ]>
8 <!-- SPDX-License-Identifier: LGPL-2.1-or-later -->
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>
32 is a system service that can be used to control the hostname and related machine metadata from user
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 executable="systemd-hostnamed" node="/org/freedesktop/hostname1" interface="org.freedesktop.hostname1">
42 node /org/freedesktop/hostname1 {
43 interface org.freedesktop.hostname1 {
44 methods:
45 SetHostname(in s hostname,
46 in b interactive);
47 SetStaticHostname(in s hostname,
48 in b interactive);
49 SetPrettyHostname(in s hostname,
50 in b interactive);
51 SetIconName(in s icon,
52 in b interactive);
53 SetChassis(in s chassis,
54 in b interactive);
55 SetDeployment(in s deployment,
56 in b interactive);
57 SetLocation(in s location,
58 in b interactive);
59 SetTags(in as tags);
60 GetProductUUID(in b interactive,
61 out ay uuid);
62 GetHardwareSerial(out s serial);
63 Describe(out s json);
64 GetMachineInfo(in s field,
65 out s value);
66 properties:
67 readonly s Hostname = '...';
68 readonly s StaticHostname = '...';
69 readonly s PrettyHostname = '...';
70 @org.freedesktop.DBus.Property.EmitsChangedSignal("const")
71 readonly s DefaultHostname = '...';
72 readonly s HostnameSource = '...';
73 readonly s IconName = '...';
74 readonly s Chassis = '...';
75 readonly s Deployment = '...';
76 readonly s Location = '...';
77 readonly as Tags = ['...', ...];
78 @org.freedesktop.DBus.Property.EmitsChangedSignal("const")
79 readonly s KernelName = '...';
80 @org.freedesktop.DBus.Property.EmitsChangedSignal("const")
81 readonly s KernelRelease = '...';
82 @org.freedesktop.DBus.Property.EmitsChangedSignal("const")
83 readonly s KernelVersion = '...';
84 @org.freedesktop.DBus.Property.EmitsChangedSignal("const")
85 readonly s OperatingSystemPrettyName = '...';
86 @org.freedesktop.DBus.Property.EmitsChangedSignal("const")
87 readonly s OperatingSystemFancyName = '...';
88 @org.freedesktop.DBus.Property.EmitsChangedSignal("const")
89 readonly s OperatingSystemCPEName = '...';
90 @org.freedesktop.DBus.Property.EmitsChangedSignal("const")
91 readonly t OperatingSystemSupportEnd = ...;
92 @org.freedesktop.DBus.Property.EmitsChangedSignal("const")
93 readonly s HomeURL = '...';
94 @org.freedesktop.DBus.Property.EmitsChangedSignal("const")
95 readonly s OperatingSystemImageID = '...';
96 @org.freedesktop.DBus.Property.EmitsChangedSignal("const")
97 readonly s OperatingSystemImageVersion = '...';
98 @org.freedesktop.DBus.Property.EmitsChangedSignal("const")
99 readonly s HardwareVendor = '...';
100 @org.freedesktop.DBus.Property.EmitsChangedSignal("const")
101 readonly s HardwareModel = '...';
102 @org.freedesktop.DBus.Property.EmitsChangedSignal("const")
103 readonly s HardwareSKU = '...';
104 @org.freedesktop.DBus.Property.EmitsChangedSignal("const")
105 readonly s HardwareVersion = '...';
106 @org.freedesktop.DBus.Property.EmitsChangedSignal("const")
107 readonly s FirmwareVersion = '...';
108 @org.freedesktop.DBus.Property.EmitsChangedSignal("const")
109 readonly s FirmwareVendor = '...';
110 @org.freedesktop.DBus.Property.EmitsChangedSignal("const")
111 readonly t FirmwareDate = ...;
112 @org.freedesktop.DBus.Property.EmitsChangedSignal("const")
113 readonly ay MachineID = [...];
114 @org.freedesktop.DBus.Property.EmitsChangedSignal("const")
115 readonly ay BootID = [...];
116 @org.freedesktop.DBus.Property.EmitsChangedSignal("const")
117 readonly u VSockCID = ...;
118 @org.freedesktop.DBus.Property.EmitsChangedSignal("const")
119 readonly s ChassisAssetTag = '...';
120 };
121 interface org.freedesktop.DBus.Peer { ... };
122 interface org.freedesktop.DBus.Introspectable { ... };
123 interface org.freedesktop.DBus.Properties { ... };
124 };
125 </programlisting>
126
127 <!--Autogenerated cross-references for systemd.directives, do not edit-->
128
129 <variablelist class="dbus-interface" generated="True" extra-ref="org.freedesktop.hostname1"/>
130
131 <variablelist class="dbus-interface" generated="True" extra-ref="org.freedesktop.hostname1"/>
132
133 <variablelist class="dbus-method" generated="True" extra-ref="SetHostname()"/>
134
135 <variablelist class="dbus-method" generated="True" extra-ref="SetStaticHostname()"/>
136
137 <variablelist class="dbus-method" generated="True" extra-ref="SetPrettyHostname()"/>
138
139 <variablelist class="dbus-method" generated="True" extra-ref="SetIconName()"/>
140
141 <variablelist class="dbus-method" generated="True" extra-ref="SetChassis()"/>
142
143 <variablelist class="dbus-method" generated="True" extra-ref="SetDeployment()"/>
144
145 <variablelist class="dbus-method" generated="True" extra-ref="SetLocation()"/>
146
147 <variablelist class="dbus-method" generated="True" extra-ref="SetTags()"/>
148
149 <variablelist class="dbus-method" generated="True" extra-ref="GetProductUUID()"/>
150
151 <variablelist class="dbus-method" generated="True" extra-ref="GetHardwareSerial()"/>
152
153 <variablelist class="dbus-method" generated="True" extra-ref="Describe()"/>
154
155 <variablelist class="dbus-method" generated="True" extra-ref="GetMachineInfo()"/>
156
157 <variablelist class="dbus-property" generated="True" extra-ref="Hostname"/>
158
159 <variablelist class="dbus-property" generated="True" extra-ref="StaticHostname"/>
160
161 <variablelist class="dbus-property" generated="True" extra-ref="PrettyHostname"/>
162
163 <variablelist class="dbus-property" generated="True" extra-ref="DefaultHostname"/>
164
165 <variablelist class="dbus-property" generated="True" extra-ref="HostnameSource"/>
166
167 <variablelist class="dbus-property" generated="True" extra-ref="IconName"/>
168
169 <variablelist class="dbus-property" generated="True" extra-ref="Chassis"/>
170
171 <variablelist class="dbus-property" generated="True" extra-ref="Deployment"/>
172
173 <variablelist class="dbus-property" generated="True" extra-ref="Location"/>
174
175 <variablelist class="dbus-property" generated="True" extra-ref="Tags"/>
176
177 <variablelist class="dbus-property" generated="True" extra-ref="KernelName"/>
178
179 <variablelist class="dbus-property" generated="True" extra-ref="KernelRelease"/>
180
181 <variablelist class="dbus-property" generated="True" extra-ref="KernelVersion"/>
182
183 <variablelist class="dbus-property" generated="True" extra-ref="OperatingSystemPrettyName"/>
184
185 <variablelist class="dbus-property" generated="True" extra-ref="OperatingSystemFancyName"/>
186
187 <variablelist class="dbus-property" generated="True" extra-ref="OperatingSystemCPEName"/>
188
189 <variablelist class="dbus-property" generated="True" extra-ref="OperatingSystemSupportEnd"/>
190
191 <variablelist class="dbus-property" generated="True" extra-ref="HomeURL"/>
192
193 <variablelist class="dbus-property" generated="True" extra-ref="OperatingSystemImageID"/>
194
195 <variablelist class="dbus-property" generated="True" extra-ref="OperatingSystemImageVersion"/>
196
197 <variablelist class="dbus-property" generated="True" extra-ref="HardwareVendor"/>
198
199 <variablelist class="dbus-property" generated="True" extra-ref="HardwareModel"/>
200
201 <variablelist class="dbus-property" generated="True" extra-ref="HardwareSKU"/>
202
203 <variablelist class="dbus-property" generated="True" extra-ref="HardwareVersion"/>
204
205 <variablelist class="dbus-property" generated="True" extra-ref="FirmwareVersion"/>
206
207 <variablelist class="dbus-property" generated="True" extra-ref="FirmwareVendor"/>
208
209 <variablelist class="dbus-property" generated="True" extra-ref="FirmwareDate"/>
210
211 <variablelist class="dbus-property" generated="True" extra-ref="MachineID"/>
212
213 <variablelist class="dbus-property" generated="True" extra-ref="BootID"/>
214
215 <variablelist class="dbus-property" generated="True" extra-ref="VSockCID"/>
216
217 <variablelist class="dbus-property" generated="True" extra-ref="ChassisAssetTag"/>
218
219 <!--End of Autogenerated section-->
220
221 <para>Whenever the hostname or other metadata is changed via the daemon,
222 <function>PropertyChanged</function> signals are sent out to subscribed clients. Changing a hostname
223 using this interface is authenticated via
224 <ulink url="https://www.freedesktop.org/software/polkit/docs/latest/">polkit</ulink>.</para>
225 </refsect1>
226
227 <refsect1>
228 <title>Semantics</title>
229
230 <para>The <varname>StaticHostname</varname> property exposes the "static" hostname configured in
231 <filename>/etc/hostname</filename>. It is not always in sync with the current hostname as returned by the
232 <citerefentry project="man-pages"><refentrytitle>gethostname</refentrytitle><manvolnum>3</manvolnum></citerefentry>
233 system call. If no static hostname is configured this property will be the empty string.</para>
234
235 <para>When <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry> or
236 <citerefentry><refentrytitle>systemd-hostnamed.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>
237 set the hostname, this static hostname <emphasis>has the highest priority</emphasis>.</para>
238
239 <para>The <varname>Hostname</varname> property exposes the actual hostname configured in the kernel via
240 <citerefentry project="man-pages"><refentrytitle>sethostname</refentrytitle><manvolnum>2</manvolnum></citerefentry>.
241 It can be different from the static hostname. This property is never empty.</para>
242
243 <para>The <varname>PrettyHostname</varname> property exposes the <emphasis>pretty hostname</emphasis>
244 which is a free-form UTF-8 hostname for presentation to the user. User interfaces should ensure that the
245 pretty hostname and the static hostname stay in sync. E.g. when the former is <literal>Lennart’s
246 Computer</literal> the latter should be <literal>lennarts-computer</literal>. If no pretty hostname is
247 set this setting will be the empty string. Applications should then find a suitable fallback, such as the
248 dynamic hostname.</para>
249
250 <para>The <varname>DefaultHostname</varname> property exposes the default hostname (configured through
251 <citerefentry><refentrytitle>os-release</refentrytitle><manvolnum>5</manvolnum></citerefentry>, or a
252 fallback set at compilation time).</para>
253
254 <para>The <varname>HostnameSource</varname> property exposes the origin of the currently configured
255 hostname. One of <literal>static</literal> (set from <filename>/etc/hostname</filename>),
256 <literal>transient</literal> (a non-permanent hostname from an external source),
257 <literal>default</literal> (the value from <filename>os-release</filename> or the compiled-in
258 fallback).</para>
259
260 <para>The <varname>IconName</varname> property exposes the <emphasis>icon name</emphasis> following the
261 XDG icon naming spec. If not set, information such as the chassis type (see below) is used to find a
262 suitable fallback icon name (i.e. <literal>computer-laptop</literal>
263 vs. <literal>computer-desktop</literal> is picked based on the chassis information). If no such data is
264 available, the empty string is returned. In that case an application should fall back to a replacement
265 icon, for example <literal>computer</literal>. If this property is set to the empty string, the automatic
266 fallback name selection is enabled again.</para>
267
268 <para>The <varname>Chassis</varname> property exposes a <emphasis>chassis type</emphasis>, one of the
269 currently defined chassis types: <literal>desktop</literal>, <literal>laptop</literal>,
270 <literal>server</literal>, <literal>tablet</literal>, <literal>handset</literal>, as well as the special
271 chassis types <literal>vm</literal> and <literal>container</literal> for virtualized systems. Note that
272 in most cases the chassis type will be determined automatically from DMI/SMBIOS/ACPI firmware
273 information. Writing to this setting is hence useful only to override misdetected chassis types, or to
274 configure the chassis type if it could not be auto-detected. Set this property to the empty string to
275 reenable the automatic detection of the chassis type from firmware information.</para>
276
277 <para>The <varname>Tags</varname> property exposes a list of <emphasis>machine tags</emphasis>: short
278 labels that may be used to classify and group machines for management purposes, for example to identify
279 the role a machine plays in a deployment, the fleet or organizational unit it belongs to, or any other
280 administrator-defined attribute. Each individual tag is 1…255 characters long and consists only of the
281 ASCII alphanumeric characters, <literal>-</literal> and <literal>.</literal>. The tags are stored as a
282 colon-separated list in the <varname>TAGS=</varname> field of <filename>/etc/machine-info</filename>, see
283 <citerefentry><refentrytitle>machine-info</refentrytitle><manvolnum>5</manvolnum></citerefentry> for
284 details. If no tags are configured this property is the empty list.</para>
285
286 <para>Note that <filename>systemd-hostnamed</filename> starts only on request and terminates after a
287 short idle period. This effectively means that <function>PropertyChanged</function> messages are not sent
288 out for changes made directly on the files (as in: administrator edits the files with vi). This is
289 the intended behavior: manual configuration changes should require manual reloading.</para>
290
291 <para>The transient (dynamic) hostname exposed by the <varname>Hostname</varname> property maps directly
292 to the kernel hostname. This hostname should be assumed to be highly dynamic, and hence should be watched
293 directly, without depending on <function>PropertyChanged</function> messages from
294 <filename>systemd-hostnamed</filename>. To accomplish this, open
295 <filename>/proc/sys/kernel/hostname</filename> and
296 <citerefentry project="man-pages"><refentrytitle>poll</refentrytitle><manvolnum>3</manvolnum></citerefentry>
297 for <constant>SIGHUP</constant> which is triggered by the kernel every time the hostname changes. Again:
298 this is special for the transient (dynamic) hostname, and does not apply to the configured (fixed)
299 hostname.</para>
300
301 <para>Applications may read the hostname data directly if hostname change notifications
302 are not necessary. Use
303 <citerefentry project="man-pages"><refentrytitle>gethostname</refentrytitle><manvolnum>2</manvolnum></citerefentry>,
304 <filename>/etc/hostname</filename> (possibly with per-distribution fallbacks), and
305 <citerefentry><refentrytitle>machine-info</refentrytitle><manvolnum>5</manvolnum></citerefentry>
306 for that. For more information on these files and syscalls see the respective man pages.</para>
307
308 <para><varname>KernelName</varname>, <varname>KernelRelease</varname>, and
309 <varname>KernelVersion</varname> expose the kernel name (e.g. <literal>Linux</literal>), release
310 (e.g. <literal>5.0.0-11</literal>), and version (i.e. the build number, e.g. <literal>#11</literal>) as
311 reported by <citerefentry project="man-pages"><refentrytitle>uname</refentrytitle><manvolnum>2</manvolnum></citerefentry>.</para>
312
313 <para><varname>OperatingSystemPrettyName</varname>, <varname>OperatingSystemFancyName</varname>,
314 <varname>OperatingSystemCPEName</varname>, and <varname>HomeURL</varname> expose the
315 <varname>PRETTY_NAME=</varname>, <varname>FANCY_NAME=</varname>, <varname>CPE_NAME=</varname> and
316 <varname>HOME_URL=</varname> fields from
317 <citerefentry><refentrytitle>os-release</refentrytitle><manvolnum>5</manvolnum></citerefentry>. The
318 purpose of those properties is to allow remote clients to access this information over D-Bus. Local
319 clients can access the information directly.</para>
320
321 <para><varname>MachineID</varname> expose the 128bit machine ID, see
322 <citerefentry><refentrytitle>machine-id</refentrytitle><manvolnum>5</manvolnum></citerefentry> for
323 details.</para>
324
325 <para><varname>BootID</varname> expose the 128bit boot ID, as per
326 <filename>/proc/sys/kernel/random/boot_id</filename>.</para>
327
328 <para><varname>VSockCID</varname> exposes the system's local <constant>AF_VSOCK</constant> CID (Context
329 Identifier, i.e. address) for the system, if one is available in the virtual machine environment. Set to
330 <constant>UINT32_MAX</constant> otherwise. See <citerefentry project="man-pages"><refentrytitle>vsock</refentrytitle><manvolnum>7</manvolnum></citerefentry> for
331 details.</para>
332
333 <para><varname>OperatingSystemSupportEnd</varname> exposes when the OS' vendor support ends, if this
334 information is known. It's an unsigned 64bit value, in µs since the UNIX epoch, UTC. If this information
335 is not known carries the value 2^64-1, i.e. <constant>UINT64_MAX</constant>.</para>
336
337 <para><varname>OperatingSystemImageID</varname> and <varname>OperatingSystemImageVersion</varname> expose
338 the OS image name and version if available, or contain empty strings otherwise. This mostly corresponds
339 to the <varname>IMAGE_ID=</varname> and <varname>IMAGE_VERSION=</varname> fields of the
340 <filename>os-release</filename> file.</para>
341
342 <para><varname>HardwareVendor</varname>, <varname>HardwareModel</varname>, <varname>HardwareSKU</varname>,
343 and <varname>HardwareVersion</varname> expose vendor information about the hardware of the system. The
344 stock keeping unit (SKU) describes a distinct type of hardware for sale, purchase or inventory management.
345 The SKU and version are only available if they deviate from the model and among each other. Thereby the
346 version is more specific and only available if it differs from the model and SKU. If no such information
347 can be determined these properties are set to empty strings.</para>
348
349 <para><varname>FirmwareVersion</varname> and <varname>FirmwareVendor</varname> expose information about
350 the system's firmware, i.e. a version string and a vendor name. If no such information can be determined
351 these properties are set to empty strings.</para>
352
353 <para><varname>FirmwareDate</varname> exposes the firmware build date, if that information is known. It's
354 an unsigned 64bit value, in µs since the UNIX epoch, UTC. If not known
355 <constant>UNIT64_MAX</constant>.</para>
356
357 <para><varname>ChassisAssetTag</varname> exposes an unique identifier of the system chassis. If this
358 information is not known this property is set to an empty string.</para>
359
360 <refsect2>
361 <title>Methods</title>
362
363 <para><function>SetHostname()</function> sets the transient (dynamic) hostname, which is used if no
364 static hostname is set. This value must be an internet-style hostname, 7-bit lowercase ASCII, no
365 special chars/spaces. An empty string will unset the transient hostname.</para>
366
367 <para><function>SetStaticHostname()</function> sets the static hostname which is exposed by the
368 <varname>StaticHostname</varname> property. When called with an empty argument, the static
369 configuration in <filename>/etc/hostname</filename> is removed. Since the static hostname has the
370 highest priority, calling this function usually affects also the <varname>Hostname</varname> property
371 and the effective hostname configured in the kernel.</para>
372
373 <para><function>SetPrettyHostname()</function> sets the pretty hostname which is exposed by the
374 <varname>PrettyHostname</varname> property.</para>
375
376 <para><function>SetIconName()</function>, <function>SetChassis()</function>,
377 <function>SetDeployment()</function>, and <function>SetLocation()</function> set the properties
378 <varname>IconName</varname> (the name of the icon representing for the machine),
379 <varname>Chassis</varname> (the machine form factor), <varname>Deployment</varname> (the system
380 deployment environment), and <varname>Location</varname> (physical system location), respectively.
381 </para>
382
383 <para><function>SetTags()</function> sets the machine tags exposed by the <varname>Tags</varname>
384 property. It takes a list of strings, each of which must be a valid machine tag (1…255 ASCII
385 alphanumeric characters, <literal>-</literal> and <literal>.</literal>). Passing an empty list removes
386 the <varname>TAGS=</varname> field from <filename>/etc/machine-info</filename>.</para>
387
388 <para><varname>PrettyHostname</varname>, <varname>IconName</varname>, <varname>Chassis</varname>,
389 <varname>Deployment</varname>, <varname>Location</varname>, and <varname>Tags</varname> are stored in
390 <filename>/etc/machine-info</filename>. See
391 <citerefentry><refentrytitle>machine-info</refentrytitle><manvolnum>5</manvolnum></citerefentry> for
392 the semantics of those settings.</para>
393
394 <para><function>GetProductUUID()</function> returns the "product UUID" as exposed by the kernel based
395 on DMI information in <filename>/sys/class/dmi/id/product_uuid</filename>. Reading the file directly
396 requires root privileges, and this method allows access to unprivileged clients through the polkit
397 framework.</para>
398
399 <para><function>GetHardwareSerial()</function> returns the "hardware serial" as exposed by the kernel
400 based on DMI information. Reading the file directly requires root privileges, and this method allows
401 access to unprivileged clients through the polkit framework.</para>
402
403 <para><function>Describe()</function> returns a JSON representation of all properties in one.</para>
404
405 <para><function>GetMachineInfo()</function> returns the value of the given field from
406 <filename>/etc/machine-info</filename>. For well-known fields, this method reads values from the same
407 internal cache used by the corresponding D-Bus property getters, but returns only the raw
408 <filename>/etc/machine-info</filename> values (i.e. without property-level fallback logic such as
409 DMI/chassis-based detection). Custom (non-standard) fields are read directly from the file.
410 An error is returned if the field name is empty, invalid, or not set in the file.</para>
411 </refsect2>
412
413 <refsect2>
414 <title>Security</title>
415
416 <para>The <varname>interactive</varname> boolean parameters can be used to control whether polkit
417 should interactively ask the user for authentication credentials if required.</para>
418
419 <para>The polkit action for <function>SetHostname()</function> is
420 <interfacename>org.freedesktop.hostname1.set-hostname</interfacename>. For
421 <function>SetStaticHostname()</function> and <function>SetPrettyHostname()</function> it is
422 <interfacename>org.freedesktop.hostname1.set-static-hostname</interfacename>. For
423 <function>SetIconName()</function>, <function>SetChassis()</function>, <function>SetDeployment()</function>,
424 <function>SetLocation()</function> and <function>SetTags()</function> it is
425 <interfacename>org.freedesktop.hostname1.set-machine-info</interfacename>.</para>
426 </refsect2>
427 </refsect1>
428
429 <refsect1>
430 <title>Recommendations</title>
431
432 <para>Here are three examples that show how the pretty hostname and the icon name should be used:
433 <itemizedlist>
434 <listitem><para>When registering DNS-SD services: use the pretty hostname in the service name, and pass
435 the icon name in the TXT data, if there is an icon name. Browsing clients can then show the server icon
436 on each service. This is especially useful for WebDAV applications or UPnP media sharing.
437 </para></listitem>
438
439 <listitem><para>Set the bluetooth name to the pretty hostname.</para></listitem>
440
441 <listitem><para>When your file browser has a "Computer" icon, replace the name with the pretty hostname
442 if set, and the icon with the icon name, if it is set.</para></listitem>
443 </itemizedlist></para>
444
445 <para>To properly handle name lookups with changing local hostnames without having to edit
446 <filename>/etc/hosts</filename>, we recommend using <filename>systemd-hostnamed</filename> in combination
447 with <citerefentry><refentrytitle>nss-myhostname</refentrytitle><manvolnum>8</manvolnum></citerefentry>.
448 </para>
449
450 <para>Here are some recommendations to follow when generating a static (internet) hostname from a pretty
451 name:
452 <itemizedlist>
453 <listitem><para>Generate a single DNS label only, not an FQDN. That means no dots allowed. Strip them,
454 or replace them with <literal>-</literal>.</para></listitem>
455
456 <listitem><para>It's probably safer to not use any non-ASCII chars, even if DNS allows this in some way
457 these days. In fact, restrict your charset to <literal>a-zA-Z0-9</literal> and <literal>-</literal>.
458 Strip other chars, or try to replace them in some smart way with chars from this set, for example
459 <literal>ä</literal> → <literal>ae</literal>, and use <literal>-</literal> as the replacement for all
460 punctuation characters and whitespace.</para></listitem>
461
462 <listitem><para>Try to avoid creating repeated <literal>-</literal>, as well as <literal>-</literal> as
463 the first or last char.</para></listitem>
464
465 <listitem><para>Limit the hostname to 63 chars, which is the length of a DNS label.</para></listitem>
466
467 <listitem><para>If after stripping special chars the empty string is the result, you can pass this
468 as-is to <filename>systemd-hostnamed</filename> in which case it will automatically use a suitable
469 fallback.</para></listitem>
470
471 <listitem><para>Uppercase characters should be replaced with their lowercase equivalents.
472 </para></listitem>
473 </itemizedlist></para>
474
475 <para>Note that while <filename>systemd-hostnamed</filename> applies some checks to the hostname you pass
476 they are much looser than the recommendations above. For example, <filename>systemd-hostnamed</filename>
477 will also accept <literal>_</literal> in the hostname, but we recommend not using this to avoid clashes
478 with DNS-SD service types. Also <filename>systemd-hostnamed</filename> allows longer hostnames, but
479 because of the DNS label limitations, we recommend not making use of this.</para>
480
481 <para>Here are a couple of example conversions:
482 <itemizedlist>
483 <listitem><para><literal>Lennart's PC</literal> → <literal>lennarts-pc</literal></para></listitem>
484 <listitem><para><literal>Müllers Computer</literal> → <literal>muellers-computer</literal></para></listitem>
485 <listitem><para><literal>Voran!</literal> → <literal>voran</literal></para></listitem>
486 <listitem><para><literal>Es war einmal ein Männlein</literal> → <literal>es-war-einmal-ein-maennlein</literal></para></listitem>
487 <listitem><para><literal>Jawoll. Ist doch wahr!</literal> → <literal>jawoll-ist-doch-wahr</literal></para></listitem>
488 <listitem><para><literal>レナート</literal> → <literal>localhost</literal></para></listitem>
489 <listitem><para><literal>...zack!!! zack!...</literal> → <literal>zack-zack</literal></para></listitem>
490 </itemizedlist></para>
491
492 <para>Of course, an already valid internet hostname label you enter and pass through this
493 conversion should stay unmodified, so that users have direct control of it, if they want — by simply
494 ignoring the fact that the pretty hostname is pretty and just edit it as if it was the normal internet
495 name.</para>
496 </refsect1>
497
498 <refsect1>
499 <title>Examples</title>
500
501 <example>
502 <title>Introspect <interfacename>org.freedesktop.hostname1</interfacename> on the bus</title>
503
504 <programlisting>$ gdbus introspect --system \
505 --dest org.freedesktop.hostname1 \
506 --object-path /org/freedesktop/hostname1
507 </programlisting>
508 </example>
509 </refsect1>
510
511 <xi:include href="org.freedesktop.locale1.xml" xpointer="versioning"/>
512
513 <refsect1>
514 <title>History</title>
515 <refsect2>
516 <title>The D-Bus API</title>
517 <para><varname>FirmwareVersion</varname> and
518 <function>GetHardwareSerial()</function> were added in version 251.</para>
519 <para><varname>OperatingSystemSupportEnd</varname>,
520 <varname>FirmwareVendor</varname>, and
521 <varname>FirmwareDate</varname> were added in version 253.</para>
522 <para><varname>MachineID</varname>, <varname>BootID</varname> and
523 <varname>VSockCID</varname> were added in version 256.</para>
524 <para><varname>ChassisAssetTag</varname>, <varname>OperatingSystemImageID</varname>,
525 <varname>OperatingSystemImageVersion</varname>, <varname>HardwareSKU</varname>, and
526 <varname>HardwareVersion</varname> were added in version 258.</para>
527 <para><varname>OperatingSystemFancyName</varname> was added in version 260.</para>
528 <para><function>GetMachineInfo()</function>, <varname>Tags</varname> and
529 <function>SetTags()</function> were added in version 261.</para>
530 </refsect2>
531 </refsect1>
532
533 <refsect1>
534 <title>See Also</title>
535
536 <para><simplelist type="inline">
537 <member><citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry></member>
538 <member><citerefentry><refentrytitle>systemd-hostnamed.service</refentrytitle><manvolnum>8</manvolnum></citerefentry></member>
539 <member><citerefentry><refentrytitle>hostnamectl</refentrytitle><manvolnum>1</manvolnum></citerefentry></member>
540 <member>David Zeuthen's original Fedora
541 <ulink url="https://fedoraproject.org/wiki/Features/BetterHostname">Feature page about xdg-hostname</ulink></member>
542 </simplelist></para>
543 </refsect1>
544 </refentry>