Skip to content

hosts.alpine.tmpl: rearrange the order of short and long hostnames#1084

Merged
TheRealFalcon merged 1 commit into
canonical:mainfrom
dermotbradley:alpine-hosts-template-tweak
Oct 26, 2021
Merged

hosts.alpine.tmpl: rearrange the order of short and long hostnames#1084
TheRealFalcon merged 1 commit into
canonical:mainfrom
dermotbradley:alpine-hosts-template-tweak

Conversation

@dermotbradley
Copy link
Copy Markdown
Contributor

Proposed Commit Message

hosts.alpine.tmpl: rearrange the order of short and long hostnames

The Alpine /etc/hosts template results in a file where the long form of
names (including localhost) come before the short form. This means that
when running tools like 'netstat' and 'ss' which convert IP address to
names that their output will show 'localhost.localdomain' rather than
'localhost.' This patch swaps the order of the short and long form names
so such utils will show the short form name.

It also removes several unnecessary IPv6-specific entries.

Additional Context

Test Steps

Checklist:

  • My code follows the process laid out in the documentation
  • I have updated or added any unit tests accordingly
  • I have updated or added any documentation accordingly

Copy link
Copy Markdown
Member

@holmanb holmanb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR @dermotbradley.

The FQDN should definitely be second.

I don't think removing the addresses should be an issue. I spot checked alpine 3.11 and edge, both have the following /etc/hosts value:

127.0.1.1	me
127.0.0.1	localhost localhost.localdomain
::1		localhost localhost.localdomain

A grep of the codebase shows that the alpine template is the only one to have those extra addresses and cloud-init doesn't seem to use them. Since they are unnecessary for common usage, I don't have any objections to this.

@dermotbradley
Copy link
Copy Markdown
Contributor Author

A grep of the codebase shows that the alpine template is the only one to have those extra addresses and cloud-init doesn't seem to use them. Since they are unnecessary for common usage, I don't have any objections to this.

They used to also be present in the Debian template until they were removed last month by #1021.

These entries are only in the Alpine template as, at the time, I thought they were a good idea (I submitted the original Alpine support for cloud-init).

@TheRealFalcon
Copy link
Copy Markdown
Contributor

Will merged once CI fix is merged.

The Alpine /etc/hosts template results in a file where the long form of
names (including localhost) come before the short form. This means that
when running tools like 'netstat' and 'ss' which convert IP address to
names that their output will show 'localhost.localdomain' rather than
'localhost.' This patch swaps the order of the short and long form names
so such utils will show the short form name.

It also removes several unnecessary IPv6-specific entries.
@TheRealFalcon TheRealFalcon force-pushed the alpine-hosts-template-tweak branch from c59fafe to 199d2fd Compare October 26, 2021 20:30
@TheRealFalcon TheRealFalcon merged commit 75b26b0 into canonical:main Oct 26, 2021
dermotbradley added a commit to dermotbradley/cloud-init that referenced this pull request Jan 16, 2024
Revert the changes I introduced with canonical#1084, these had the side-effect
of causing "hostname" problems. Fixes canonical#4771.

Also remove the "::1 {{fqdn}} {{hostname}}" entry as this this being
results in strange behaviour with both Busybox "hostname -i" (returns
"127.0.0.1", or "127.0.0.1 A.B.C.D" if an additional non-loopback IP
entry in /etc/hosts) and Coreutils "hostname -i" (returns "::1" in
both situations), commands whereas if the "::1" entry is removed then
both Busybox and Coreutils behave the the same fashion returning
"127.0.0.1" or "127.0.0.1 A.B.C.D" as appropriate.

Also correct hosts.mariner.tmpli file it was not valid (every line
was prefixed with "+").
dermotbradley added a commit to dermotbradley/cloud-init that referenced this pull request Jan 16, 2024
Revert the changes I introduced with canonical#1084, these had the side-effect
of causing "hostname" problems. Fixes canonical#4771.

Also remove the "::1 {{fqdn}} {{hostname}}" entry as this this being
results in strange behaviour with both Busybox "hostname -i" (returns
"127.0.0.1", or "127.0.0.1 A.B.C.D" if an additional non-loopback IP
entry in /etc/hosts) and Coreutils "hostname -i" (returns "::1" in
both situations), commands whereas if the "::1" entry is removed then
both Busybox and Coreutils behave the the same fashion returning
"127.0.0.1" or "127.0.0.1 A.B.C.D" as appropriate.

Also correct hosts.mariner.tmpli file it was not valid (every line
was prefixed with "+").
holmanb pushed a commit that referenced this pull request Jan 25, 2024
Revert the changes I introduced with #1084, these had the side-effect
of causing "hostname" problems. Fixes #4771.

Also remove the "::1 {{fqdn}} {{hostname}}" entry as this being present
results in strange behaviour with "hostname -i" command: Busybox
returns "127.0.0.1", or "127.0.0.1 A.B.C.D" if an additional
non-loopback IP entry in /etc/hosts), Coreutils and net-tools both
return "::1" in both situations, whereas if the "::1" entry is removed
then Busybox, Coreutils, and net-tools "hostname -i" all behave in the
same fashion returning "127.0.0.1" or "127.0.0.1 A.B.C.D" as appropriate.

Also correct hosts.mariner.tmpli file it was not valid (every line
was prefixed with "+").

Fixes GH-4771
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.

3 participants