]> git.proxmox.com Git - systemd.git/blob - man/org.freedesktop.hostname1.xml
New upstream version 249~rc1
[systemd.git] / man / org.freedesktop.hostname1.xml
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-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 GetProductUUID(in b interactive,
60 out ay uuid);
61 Describe(out s json);
62 properties:
63 readonly s Hostname = '...';
64 readonly s StaticHostname = '...';
65 readonly s PrettyHostname = '...';
66 @org.freedesktop.DBus.Property.EmitsChangedSignal("const")
67 readonly s DefaultHostname = '...';
68 readonly s HostnameSource = '...';
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 = '...';
85 @org.freedesktop.DBus.Property.EmitsChangedSignal("const")
86 readonly s HardwareVendor = '...';
87 @org.freedesktop.DBus.Property.EmitsChangedSignal("const")
88 readonly s HardwareModel = '...';
89 };
90 interface org.freedesktop.DBus.Peer { ... };
91 interface org.freedesktop.DBus.Introspectable { ... };
92 interface org.freedesktop.DBus.Properties { ... };
93 };
94 </programlisting>
95
96 <!--property HardwareVendor is not documented!-->
97
98 <!--property HardwareModel is not documented!-->
99
100 <!--Autogenerated cross-references for systemd.directives, do not edit-->
101
102 <variablelist class="dbus-interface" generated="True" extra-ref="org.freedesktop.hostname1"/>
103
104 <variablelist class="dbus-interface" generated="True" extra-ref="org.freedesktop.hostname1"/>
105
106 <variablelist class="dbus-method" generated="True" extra-ref="SetHostname()"/>
107
108 <variablelist class="dbus-method" generated="True" extra-ref="SetStaticHostname()"/>
109
110 <variablelist class="dbus-method" generated="True" extra-ref="SetPrettyHostname()"/>
111
112 <variablelist class="dbus-method" generated="True" extra-ref="SetIconName()"/>
113
114 <variablelist class="dbus-method" generated="True" extra-ref="SetChassis()"/>
115
116 <variablelist class="dbus-method" generated="True" extra-ref="SetDeployment()"/>
117
118 <variablelist class="dbus-method" generated="True" extra-ref="SetLocation()"/>
119
120 <variablelist class="dbus-method" generated="True" extra-ref="GetProductUUID()"/>
121
122 <variablelist class="dbus-method" generated="True" extra-ref="Describe()"/>
123
124 <variablelist class="dbus-property" generated="True" extra-ref="Hostname"/>
125
126 <variablelist class="dbus-property" generated="True" extra-ref="StaticHostname"/>
127
128 <variablelist class="dbus-property" generated="True" extra-ref="PrettyHostname"/>
129
130 <variablelist class="dbus-property" generated="True" extra-ref="DefaultHostname"/>
131
132 <variablelist class="dbus-property" generated="True" extra-ref="HostnameSource"/>
133
134 <variablelist class="dbus-property" generated="True" extra-ref="IconName"/>
135
136 <variablelist class="dbus-property" generated="True" extra-ref="Chassis"/>
137
138 <variablelist class="dbus-property" generated="True" extra-ref="Deployment"/>
139
140 <variablelist class="dbus-property" generated="True" extra-ref="Location"/>
141
142 <variablelist class="dbus-property" generated="True" extra-ref="KernelName"/>
143
144 <variablelist class="dbus-property" generated="True" extra-ref="KernelRelease"/>
145
146 <variablelist class="dbus-property" generated="True" extra-ref="KernelVersion"/>
147
148 <variablelist class="dbus-property" generated="True" extra-ref="OperatingSystemPrettyName"/>
149
150 <variablelist class="dbus-property" generated="True" extra-ref="OperatingSystemCPEName"/>
151
152 <variablelist class="dbus-property" generated="True" extra-ref="HomeURL"/>
153
154 <variablelist class="dbus-property" generated="True" extra-ref="HardwareVendor"/>
155
156 <variablelist class="dbus-property" generated="True" extra-ref="HardwareModel"/>
157
158 <!--End of Autogenerated section-->
159
160 <para>Whenever the hostname or other metadata is changed via the daemon,
161 <function>PropertyChanged</function> signals are sent out to subscribed clients. Changing a hostname
162 using this interface is authenticated via
163 <ulink url="https://www.freedesktop.org/software/polkit/docs/latest/">polkit</ulink>.</para>
164 </refsect1>
165
166 <refsect1>
167 <title>Semantics</title>
168
169 <para>The <varname>StaticHostname</varname> property exposes the "static" hostname configured in
170 <filename>/etc/hostname</filename>. It is not always in sync with the current hostname as returned by the
171 <citerefentry project="man-pages"><refentrytitle>gethostname</refentrytitle><manvolnum>3</manvolnum></citerefentry>
172 system call. If no static hostname is configured this property will be the empty string.</para>
173
174 <para>When <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry> or
175 <citerefentry><refentrytitle>systemd-hostnamed.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>
176 set the hostname, this static hostname <emphasis>has the highest priority</emphasis>.</para>
177
178 <para>The <varname>Hostname</varname> property exposes the actual hostname configured in the kernel via
179 <citerefentry project="man-pages"><refentrytitle>sethostname</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
180 It can be different from the static hostname. This property is never empty.</para>
181
182 <para>The <varname>PrettyHostname</varname> property exposes the <emphasis>pretty hostname</emphasis>
183 which is a free-form UTF-8 hostname for presentation to the user. User interfaces should ensure that the
184 pretty hostname and the static hostname stay in sync. E.g. when the former is <literal>Lennart’s
185 Computer</literal> the latter should be <literal>lennarts-computer</literal>. If no pretty hostname is
186 set this setting will be the empty string. Applications should then find a suitable fallback, such as the
187 dynamic hostname.</para>
188
189 <para>The <varname>DefaultHostname</varname> property exposes the default hostname (configured through
190 <citerefentry><refentrytitle>os-release</refentrytitle><manvolnum>5</manvolnum></citerefentry>, or a
191 fallback set at compilation time).</para>
192
193 <para>The <varname>HostnameSource</varname> property exposes the origin of the currently configured
194 hostname. One of <literal>static</literal> (set from <filename>/etc/hostname</filename>),
195 <literal>transient</literal> (a non-permanent hostname from an external source),
196 <literal>default</literal> (the value from <filename>os-release</filename> or the the compiled-in
197 fallback).</para>
198
199 <para>The <varname>IconName</varname> property exposes the <emphasis>icon name</emphasis> following the
200 XDG icon naming spec. If not set, information such as the chassis type (see below) is used to find a
201 suitable fallback icon name (i.e. <literal>computer-laptop</literal>
202 vs. <literal>computer-desktop</literal> is picked based on the chassis information). If no such data is
203 available, the empty string is returned. In that case an application should fall back to a replacement
204 icon, for example <literal>computer</literal>. If this property is set to the empty string, the automatic
205 fallback name selection is enabled again.</para>
206
207 <para>The <varname>Chassis</varname> property exposes a <emphasis>chassis type</emphasis>, one of the
208 currently defined chassis types: <literal>desktop</literal>, <literal>laptop</literal>,
209 <literal>server</literal>, <literal>tablet</literal>, <literal>handset</literal>, as well as the special
210 chassis types <literal>vm</literal> and <literal>container</literal> for virtualized systems. Note that
211 in most cases the chassis type will be determined automatically from DMI/SMBIOS/ACPI firmware
212 information. Writing to this setting is hence useful only to override misdetected chassis types, or to
213 configure the chassis type if it could not be auto-detected. Set this property to the empty string to
214 reenable the automatic detection of the chassis type from firmware information.</para>
215
216 <para>Note that <filename>systemd-hostnamed</filename> starts only on request and terminates after a
217 short idle period. This effectively means that <function>PropertyChanged</function> messages are not sent
218 out for changes made directly on the files (as in: administrator edits the files with vi). This is
219 the intended behavior: manual configuration changes should require manual reloading.</para>
220
221 <para>The transient (dynamic) hostname exposed by the <varname>Hostname</varname> property maps directly
222 to the kernel hostname. This hostname should be assumed to be highly dynamic, and hence should be watched
223 directly, without depending on <function>PropertyChanged</function> messages from
224 <filename>systemd-hostnamed</filename>. To accomplish this, open
225 <filename>/proc/sys/kernel/hostname</filename> and
226 <citerefentry project="man-pages"><refentrytitle>poll</refentrytitle><manvolnum>3</manvolnum></citerefentry>
227 for <constant>SIGHUP</constant> which is triggered by the kernel every time the hostname changes. Again:
228 this is special for the transient (dynamic) hostname, and does not apply to the configured (fixed)
229 hostname.</para>
230
231 <para>Applications may read the hostname data directly if hostname change notifications
232 are not necessary. Use
233 <citerefentry project="man-pages"><refentrytitle>gethostname</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
234 <filename>/etc/hostname</filename> (possibly with per-distribution fallbacks), and
235 <citerefentry><refentrytitle>machine-info</refentrytitle><manvolnum>3</manvolnum></citerefentry>
236 for that. For more information on these files and syscalls see the respective man pages.</para>
237
238 <para><varname>KernelName</varname>, <varname>KernelRelease</varname>, and
239 <varname>KernelVersion</varname> expose the kernel name (e.g. <literal>Linux</literal>), release
240 (e.g. <literal>5.0.0-11</literal>), and version (i.e. the build number, e.g. <literal>#11</literal>) as
241 reported by <citerefentry project="man-pages"><refentrytitle>uname</refentrytitle><manvolnum>2</manvolnum></citerefentry>.
242 <varname>OperatingSystemPrettyName</varname>, <varname>OperatingSystemCPEName</varname>, and
243 <varname>HomeURL</varname> expose the <varname>PRETTY_NAME=</varname>, <varname>CPE_NAME=</varname> and
244 <varname>HOME_URL=</varname> fields from
245 <citerefentry><refentrytitle>os-release</refentrytitle><manvolnum>5</manvolnum></citerefentry>. The
246 purpose of those properties is to allow remote clients to access this information over D-Bus. Local
247 clients can access the information directly.</para>
248
249 <refsect2>
250 <title>Methods</title>
251
252 <para><function>SetHostname()</function> sets the transient (dynamic) hostname, which is used if no
253 static hostname is set. This value must be an internet-style hostname, 7-bit lowercase ASCII, no
254 special chars/spaces. An empty string will unset the transient hostname.</para>
255
256 <para><function>SetStaticHostname()</function> sets the static hostname which is exposed by the
257 <varname>StaticHostname</varname> property. When called with an empty argument, the static
258 configuration in <filename>/etc/hostname</filename> is removed. Since the static hostname has the
259 highest priority, calling this function usually affects also the <varname>Hostname</varname> property
260 and the effective hostname configured in the kernel.</para>
261
262 <para><function>SetPrettyHostname()</function> sets the pretty hostname which is exposed by the
263 <varname>PrettyHostname</varname> property.</para>
264
265 <para><function>SetIconName()</function>, <function>SetChassis()</function>,
266 <function>SetDeployment()</function>, and <function>SetLocation()</function> set the properties
267 <varname>IconName</varname> (the name of the icon representing for the machine),
268 <varname>Chassis</varname> (the machine form factor), <varname>Deployment</varname> (the system
269 deployment environment), and <varname>Location</varname> (physical system location), respectively.
270 </para>
271
272 <para><varname>PrettyHostname</varname>, <varname>IconName</varname>, <varname>Chassis</varname>,
273 <varname>Deployment</varname>, and <varname>Location</varname> are stored in
274 <filename>/etc/machine-info</filename>. See
275 <citerefentry><refentrytitle>machine-info</refentrytitle><manvolnum>5</manvolnum></citerefentry> for
276 the semantics of those settings.</para>
277
278 <para><function>GetProductUUID()</function> returns the "product UUID" as exposed by the kernel based
279 on DMI information in <filename>/sys/class/dmi/id/product_uuid</filename>. Reading the file directly
280 requires root privileges, and this method allows access to unprivileged clients through the polkit
281 framework.</para>
282
283 <para><function>Describe()</function> returns a JSON representation of all properties in one.</para>
284 </refsect2>
285
286 <refsect2>
287 <title>Security</title>
288
289 <para>The <varname>interactive</varname> boolean parameters can be used to control whether polkit
290 should interactively ask the user for authentication credentials if required.</para>
291
292 <para>The polkit action for <function>SetHostname()</function> is
293 <interfacename>org.freedesktop.hostname1.set-hostname</interfacename>. For
294 <function>SetStaticHostname()</function> and <function>SetPrettyHostname()</function> it is
295 <interfacename>org.freedesktop.hostname1.set-static-hostname</interfacename>. For
296 <function>SetIconName()</function>, <function>SetChassis()</function>, <function>SetDeployment()</function>
297 and <function>SetLocation()</function> it is
298 <interfacename>org.freedesktop.hostname1.set-machine-info</interfacename>.</para>
299 </refsect2>
300 </refsect1>
301
302 <refsect1>
303 <title>Recommendations</title>
304
305 <para>Here are three examples that show how the pretty hostname and the icon name should be used:
306 <itemizedlist>
307 <listitem><para>When registering DNS-SD services: use the pretty hostname in the service name, and pass
308 the icon name in the TXT data, if there is an icon name. Browsing clients can then show the server icon
309 on each service. This is especially useful for WebDAV applications or UPnP media sharing.
310 </para></listitem>
311
312 <listitem><para>Set the bluetooth name to the pretty hostname.</para></listitem>
313
314 <listitem><para>When your file browser has a "Computer" icon, replace the name with the pretty hostname
315 if set, and the icon with the icon name, if it is set.</para></listitem>
316 </itemizedlist></para>
317
318 <para>To properly handle name lookups with changing local hostnames without having to edit
319 <filename>/etc/hosts</filename>, we recommend using <filename>systemd-hostnamed</filename> in combination
320 with <citerefentry><refentrytitle>nss-myhostname</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
321 </para>
322
323 <para>Here are some recommendations to follow when generating a static (internet) hostname from a pretty
324 name:
325 <itemizedlist>
326 <listitem><para>Generate a single DNS label only, not an FQDN. That means no dots allowed. Strip them,
327 or replace them with <literal>-</literal>.</para></listitem>
328
329 <listitem><para>It's probably safer to not use any non-ASCII chars, even if DNS allows this in some way
330 these days. In fact, restrict your charset to <literal>a-zA-Z0-9</literal> and <literal>-</literal>.
331 Strip other chars, or try to replace them in some smart way with chars from this set, for example
332 <literal>ä</literal><literal>ae</literal>, and use <literal>-</literal> as the replacement for all
333 punctuation characters and whitespace.</para></listitem>
334
335 <listitem><para>Try to avoid creating repeated <literal>-</literal>, as well as <literal>-</literal> as
336 the first or last char.</para></listitem>
337
338 <listitem><para>Limit the hostname to 63 chars, which is the length of a DNS label.</para></listitem>
339
340 <listitem><para>If after stripping special chars the empty string is the result, you can pass this
341 as-is to <filename>systemd-hostnamed</filename> in which case it will automatically use a suitable
342 fallback.</para></listitem>
343
344 <listitem><para>Uppercase charaacters should be replaced with their lowercase equivalents.
345 </para></listitem>
346 </itemizedlist></para>
347
348 <para>Note that while <filename>systemd-hostnamed</filename> applies some checks to the hostname you pass
349 they are much looser than the recommendations above. For example, <filename>systemd-hostnamed</filename>
350 will also accept <literal>_</literal> in the hostname, but we recommend not using this to avoid clashes
351 with DNS-SD service types. Also <filename>systemd-hostnamed</filename> allows longer hostnames, but
352 because of the DNS label limitations, we recommend not making use of this.</para>
353
354 <para>Here are a couple of example conversions:
355 <itemizedlist>
356 <listitem><para><literal>Lennart's PC</literal><literal>lennarts-pc</literal></para></listitem>
357 <listitem><para><literal>Müllers Computer</literal><literal>muellers-computer</literal></para></listitem>
358 <listitem><para><literal>Voran!</literal><literal>voran</literal></para></listitem>
359 <listitem><para><literal>Es war einmal ein Männlein</literal><literal>es-war-einmal-ein-maennlein</literal></para></listitem>
360 <listitem><para><literal>Jawoll. Ist doch wahr!</literal><literal>jawoll-ist-doch-wahr</literal></para></listitem>
361 <listitem><para><literal>レナート</literal><literal>localhost</literal></para></listitem>
362 <listitem><para><literal>...zack!!! zack!...</literal><literal>zack-zack</literal></para></listitem>
363 </itemizedlist></para>
364
365 <para>Of course, an already valid internet hostname label you enter and pass through this
366 conversion should stay unmodified, so that users have direct control of it, if they want — by simply
367 ignoring the fact that the pretty hostname is pretty and just edit it as if it was the normal internet
368 name.</para>
369 </refsect1>
370
371 <refsect1>
372 <title>Versioning</title>
373
374 <para>These D-Bus interfaces follow <ulink url="http://0pointer.de/blog/projects/versioning-dbus.html">
375 the usual interface versioning guidelines</ulink>.</para>
376 </refsect1>
377
378 <refsect1>
379 <title>Examples</title>
380
381 <example>
382 <title>Introspect <interfacename>org.freedesktop.hostname1</interfacename> on the bus</title>
383
384 <programlisting>$ gdbus introspect --system \
385 --dest org.freedesktop.hostname1 \
386 --object-path /org/freedesktop/hostname1
387 </programlisting>
388 </example>
389 </refsect1>
390
391 <refsect1>
392 <title>See also</title>
393
394 <para>David Zeuthen's original Fedora
395 <ulink url="https://fedoraproject.org/wiki/Features/BetterHostname">Feature page about xdg-hostname</ulink></para>
396 </refsect1>
397 </refentry>