Search code examples
centoshostname

Why do "hostname" and "hostname -f" return each other's value?


I'm using a Centos8 VM to learn puppet. At first, I only set a short hostname for my VM -- puppet-mst. After some failure-- someone told me puppet needs FQDN to proceed. So I set a long hostname for my vm --

hostnamectl set-hostname puppet-mst.eisen

Then I found something weird --

[root@puppet-mst yum.repos.d]# hostname -f
puppet-mst
[root@puppet-mst yum.repos.d]# hostname
puppet-mst.eisen

"hostname" and "hostname -f" just return each other's values-- "hostname" return the long name while "hostname -f" returns the short one...
 So now -- I can't install foreman on this centos VM -- as it will return error --

[root@puppet-mst yum.repos.d]# foreman-installer -i
2021-11-01 00:22:04 [NOTICE] [root] Loading installer configuration. This will take some time.
2021-11-01 00:22:08 [NOTICE] [root] Running installer with log based terminal output at level NOTICE.
2021-11-01 00:22:08 [NOTICE] [root] Use -l to set the terminal output log level to ERROR, WARN, NOTICE, INFO, or DEBUG. See --full-help for definitions.
Output of 'facter fqdn' is different from 'hostname -f'

Please kind help -- how to set the hostname then made both "hostname" and "hostname -f" return the correct one -- especially "hostname -f" should return the long domainname? Thanks in advance.


Solution

  • After some research, I found it's due to /etc/hosts.

    When it's --

    192.168.160.131 puppet-mst puppet-mst.eisen
    

    the "hostname -f" will return puppet-mst and when it's --

    192.168.160.131 puppet-mst.eisen puppet-mst
    

    the "hostname -f" will return puppet-mst.eisen