Skip to content

Conversation

@teclator
Copy link
Contributor

@teclator teclator commented Mar 11, 2025

Problem

Currently the backend and the UI does not allow to set the system hostname, and the kernel cmdline argument only allow to set the transient hostname.

Solution

  • Added a hostname specific model and API for getting/setting the transient and persistent hostname.
  • Set the persistent hostname in dracut if the hostname option is given as linuxrc used to do.
  • Allow to disable the manage of the hostname only in case the kernel cmdline SetHostname option is given
  • By now we will not expose the hostname-mode or the via_dhcp option through the profile or config.. see below some notes and clarifications about it.

I decided to not expose the by_dhcp option by now until discussed, and maybe renaming it to via_dhcp would be better, or just use mode allowing to set it to {default|dhcp|none}.

From the doc page ... https://networkmanager.pages.freedesktop.org/NetworkManager/NetworkManager/NetworkManager.conf.html

hostname-mode

Set the management mode of the hostname. This parameter will affect only the transient hostname. If a valid static hostname is set, NetworkManager will skip the update of the hostname despite the value of this option. An hostname empty or equal to 'localhost', 'localhost6', 'localhost.localdomain' or 'localhost6.localdomain' is considered invalid.

default: NetworkManager will update the hostname with the one provided via DHCP or reverse DNS lookup of the IP address on the connection with the default route or on any connection with the property hostname.only-from-default set to 'false'. Connections are considered in order of increasing value of the hostname.priority property. In case multiple connections have the same priority, connections activated earlier are considered first. If no hostname can be determined in such way, the hostname will be updated to the last one set outside NetworkManager or to 'localhost.localdomain'.

dhcp: this is similar to 'default', with the difference that after trying to get the DHCP hostname, reverse DNS lookup is not done. Note that selecting this option is equivalent to setting the property 'hostname.from-dns-lookup' to 'false' globally for all connections in NetworkManager.conf.

none: NetworkManager will not manage the transient hostname and will never set it.

So, basically, if a static hostname is set then it will not be updated by any DHCP Ack. Therefore, I'm even considering to not expose it.

In linurxc we had the SetHostname option for disabling set the hostname via DHCP. Currently the kernel cmdline argument hostname=test only sets the transient hostname, but this PR add the linuxrc behavior setting the persistent hostname which prevents the hostname to be modified via DHCP, but it also allows to pass the SetHostname=0 to set the hostname-mode to none disabling the manage of the transient hostname by NetworkManager. This option is what we wanted to offer in the interface, but as setting the persistent hostname is enough I think we can omit it by now.

With linuxrc was different, the persistent hostname can be modified via DHCP if not disable the DHCP hostname.

Testing

  • Tested manually

@coveralls
Copy link

coveralls commented Mar 12, 2025

Pull Request Test Coverage Report for Build 13832216888

Details

  • 0 of 60 (0.0%) changed or added relevant lines in 8 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage decreased (-0.2%) to 72.32%

Changes Missing Coverage Covered Lines Changed/Added Lines %
rust/agama-server/src/web.rs 0 1 0.0%
rust/xtask/src/main.rs 0 1 0.0%
rust/agama-lib/src/store.rs 0 4 0.0%
rust/agama-lib/src/hostname/http_client.rs 0 5 0.0%
rust/agama-server/src/web/docs/hostname.rs 0 6 0.0%
rust/agama-lib/src/hostname/store.rs 0 7 0.0%
rust/agama-server/src/hostname/web.rs 0 13 0.0%
rust/agama-lib/src/hostname/client.rs 0 23 0.0%
Files with Coverage Reduction New Missed Lines %
rust/agama-server/src/web.rs 1 0.0%
Totals Coverage Status
Change from base Build 13812608688: -0.2%
Covered Lines: 20016
Relevant Lines: 27677

💛 - Coveralls

@teclator teclator force-pushed the hostname_handling branch from 60ea02d to 78c7f4f Compare March 12, 2025 22:23
@teclator teclator force-pushed the hostname_handling branch from 78c7f4f to b967cc5 Compare March 12, 2025 22:37
@teclator teclator force-pushed the hostname_handling branch from a596a70 to 65e3ab8 Compare March 13, 2025 14:49
@teclator teclator merged commit 9ac77fd into after-release-beta2 Mar 13, 2025
4 checks passed
@teclator teclator deleted the hostname_handling branch March 13, 2025 15:07
@imobachgs imobachgs mentioned this pull request Mar 27, 2025
imobachgs added a commit that referenced this pull request Mar 27, 2025
bmwiedemann pushed a commit to bmwiedemann/openSUSE that referenced this pull request Mar 27, 2025
https://build.opensuse.org/request/show/1256476
by user IGonzalezSosa + anag+factory
- Version 13

- live/src/agama-installer.kiwi: Adapt to latest patterns (SR#364982)

- Fixed DUD issues (gh#agama-project/agama#2199):
  - Enabling the agama-dud service in the live media
  - Making the agama-dud script executable
  - Disabling dmesg on the console while DUD runs

- Added the initial functionality for inst.dud
  (jsc#3670 and jsc#AGM-65)

- Add aaa_base-extras which includes setup-systemd-proxy-env.path
  (gh#agama-project/agama#2184).

- Fixed broken "inst.self_update" boot option
  (gh#agama-project/agama#2175)

- Remove /etc/nvme/host* files from the image (bsc#1238038)

- Fixed broken media check service (bsc#1239155)

- (gh#agama-project/agama#2142)
  - Allow to set the static hostname using the hostname kernel
    cmdline argument.
  - Allow to disable the set of the
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants