linux - 无法从 Linux 中的同一台机器上 ping 通主机名

标签 linux centos redhat centos7

我设置了 2 台 centos7 机器(A 和 B),具有主机名和静态 IP 地址。登录到机器 A。然后尝试使用机器 A 的主机名进行 ping 操作。它正在执行 ping 操作。登录到机器 B,然后尝试使用机器 B 的主机名进行 ping 操作,但未 ping 通。不确定是否遗漏了任何配置。

下面是A机器的输出

[rmdev01@inches-rmdev01 ~]$ cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
<ip address> inches-rmdev01.aaitg.com

[rmdev01@inches-rmdev01 ~]$ cat /etc/hostname
inches-rmdev01

[rmdev01@inches-rmdev01 ~]$ ping inches-rmdev01
PING inches-rmdev01 (<ip address>) 56(84) bytes of data.
64 bytes from inches-rmdev01.aaitg.com (<ip address>): icmp_seq=1 ttl=64 time=0.034 ms
64 bytes from inches-rmdev01.aaitg.com (<ip address>): icmp_seq=2 ttl=64 time=0.082 ms
64 bytes from inches-rmdev01.aaitg.com (<ip address>): icmp_seq=3 ttl=64 time=0.050 ms
64 bytes from inches-rmdev01.aaitg.com (<ip address>): icmp_seq=4 ttl=64 time=0.050 ms

下面是B机器的输出。

[rmtest01@inches-rmtest01 ~]$ cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
<ip address> inches-rmtest01.aaitg.com

[rmtest01@inches-rmtest01 ~]$ cat /etc/hostname
inches-rmtest01

[rmtest01@inches-rmtest01 ~]$ ping inches-rmtest01
ping: unknown host inches-rmtest01

来自机器

[rmdev01@inches-rmdev01 ~]$ hostname
inches-rmdev01
[rmdev01@inches-rmdev01 ~]$ hostname -f
inches-rmdev01

来自B机

[rmtest01@inches-rmtest01 ~]$ hostname
inches-rmtest01
[rmtest01@inches-rmtest01 ~]$ hostname -f
inches-rmtest01.aaitg.com

最佳答案

您应该修改 /etc/hosts 并添加到最后一行短主机名,如下所示:

...
<ip address> inches-rmtest01.aaitg.com inches-rmtest01

或者您必须通过修改/etc/resolv.conf将搜索域指定为aaitg.com

关于linux - 无法从 Linux 中的同一台机器上 ping 通主机名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38451871/

相关文章:

Linux shell 脚本 - 简单的 awk 脚本问题

gcc - 搜索和链接库目录的顺序

PHP无论如何都不能写在文档根目录之外

docker - 在 Openshift 中,我如何使用 CLI 创建具有值为 secret 的环境变量的新构建?

redhat - GNU_LIBC_VERSION 和 GNU_NPTL_VERSION 有什么区别?

C 共享库 : static variable initialization + global variable visibility among processes

linux - 转储 Intel HD Audio 硬件的硬件状态

linux - 如何等待变量的值在特定时间间隔之前设置为 true

unix - GCC 总是尝试使用静态 libc 库而不是共享库

linux - 卡在 RHCSA 练习任务上