Skip to content

fix(roles/hostname): remove the loopback entries of the hostname from /etc/hosts - #776

Merged
markuslf merged 1 commit into
mainfrom
fix/hostname-loopback-entries
Nov 18, 2026
Merged

markuslf merged 1 commit into
mainfrom
fix/hostname-loopback-entries

Conversation

@markuslf

Copy link
Copy Markdown
Member

cloud-init (manage_etc_hosts) 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, 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:

  • New molecule scenario hostname passes on Debian 12/13, Rocky 8/9/10, Ubuntu 22.04/24.04/26.04.
  • Local Rocky 9 and Debian 13 VMs: --check --diff, idempotent rerun, reboot, Lynis NAME-4406 NOT FOUND afterwards.

… /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.
@markuslf
markuslf merged commit 04b1672 into main Nov 18, 2026
11 checks passed
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.

1 participant