RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 1093037 - localhost.localdomain in wrong order /etc/hosts
Summary: localhost.localdomain in wrong order /etc/hosts
Keywords:
Status: CLOSED WONTFIX
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: setup
Version: 7.0
Hardware: Unspecified
OS: Unspecified
unspecified
low
Target Milestone: rc
: ---
Assignee: Martin Osvald 🛹
QA Contact: BaseOS QE - Apps
URL:
Whiteboard:
Depends On:
Blocks: 1203710 1398314 1451294
TreeView+ depends on / blocked
 
Reported: 2014-04-30 13:12 UTC by Eduard Barrera
Modified: 2020-03-06 11:34 UTC (History)
9 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2019-06-19 15:23:31 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)

Description Eduard Barrera 2014-04-30 13:12:47 UTC
Description of problem:

A user is reporting that localhost is in wrong order on /etc/hosts file

#man hostname

THE FQDN
       The  FQDN  (Fully  Qualified Domain Name) of the system is the name that the resolver(3) returns for the host name, such as, ursula.example.com.  It is usually the hostname followed by the DNS domain name (the part after
       the first dot).  You can check the FQDN using hostname --fqdn or the domain name using dnsdomainname.


so with the current status of the /etc/hosts file

#hostname -f 
localhost

#hostname
localhost.localdomain

but it should be the oposite


If it could be considered a bug it also affects RHEL 6

Version-Release number of selected component (if applicable):
RHEL 7
RHEL 6

How reproducible:

$ cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6


#hostname -f 
localhost

#hostname
localhost.localdomain


Actual results:
cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6


#hostname -f 
localhost

#hostname
localhost.localdomain


Expected results:

the fqdn should be first

$ cat /etc/hosts
127.0.0.1    localhost.localdomain localhost localhost4 localhost4.localdomain4
::1          localhost.localdomain localhost localhost6 localhost6.localdomain6


#hostname -f 
localhost.localdomain

#hostname
localhost




Additional info:

Comment 2 Pavel Šimerda (pavlix) 2014-04-30 14:24:44 UTC
I don't think that 'localdomain', 'localdomain4' and 'localdomain6' make any sense unless you are forced to specify a domain. Therefore IMO the following contents of /etc/hosts would be perfectly valid.

127.0.0.1 localhost
::1 localhost

I would even go as far as saying that 'localhost' should be a keyword for the resolver and shouldn't need any content in /etc/hosts. Since the times of IPv4 and IPv6 dualstack, I would actually discourage any aliases in /etc/hosts.

If you insist on having 'localhost4' and 'localhost6' available (why?), it should be ok to add them to the respective lines:

127.0.0.1 localhost localhost4
::1 localhost localhost6

If you insist on having any of 'localhost.localdomain' and the 4/6 suffix variants (again, why?), you can just add them like it is shown in the actual result part of the bug report. My preference would be to avoid them entirely as there's no actual 'localdomain'.

When typing the host name, IMO the only thing 'localdomain' serves is to add a dot into the host name so that it's considered a FQDN by any tools that could check by just looking for a dot. The 'localdomain4' and 'localdomain6' seem to serve no purpose as even in the DNS you don't have IPv4 and IPv6 domains, just host names with A result, AAAA result or both.

Comment 4 Ondrej Vasik 2014-04-30 15:32:55 UTC
Reasons for having localhost4 and localhost6 are described in https://bugzilla.redhat.com/show_bug.cgi?id=483244 - localhost6 was introduced by anaconda, so it was kept... Approach with not having .localdomain* aliases is used by gentoo and suggested in https://bugzilla.redhat.com/show_bug.cgi?id=483244#c3 .
We can change the entry either by switching localhost and localhost.domain order in /etc/hosts - or by removing the .localdomain* entries - both seem to be fine - right?

