Bug 1329943

Summary: myhostname is missing from the hosts line in nsswitch.conf
Product: Red Hat Enterprise Linux 7 Reporter: wanghui <huiwa>
Component: authconfigAssignee: Tomas Mraz <tmraz>
Status: CLOSED ERRATA QA Contact: Dalibor Pospíšil <dapospis>
Severity: high Docs Contact:
Priority: urgent    
Version: 7.2CC: ashankar, bmcclain, bugs, cshao, dapospis, fdeutsch, fweimer, harald, hasuzuki, huzhao, leiwang, lnykryn, mnewsome, pfrankli, pkis, sbonazzo, snagar, systemd-maint-list, tmraz, weiwang, yaniwang, ycui
Target Milestone: pre-dev-freezeKeywords: ZStream
Target Release: 7.3   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: authconfig-6.2.8-11.el7 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
: 1364368 (view as bug list) Environment:
Last Closed: 2016-11-04 06:47:42 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 1329957, 1334735, 1364368    
Attachments:
Description Flags
Screenshot showing the nsswitch.conf status (no myhostname) after a minimal RHEL 7.2 installation.
none
Screenshot illustrating the oVirt problem none

Description wanghui 2016-04-25 07:20:22 UTC
Description of problem:
"hostname -f" report no address associated after change hostname from cockpit. It leads host to ping itself failed.

Version-Release number of selected component (if applicable):
ovirt-node-ng-installer-ovirt-3.6-2016042323.iso 
cockpit-0.103-1.el7.centos.x86_64
cockpit-ovirt-0.5.1-0.0.master.el7.centos.noarch

How reproducible:
100%

Steps to Reproduce:
1. Anaconda install NGN 4.0.
2. Start cockpit service.
3. Change hostname to "test.redhat.com" in cockpit.
4. Check in terminal.
   # hostname -f
5. Ping itself.
   # ping test.redhat.com

Actual results:
1. After step4, the output is as follows.
# hostname -f                                                      
hostname: No address associated with hostname 

2. After step5, the output is as follows.
# ping test.redhat.com                                             
ping: unknown host test.redhat.com 

Expected results:
1. Hostname can be accessed to itself after configuration.

Additional info:

Comment 1 Fabian Deutsch 2016-04-25 08:02:09 UTC
Can you please try to reproduce this on RHEL.

Please use hostnamectl set-hostname <hostname> to change the hostname.

This could be a systemd-hostnamed bug.

