我设置了 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/