Bug 837069

Summary: hostname -f may not return FQDN
Product: Red Hat Enterprise Linux 6 Reporter: Jim Pirzyk <jim+redhat>
Component: net-toolsAssignee: Jiri Popelka <jpopelka>
Status: CLOSED NOTABUG QA Contact: qe-baseos-daemons
Severity: high Docs Contact:
Priority: unspecified    
Version: 6.5Keywords: Reopened
Target Milestone: rc   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2012-07-03 13:22:12 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:

Description Jim Pirzyk 2012-07-02 16:22:48 UTC
Description of problem:

the 'hostname -f' output may actually be a short hostname output, i.e. the same as the output of 'hostname -s'.

Version-Release number of selected component (if applicable): 1.60-110.el6_2


How reproducible:  Ever time with a config change.


Steps to Reproduce:
1. edit /etc/hosts to not have the FQDN as the first hostname for the IP
2. run 'hostname -f' command, compare to output of 'hostname -s' and 'hostname'
3.
  
Actual results:

pirzyk@centos:~
2>hostname
centos.home.pirzyk.org
pirzyk@centos:~
3>hostname -f
centos
pirzyk@centos:~
4>hostname -s
centos
pirzyk@centos:~
5>g centos /etc/hosts
192.168.1.15	centos centos.home.pirzyk.org centos


Expected results:

Hostname should detect that the output of 'hostname -f' is the same length as 'hostname -s'.  Once this is detected it *could* do one of at least 2 things:

1) Throw an error (return non-zero to the shell) and complain about the configuration error.

2) use other heuristics to find the FQDN, like in the example using the output of 'hostname' command.

Additional info:

MacOSX, FreeBSD and Solaris are immune from this configuration error causing 'hostname -f' to fail.  Solaris does not actually support the -f option and the other 2 just silently ignore it.  They all expect hostname to be set to FQDN.

Comment 2 Jiri Popelka 2012-07-03 13:01:23 UTC
Yes, the '-f' option depends on configuration (/etc/hosts).
See the 'THE FQDN' section in hostname(1).

Try -A,--all-fqdns instead.

Comment 3 Jim Pirzyk 2012-07-03 13:13:24 UTC
Can we get the documentation then fixed that -f will not return fqdn if there is a configuration error?

the man page and -h help both say that FQDN will be returned with -f.  The code can determine that -f will *not* return fqdn, because it is the same result as -s.

       -f, --fqdn, --long
              Display  the FQDN (Fully Qualified Domain Name). A FQDN consists


    -f, --fqdn, --long    long host name (FQDN)


This may be working as designed, but I am asking for the design bug to be resolved.

Comment 4 Jiri Popelka 2012-07-03 13:22:12 UTC
The description of the '-f' option also says:
"See the warnings in section THE FQDN above, and avoid using this option; use hostname --all-fqdns instead."