Repository navigation
fix(roles/hostname): remove the loopback entries of the hostname from /etc/hosts - #776
Merged
Merged
Conversation
… /etc/hosts cloud-init (manage_etc_hosts, templates/hosts.*.tmpl) and the Debian installer map the hostname to 127.0.0.1, 127.0.1.1 or ::1. glibc returns /etc/hosts entries in file order, so the hostname resolved to loopback instead of the IP in the role's marker block (Lynis NAME-4406). Remove loopback lines that carry nothing but the short name, alone or with any domain. Lines listing other names, such as localhost, stay. Add a molecule scenario that seeds the cloud-init and Debian installer lines and verifies that the hostname resolves to the default IPv4 address while localhost and unrelated loopback names still resolve to loopback. Verified with cloud-init 26.2, Hetzner Rocky 9 images, Debian 13 and Rocky 9.4 with Lynis 3.1.7.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
cloud-init (
manage_etc_hosts) and the Debian installer map the hostname to127.0.0.1,127.0.1.1or::1. glibc returns/etc/hostsentries in file order, so the hostname resolved to loopback instead of the IP in the role's marker block, which Lynis reports as NAME-4406.The role now removes loopback lines that carry nothing but the short name, alone or with any domain. Lines that list other names, such as
localhost, stay.Breaking change: clients that reach a loopback-only service by the host name no longer connect (verified with MariaDB and
user@localhost). Checked read-only on all Linuxfabrik hosts that would change, nothing there depends on it.Testing:
hostnamepasses on Debian 12/13, Rocky 8/9/10, Ubuntu 22.04/24.04/26.04.--check --diff, idempotent rerun, reboot, Lynis NAME-4406 NOT FOUND afterwards.