Premise: No host name record is added to the/etc/hosts file, and the/etc/resolv.conf file is not configured correctly (or not configured).
Phenomenon: On the CentOS7, only modified the native hostname, ping the result is a bit strange.
Explain:
Originally in the/etc/nsswitch.conf file, the hosts have one more item:
#hosts: DB Files nisplus NIS DNS
hosts: files DNS myhostname
Is that the Myhostname item,/etc/hosts and DNS are not resolved to the IP, Myhostname is in effect, it can be hostname, resolved to their own range of IP address, so you can ping through.
You can view the IP for hostname with the following command:
# getent ahosts ' hostname '
fe80::f816:3eff:fe26:6d42 STREAM centos7-bind-1
fe80::f816:3eff:fe26:6d42 DGRAM
fe80::f816:3eff:fe26:6d42 RAW
192.168.122.84 STREAM
192.168.122.84 dgram
192.168.122.84 RAW
# ping ' hostname '
ping centos7-bind-1 (192.168.122.84) bytes of data.
Bytes from centos7-bind-1 (192.168.122.84): icmp_seq=1 ttl=64 time=0.120 ms @
bytes from centos7-bind-1 (192.168. 122.84): icmp_seq=2 ttl=64 time=0.043 ms
Nss-myhostname, libnss_myhostname.so.2 English Description:
Nss-myhostname, Libnss_myhostname.so.2-provide hostname resolution for the locally configured system hostname.
Nss-myhostname is a plugin for the GNU Name Service Switch (NSS) functionality of the GNU C Library (glibc) primarily Prov IDing hostname resolution for the locally configured system hostname as returned by GetHostName (2). The precise hostnames resolved by this module is:
The local, configured hostname is resolved to all locally configured IP addresses ordered by their scope, or-if none was Configured-the IPv4 address 127.0.0.2 (which is on the local loopback) and the IPV6 address:: 1 (which is the local hos T).
The hostname "localhost" is resolved to the IP addresses 127.0.0.1 and:: 1.
The hostname "Gateway" is resolved to all of the default routing gateway addresses, ordered by their metric. This assigns a stable hostname to the current gateway, useful for referencing it independently of the current network conf Iguration state.
Myhostname Detailed URL:
Http://www.freedesktop.org/software/systemd/man/nss-myhostname.html