Debian Codegraph @

man/hostname.xml

raw
1 <?xml version='1.0'?> <!--*-nxml-*-->
2 <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
3 "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
4 <!ENTITY % entities SYSTEM "custom-entities.ent" >
5 %entities;
6 ]>
7 <!-- SPDX-License-Identifier: LGPL-2.1-or-later -->
8
9 <refentry id="hostname">
10 <refentryinfo>
11 <title>hostname</title>
12 <productname>systemd</productname>
13 </refentryinfo>
14
15 <refmeta>
16 <refentrytitle>hostname</refentrytitle>
17 <manvolnum>5</manvolnum>
18 </refmeta>
19
20 <refnamediv>
21 <refname>hostname</refname>
22 <refpurpose>Local hostname configuration file</refpurpose>
23 </refnamediv>
24
25 <refsynopsisdiv>
26 <para><filename>/etc/hostname</filename></para>
27 </refsynopsisdiv>
28
29 <refsect1>
30 <title>Description</title>
31
32 <para>The <filename>/etc/hostname</filename> file configures the name of the local system. Unless
33 overridden as described in the next section,
34 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry> will set this
35 hostname during boot using the
36 <citerefentry><refentrytitle>sethostname</refentrytitle><manvolnum>2</manvolnum></citerefentry> system
37 call.</para>
38
39 <para>The file should contain a single newline-terminated hostname string. Comments (lines starting with
40 a <literal>#</literal>) are ignored. The hostname should be composed of up to 64 7-bit ASCII lower-case
41 alphanumeric characters or hyphens forming a valid DNS domain name. It is strongly recommended that this
42 name contains only a single DNS label, i.e does not contain any dots. This recommendation reflects both
43 usual expectations of applications, and the fact that the Linux kernel limits the length of the system
44 hostname to 64 (i.e. close to the maximum DNS label length of 63) rather than 255 (the maximum DNS domain
45 name length). When applied, invalid characters will be filtered out in an attempt to make the name valid,
46 but obviously it is recommended to use a valid name and not rely on this filtering.</para>
47
48 <para id="question-mark-hostname-pattern">If the question mark character <literal>?</literal> appears in
49 the hostname, it is automatically substituted by a hexadecimal character derived from the
50 <citerefentry><refentrytitle>machine-id</refentrytitle><manvolnum>5</manvolnum></citerefentry> when
51 applied, securely and deterministically by cryptographic hashing. Example:
52 <literal>foobar-????-????</literal> will automatically expand to <literal>foobar-92a9-061c</literal> or
53 similar, depending on the local machine ID.</para>
54
55 <para>You may use
56 <citerefentry><refentrytitle>hostnamectl</refentrytitle><manvolnum>1</manvolnum></citerefentry> to change
57 the value of this file during runtime from the command line. Use
58 <citerefentry><refentrytitle>systemd-firstboot</refentrytitle><manvolnum>1</manvolnum></citerefentry> to
59 initialize it on mounted (but not booted) system images.</para>
60 </refsect1>
61
62 <refsect1>
63 <title>Hostname semantics</title>
64
65 <para><citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry> and the
66 associated tools will obtain the hostname in the following ways:</para>
67 <itemizedlist>
68 <listitem><para>If the kernel command line parameter <varname>systemd.hostname=</varname> specifies a
69 valid hostname,
70 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry> will use it
71 to set the hostname during early boot, see
72 <citerefentry><refentrytitle>kernel-command-line</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
73 </para></listitem>
74
75 <listitem><para>Otherwise, the "static" hostname specified by <filename>/etc/hostname</filename> as
76 described above will be used.</para></listitem>
77
78 <listitem><para>Otherwise, a transient hostname may be set during runtime, for example based on
79 information in a DHCP lease, see
80 <citerefentry><refentrytitle>systemd-hostnamed.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>.
81 Both <ulink url="https://developer.gnome.org/NetworkManager/stable/">NetworkManager</ulink> and
82 <citerefentry><refentrytitle>systemd-networkd.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>
83 allow this. Note that
84 <citerefentry><refentrytitle>systemd-hostnamed.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>
85 gives higher priority to the static hostname, so the transient hostname will only be used if the static
86 hostname is not configured.</para></listitem>
87
88 <listitem><para>Otherwise, a fallback hostname configured at compilation time will be used
89 (<literal>&FALLBACK_HOSTNAME;</literal>).</para></listitem>
90
91 <!-- what about the "linux" fallback fallback? -->
92 </itemizedlist>
93
94 <para>Effectively, the static hostname has higher priority than a transient hostname, which has higher
95 priority than the fallback hostname. Transient hostnames are equivalent, so setting a new transient
96 hostname causes the previous transient hostname to be forgotten. The hostname specified on the kernel
97 command line is like a transient hostname, with the exception that it has higher priority when the
98 machine boots. Also note that those are the semantics implemented by systemd tools, but other programs
99 may also set the hostname.</para>
100 </refsect1>
101
102 <refsect1>
103 <title>History</title>
104
105 <para>The simple configuration file format of
106 <filename>/etc/hostname</filename> originates from Debian
107 GNU/Linux.</para>
108 </refsect1>
109
110 <refsect1>
111 <title>See Also</title>
112 <para><simplelist type="inline">
113 <member><citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry></member>
114 <member><citerefentry><refentrytitle>sethostname</refentrytitle><manvolnum>2</manvolnum></citerefentry></member>
115 <member><citerefentry><refentrytitle>hostname</refentrytitle><manvolnum>1</manvolnum></citerefentry></member>
116 <member><citerefentry><refentrytitle>hostname</refentrytitle><manvolnum>7</manvolnum></citerefentry></member>
117 <member><citerefentry><refentrytitle>machine-id</refentrytitle><manvolnum>5</manvolnum></citerefentry></member>
118 <member><citerefentry><refentrytitle>machine-info</refentrytitle><manvolnum>5</manvolnum></citerefentry></member>
119 <member><citerefentry><refentrytitle>hostnamectl</refentrytitle><manvolnum>1</manvolnum></citerefentry></member>
120 <member><citerefentry><refentrytitle>systemd-hostnamed.service</refentrytitle><manvolnum>8</manvolnum></citerefentry></member>
121 <member><citerefentry><refentrytitle>systemd-firstboot</refentrytitle><manvolnum>1</manvolnum></citerefentry></member>
122 </simplelist></para>
123 </refsect1>
124
125 </refentry>