Comment 2 wanghui 2016-04-26 03:18:59 UTC
(In reply to Fabian Deutsch from comment #1)
> Can you please try to reproduce this on RHEL.
> 
> Please use hostnamectl set-hostname <hostname> to change the hostname.
> 
> This could be a systemd-hostnamed bug.

Hi fabian,

For this issue, i did not change the hostname from node side. The hostname changes are setup by cockpit. Do I need to change the hostname in node side?

Thanks,
Hui Wang

Comment 3 Fabian Deutsch 2016-04-26 08:25:10 UTC
Yes, I understand, but I try to find the component which is causing this.

Can you please try instead of using Cockpit to change the hostname, use hostnamectl set-hostname <name> on Node. If it reproduces with this, then please also try on RHEL:

Comment 4 wanghui 2016-05-04 07:20:27 UTC
(In reply to Fabian Deutsch from comment #3)
> Yes, I understand, but I try to find the component which is causing this.
> 
> Can you please try instead of using Cockpit to change the hostname, use
> hostnamectl set-hostname <name> on Node. If it reproduces with this, then
> please also try on RHEL:

Test in rhev-hypervisor7-ng-3.6-20160429.0:
# hostnamectl set-hostname retest1.redhat.com

# hostname -f
hostname: Name or service not known

# ping retest1.redhat.com
ping: unknown host retest1.redhat.com

Test in RHEL-7.2-GA version:
# hostnamectl set-hostname retest.redhat.com

# hostname -f
hostname: Name or service not known

# ping retest.redhat.com
ping: unknown host retest.redhat.com

It's the same in RHEL-7.2-GA and node-4.0.

Comment 5 Fabian Deutsch 2016-05-04 08:37:42 UTC
Lukas, is this the expected behavior of hostnamectl?

Comment 6 Lukáš Nykrýn 2016-05-04 11:14:57 UTC
hostnamctl only change the hostname(s), which in your case should only be retest1, I am not sure where hostname -f takes the domain part.

Comment 7 Fabian Deutsch 2016-05-04 12:26:02 UTC
$ man hostname

       hostname will print the name of the system as returned by the gethostname(2) function.


hostname -f will rint the hostname including the fqdn.

I assume that the FQDN part as mentioned in comment 0 can not be set with definetly hostname and probably also not makes sense to be set with hostnamectl.

At the bottom my take is that:
`hostnamectl` should also set the hostname in such a way that `hostname` will return this hostname.

Because of this I am moving this bug to systemd.

However, neither `hostname` nor `hostnamectl` should not be used to set an FQDN, because the FQDN is composed of the hostname and domain parts, and the domain part is outside of the control of a host.

Comment 8 Lukáš Nykrýn 2016-05-04 12:56:19 UTC
hostname -f returns the result based on the answer from nss. Nothing systemd related, sorry.

Comment 9 Fabian Deutsch 2016-05-04 13:05:19 UTC
Hui, could you please provide /etc/nsswitch.conf?

On my Fedora 22 it all seems to work correctly:

[fabiand@tee ~]$ sudo hostnamectl set-hostname tee.local3
[fabiand@tee ~]$ cat /etc/hostname 
tee.local3
[fabiand@tee ~]$ hostname
tee.local3

^^ Correct

[fabiand@tee ~]$ sudo hostnamectl set-hostname tee.local
[fabiand@tee ~]$ cat /etc/hostname 
tee.local
[fabiand@tee ~]$ hostname
tee.local

^^ Correct

[fabiand@tee ~]$ grep hosts /etc/nsswitch.conf
#hosts:     db files nisplus nis dns
hosts:      files mdns4_minimal [NOTFOUND=return] dns myhostname mymachines

Let#s see if you nsswitch.conf is different.

Comment 10 Lukáš Nykrýn 2016-05-04 13:24:27 UTC
For example

[root@notas ~]# cat /etc/os-release | head -2
NAME=Fedora
VERSION="22 (Twenty Two)"
[root@notas ~]# grep ^host /etc/nsswitch.conf
hosts:      files dns myhostname
[root@notas ~]# hostname -f
notas
[root@notas ~]# grep ^host /etc/nsswitch.conf
hosts:      files dns
[root@notas ~]# hostname -f
hostname: Name or service not known

Comment 11 Red Hat Bugzilla Rules Engine 2016-05-05 00:08:50 UTC
Bug tickets must have version flags set prior to targeting them to a release. Please ask maintainer to set the correct version flags and only then set the target milestone.

Comment 12 Red Hat Bugzilla Rules Engine 2016-05-05 00:08:50 UTC
Target release should be placed once a package build is known to fix a issue. Since this bug is not modified, the target version has been reset. Please use target milestone to plan a fix for a oVirt release.

Comment 13 wanghui 2016-05-05 03:08:55 UTC
[root@dhcp-10-187 ~]# hostnamectl set-hostname tee.local
[root@dhcp-10-187 ~]# hostname -f
hostname: Name or service not known
[root@dhcp-10-187 ~]# grep hosts /etc/nsswitch.conf
#hosts:     db files nisplus nis dns
hosts:      files dns

Comment 14 Fabian Deutsch 2016-05-06 08:33:37 UTC
Okay, I see that on CentOS/RHEL myhostname is not part of the default hosts nsswitch line.

Adding it solves teh issue:

# grep hosts /etc/nsswitch.conf
hosts: files dns

## MODIFY nsswitch.conf

# grep hosts /etc/nsswitch.conf
hosts: files dns myhostname

# hostname -f
localhost
# hostnamectl set-hostname too
# hostname -f
too

We nowknow th cause.

Lukas, in upstream Fedora myhostname is already used.
Do you know if it's planned to also introduce this in RHEL?

Comment 15 Lukáš Nykrýn 2016-05-09 10:28:48 UTC
We already append myhostname to the nsswitch.conf in %post section of our specfile.

Comment 16 Fabian Deutsch 2016-05-10 12:29:42 UTC
Lukas, on a centos 7 host I don't see myhostname in /etc/nsswitch.conf

Comment 17 Lukáš Nykrýn 2016-05-10 12:44:48 UTC
I am sorry but I don't know how I can help you, on all my rhel7 machines the myhostname is used. Maybe centos made some changes, or you are using an image where this was removed.

Comment 18 Fabian Deutsch 2016-05-10 15:35:29 UTC
*** Bug 1334735 has been marked as a duplicate of this bug. ***

Comment 19 Red Hat Bugzilla Rules Engine 2016-05-11 16:07:51 UTC
Bug tickets must have version flags set prior to targeting them to a release. Please ask maintainer to set the correct version flags and only then set the target milestone.

Comment 20 Red Hat Bugzilla Rules Engine 2016-05-12 17:02:40 UTC
Bug tickets must have version flags set prior to targeting them to a release. Please ask maintainer to set the correct version flags and only then set the target milestone.

Comment 21 Fabian Deutsch 2016-05-17 20:34:44 UTC
Created attachment 1158522 [details]
Screenshot showing the nsswitch.conf status (no myhostname) after a minimal RHEL 7.2 installation.

I did a clean minimal installation using the rhel-server-7.2-x86_64-boot.iso.

Right after installation myhostname is missing from /etc/nsswitch.conf.

Note: nsswitch.conf contains my hostname after running yum update and receiving an systemd update.

Comment 22 Fabian Deutsch 2016-05-17 20:37:00 UTC
Moving this back to systemd according to comment 21.

Comment 24 Lukáš Nykrýn 2016-05-18 07:15:23 UTC
So lets try this: /etc/nsswitch.conf is owned by glibc, maybe in rhel they could add there myhostname by default, which could be more reliant and we could drop the sed from our %post section.

Comment 25 Harald Hoyer 2016-05-18 09:28:56 UTC
(In reply to Lukáš Nykrýn from comment #24)
> So lets try this: /etc/nsswitch.conf is owned by glibc, maybe in rhel they
> could add there myhostname by default, which could be more reliant and we
> could drop the sed from our %post section.

Well, it would be interesting to know, _why_ it fails.

Is there a /etc/nsswitch.conf.bak ?
Does anaconda write /etc/nsswitch.conf?
Would it be better in %posttrans?
Does the scriptlet work?

Comment 26 Lukáš Nykrýn 2016-05-18 10:03:35 UTC
I think the problem will be either in anaconda or that sed is not present at the point when the scriptlet is run. I was thinking about the posttrans as a second solution. But I still thinks that this is the preffered setup for rhel we should not add in in systemd scriplets.

Comment 27 Fabian Deutsch 2016-05-18 10:56:58 UTC
Is there a /etc/nsswitch.conf.bak ? Yes
It does not look like anaconda is writing nsswitch.conf.
But maybe some other component is rewriting it after systemd touched it.

Comment 28 Fabian Deutsch 2016-05-18 11:14:26 UTC
It can actually be authconfig which is overwriting nsswitch.conf.

Comment 29 Fabian Deutsch 2016-05-18 11:21:39 UTC
Tomas, can you imagine a flow where myhostname could be dropped from the hosts line?

Comment 30 Tomas Mraz 2016-05-18 11:24:39 UTC
Authconfig does not support myhostname in nsswitch.conf in RHEL-7. That support was added later in Fedora only.

Comment 31 Fabian Deutsch 2016-05-18 12:01:13 UTC
Ah, so we finally found the root cause :)

Tomas, can this patch get backported to RHEL 7.2.z?

Comment 36 Fabian Deutsch 2016-05-18 19:15:51 UTC
Created attachment 1159048 [details]
Screenshot illustrating the oVirt problem

Just for reference (because I'll have forgotten about this in 2days): The problem is that the own hostname can not be resolved during hosted-engine-setup.

Comment 49 errata-xmlrpc 2016-11-04 06:47:42 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://rhn.redhat.com/errata/RHBA-2016-2462.html