【问题标题】:Why do "hostname" and "hostname -f" return each other's value?为什么“hostname”和“hostname -f”会返回对方的值?
【发布时间】:2021-11-04 20:00:10
【问题描述】:

我正在使用 Centos8 虚拟机来学习 puppet。起初,我只为我的虚拟机设置了一个简短的主机名——puppet-mst。在一些失败之后——有人告诉我 puppet 需要 FQDN 才能继续。所以我为我的虚拟机设置了一个长主机名--

hostnamectl set-hostname puppet-mst.eisen

然后我发现了一些奇怪的东西--

[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'

请帮忙——如何设置主机名然后让“主机名”和“主机名-f”都返回正确的——尤其是“主机名-f”应该返回长域名?提前致谢。

【问题讨论】:

    标签: centos hostname


    【解决方案1】:

    经过一番研究,我发现这是由于 /etc/hosts。

    什么时候——

    192.168.160.131 puppet-mst puppet-mst.eisen
    

    “主机名 -f”将返回 puppet-mst 什么时候--

    192.168.160.131 puppet-mst.eisen puppet-mst
    

    “主机名 -f”将返回 puppet-mst.eisen

    【讨论】: