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.2/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 recommended that this name 42 contains only a single label, i.e. without any dots. Invalid characters will be filtered out in an 43 attempt to make the name valid, but obviously it is recommended to use a valid name and not rely on this 44 filtering.</para> 45 46 <para>You may use 47 <citerefentry><refentrytitle>hostnamectl</refentrytitle><manvolnum>1</manvolnum></citerefentry> to change 48 the value of this file during runtime from the command line. Use 49 <citerefentry><refentrytitle>systemd-firstboot</refentrytitle><manvolnum>1</manvolnum></citerefentry> to 50 initialize it on mounted (but not booted) system images.</para> 51 </refsect1> 52 53 <refsect1> 54 <title>Hostname semantics</title> 55 56 <para><citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry> and the 57 associated tools will obtain the hostname in the following ways:</para> 58 <itemizedlist> 59 <listitem><para>If the kernel commandline parameter <varname>systemd.hostname=</varname> specifies a 60 valid hostname, 61 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry> will use it 62 to set the hostname during early boot, see 63 <citerefentry><refentrytitle>kernel-command-line</refentrytitle><manvolnum>7</manvolnum></citerefentry>, 64 </para></listitem> 65 66 <listitem><para>Otherwise, the "static" hostname specified by <filename>/etc/hostname</filename> as 67 described above will be used.</para></listitem> 68 69 <listitem><para>Otherwise, a transient hostname may be set during runtime, for example based on 70 information in a DHCP lease, see 71 <citerefentry><refentrytitle>systemd-hostnamed.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>. 72 Both <ulink url="https://developer.gnome.org/NetworkManager/stable/">NetworkManager</ulink> and 73 <citerefentry><refentrytitle>systemd-networkd.service</refentrytitle><manvolnum>8</manvolnum></citerefentry> 74 allow this. Note that 75 <citerefentry><refentrytitle>systemd-hostnamed.service</refentrytitle><manvolnum>8</manvolnum></citerefentry> 76 gives higher priority to the static hostname, so the transient hostname will only be used if the static 77 hostname is not configured.</para></listitem> 78 79 <listitem><para>Otherwise, a fallback hostname configured at compilation time will be used 80 (<literal>&FALLBACK_HOSTNAME;</literal>).</para></listitem> 81 82 <!-- what about the "linux" fallback fallback? --> 83 </itemizedlist> 84 85 <para>Effectively, the static hostname has higher priority than a transient hostname, which has higher 86 priority than the fallback hostname. Transient hostnames are equivalent, so setting a new transient 87 hostname causes the previous transient hostname to be forgotten. The hostname specified on the kernel 88 command line is like a transient hostname, with the exception that it has higher priority when the 89 machine boots. Also note that those are the semantics implemented by systemd tools, but other programs 90 may also set the hostname.</para> 91 </refsect1> 92 93 <refsect1> 94 <title>History</title> 95 96 <para>The simple configuration file format of 97 <filename>/etc/hostname</filename> originates from Debian 98 GNU/Linux.</para> 99 </refsect1> 100 101 <refsect1> 102 <title>See Also</title> 103 <para> 104 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>, 105 <citerefentry><refentrytitle>sethostname</refentrytitle><manvolnum>2</manvolnum></citerefentry>, 106 <citerefentry><refentrytitle>hostname</refentrytitle><manvolnum>1</manvolnum></citerefentry>, 107 <citerefentry><refentrytitle>hostname</refentrytitle><manvolnum>7</manvolnum></citerefentry>, 108 <citerefentry><refentrytitle>machine-id</refentrytitle><manvolnum>5</manvolnum></citerefentry>, 109 <citerefentry><refentrytitle>machine-info</refentrytitle><manvolnum>5</manvolnum></citerefentry>, 110 <citerefentry><refentrytitle>hostnamectl</refentrytitle><manvolnum>1</manvolnum></citerefentry>, 111 <citerefentry><refentrytitle>systemd-hostnamed.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>, 112 <citerefentry><refentrytitle>systemd-firstboot</refentrytitle><manvolnum>1</manvolnum></citerefentry> 113 </para> 114 </refsect1> 115 116</refentry> 117