sd-dhcp-server: Add Hostname= option to static leases

This adds a new `Hostname=` option to the [DHCPServerStaticLease]
section in .network files, allowing an administrator to assign a
specific hostname to a client receiving a static lease.

We automatically select the correct DHCP option to use based on the
format of the provided string:

- Single DNS labels are sent as Option 12.
- Names with multiple DNS labels are sent as Option 81 in wire format.

Fixes: #39634
This commit is contained in:
Chris Down
2025-11-10 00:59:59 +08:00
committed by Yu Watanabe
parent c83f3f0837
commit 7f9c0c31d2
18 changed files with 409 additions and 36 deletions

View File

@@ -4227,6 +4227,25 @@ ServerAddress=192.168.0.1/24</programlisting>
<xi:include href="version-info.xml" xpointer="v249"/></listitem>
</varlistentry>
<varlistentry>
<term><varname>Hostname=</varname></term>
<listitem><para>The hostname to send to the client in DHCP replies. This can be either a simple
hostname (e.g., <literal>mydevice</literal>) or a fully qualified domain name (e.g.,
<literal>mydevice.example.com</literal>), following RFC 1123 naming conventions. Each label can be
up to 63 characters, with a total maximum length of 253 characters for FQDNs. When this option is
set, the DHCP server will include the hostname in DHCP replies (both OFFER and ACK) to the client
with the matched MAC address.</para>
<para>The server automatically selects the appropriate DHCP option based on the hostname format:
simple hostnames (single DNS label) are sent via option 12 (Host Name) per RFC 2132, while FQDNs
with multiple labels are sent via option 81 (Client FQDN) per RFC 4702 using DNS wire format
encoding. The configured hostname is sent unconditionally, any hostname requested by the client in
its DHCP message is ignored.</para>
<xi:include href="version-info.xml" xpointer="v259"/></listitem>
</varlistentry>
</variablelist>
</refsect1>