Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hostname: consider systemd.hostname= static and give it precedence #25158

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Commits on Jan 11, 2024

  1. hostname: consider systemd.hostname= static and give it precedence

    The systemd.hostname= kernel commandline can for example be used to set a
    unique hostname on embedded devices with read-only root file systems,
    by letting the bootloader generate it from factory data.
    
    The current semantics result in somewhat unexpected behaviour when doing so.
    Clean up the semantics of the systemd.hostname= kernel parameter to make it
    more useful and predictable.
    
    The previous semantics were:
    
     - systemd.hostname= takes precedence over /etc/hostname during boot,
       even though it is technically considered a transient hostname.
     - In systemd-hostnamed however /etc/hostname takes precedence over
       systemd.hostname= as it is considered transient again and the normal
       priorities (static over transient over default) are followed.
       This means if a new transient hostname is set, the hostname of the system
       will be sethostname()'d to the one in /etc/hostname (if present) or
       the new transient hostname.
     - If /etc/hostname does not exist, systemd-hostnamed does not report a static
       hostname via dbus to consumers like the NetworkManager dhcp client.
       In the case of NetworkManager this results in no hostname being set in dhcp
       requests.
    
    The new semantics are:
    
     - systemd.hostname= is considered a static hostname during boot and in
       systemd-hostnamed and as such takes precedence over transient or default
       hostnames.
     - systemd.hostname= takes precedence over /etc/hostname.
    hnez committed Jan 11, 2024
    Configuration menu
    Copy the full SHA
    e02ea87 View commit details
    Browse the repository at this point in the history
  2. hostname: use hostname= kernel command line parameter as default host…

    …name
    
    The hostname= kernel commandline parameter is interpreted by the Linux
    kernel and used as the initial hostname of the system.
    
    As of now systemd (when running as PID 1) will behave as follows with
    respect to the hostname set via the kernel command line:
    
     - If a static hostname is configured via systemd.hostname= or /etc/hostname
       it will be set regardless of what was set via hostname=.
     - If no static hostname is configured but there is already _some_ hostname
       set (e.g. via the hostname= kernel command line), that hostname will be
       kept.
     - If no static hostname is configured and none is configured e.g. via
       hostname= a generic default is used based on e.g. the OS release.
    
    If later on a new transient hostname is set via the `SetHostname` DBus call
    to systemd-hostnamed, it will take precedence over the hostname provided via
    the hostname= kernel command line, but not over the static hostname.
    This means the hostname= parameter behaves like a default hostname.
    
    There is however an inconsistency: when unsetting the transient hostname
    with an empty `SetHostname` method call without a static hostname set.
    In this case the hostname will not revert to the one set via the hostname=
    parameter, but instead to a generic default hostname.
    
    Fix this by considering hostname= as an actual default hostname when no
    static or transient hostname is set.
    
    Signed-off-by: Leonard Göhrs <l.goehrs@pengutronix.de>
    hnez committed Jan 11, 2024
    Configuration menu
    Copy the full SHA
    6afbb5a View commit details
    Browse the repository at this point in the history
  3. man/hostnamed: document the various hostname sources and their priori…

    …ties
    
    The way a hostname for the system is chosen has become quite complex
    with three classes (static, transient, default) of hostnames and
    multiple options per class, each with their own priorities w.r.t.
    which hostname will be prefered over which other hostname.
    
    Document the different hostname sources in the systemd-hostnamed man page.
    
    Signed-off-by: Leonard Göhrs <l.goehrs@pengutronix.de>
    hnez committed Jan 11, 2024
    Configuration menu
    Copy the full SHA
    d44e998 View commit details
    Browse the repository at this point in the history