Comment 5 Pavel Šimerda (pavlix) 2014-04-30 16:13:16 UTC
(In reply to Ondrej Vasik from comment #4)
> Reasons for having localhost4 and localhost6 are described in
> https://bugzilla.redhat.com/show_bug.cgi?id=483244 - localhost6 was
> introduced by anaconda, so it was kept...

Then we can consider 'localhost6' a backwards compatibility measure and 'localhost4' its logical counterpart to avoid any doubt about the dualstack nature of localhost.

> Approach with not having
> .localdomain* aliases is used by gentoo and suggested in
> https://bugzilla.redhat.com/show_bug.cgi?id=483244#c3 .

According to your comment there localhost6.localdomain6 was already being used.

> We can change the entry either by switching localhost and localhost.domain
> order in /etc/hosts

I would rather keep localhost as the canonical hostname.

> - or by removing the .localdomain* entries - both seem
> to be fine - right?

If you agree that it's time to remove all *.localdomain* entires, I'd go with it. In any case, I would advocate keeping localhost first so that we don't change the semantics of reverse queries for 127.0.0.1 and ::1 that resolve to 'localhost'.

Comment 9 Bernie Hoefer 2016-04-07 15:37:11 UTC
Adding myself to the CC field because I (before I knew better) and a customer, long ago, hit this bug.  When one edits the /etc/hosts file, it is natural to add lines that look like what is already there.  Thus, this:

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4

has caused users to enter something like:

192.168.1.1  testmachine testmachine.example.com

...even though the man page states the FQDN should come 1st.  My opinion is that we don't need to change this for a RHEL6 minor release, or maybe even a RHEL 7 minor release -- since, as Pavel Šimerda mentioned in comment #5 there is a concern over how this change could affect localhost queries.  However, it would be nice if it was corrected for RHEL8.

Comment 16 Martin Osvald 🛹 2019-06-19 15:23:31 UTC
I am a new maintainer of setup package and got to this when going through the existing BZs to check what can get on RHEL7.8 RPL.

given the fact:

* this has been opened for 5 years already
  - so nobody is really pushing to get it fixed
* the same setting/behavior is here for *years* / the same behavior is (was) on RHEL5, RHEL6, RHEL7, RHEL8 and Fedora (30)
  - there are surely tools out there expecting this behavior
* RHEL7.8 will be in Maintenance Phase 1 (no RFEs/rebases)
* this is low prio BZ, low impacting problem
* there is only 1 customer, low prio case attached
  - if this was something really wanted, I would expect dozens of them
* workaround exists

Therefore closing this as WONTFIX, it wouldn't be wise to do this change such late for RHEL7.

Comment 17 Bernie Hoefer 2019-06-25 20:19:50 UTC
Hi, Martin.  Congrats on being the new maintainer of the setup package, and thanks for taking a look at this ticket.  While I agree that this is a very low priority, I sure would like to see it corrected.

It sets a bad example for us to provide a file whose lines are incorrectly formatted (according to the "man hosts" page).  It causes the hostname to give incorrect output if the machine doesn't have a user-provided host name set.  And finally, users who go to add their own /etc/hosts entries often format them to look like the lines we have provided -- meaning theirs will also be wrong.

I agree that changing it for RHEL 5, 6 and 7 is not wise at this stage in their life cycles.  I could even understand it for RHEL 8.  But we should correct it in whatever comes after RHEL 8.  I guess to do that, should I re-open this bug against Fedora 30 so to get it in Fedora, first?

Comment 18 Martin Osvald 🛹 2019-06-27 09:22:22 UTC
Hello Bernie,

thank you for the needinfo! I planned to clone it for Fedora, but I somehow overlooked to do so due to different BZ, so just did it now:

Bug 1724539 - localhost.localdomain in wrong order /etc/hosts


Otherwise, I agree that we should fix it.

Interestingly, RHEL4 was the last RHEL which had the expected order, but hostname & hostname -f returned the same thing at that time:

~~~
[root@localhost ~]# cat /etc/redhat-release 
Red Hat Enterprise Linux AS release 4 (Nahant Update 8)
[root@localhost ~]#

[root@localhost ~]# cat /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1               localhost.localdomain localhost
[root@localhost ~]#

[root@localhost ~]# hostname
localhost.localdomain
[root@localhost ~]# hostname -f
localhost.localdomain
[root@localhost ~]#

[root@localhost ~]# hostname -h
...
    -s, --short           short host name
    -a, --alias           alias names
    -i, --ip-address      addresses for the hostname
    -f, --fqdn, --long    long host name (FQDN)
    -d, --domain          DNS domain name
    -y, --yp, --nis       NIS/YP domainname
    -F, --file            read hostname or NIS domainname from given file
...
[root@localhost ~]#

[root@localhost ~]# hostname -s
localhost
[root@localhost ~]# hostname -a
localhost
[root@localhost ~]# hostname -d
localdomain
[root@localhost ~]#
~~~

I will try to dig into the history of this change to find out why it was done this way.


Note You need to log in before you can comment on or make changes to this bug.