ping通本机主机名问题

前提:/etc/hosts文件里面未添加任何主机名记录,/etc/resolv.conf文件也没有配置正确(或不配置)。
现象:在CentOS7上,只修改了本机主机名,ping一下结果通了,很奇怪。
解释:
原来在/etc/nsswitch.conf文件中hosts多了一个项:

#hosts:     db files nisplus nis dns
hosts:      files dns myhostname

就是那个myhostname项,/etc/hosts和dns都解析不到IP时,myhostname就起作用了,它可以把hostname,解析成自己范围内的IP地址,因此就可以ping通了。

可以通过下面命令查看hostname对应的IP:

# 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) 56(84) bytes of data.
64 bytes from centos7-bind-1 (192.168.122.84): icmp_seq=1 ttl=64 time=0.120 ms
64 bytes from centos7-bind-1 (192.168.122.84): icmp_seq=2 ttl=64 time=0.043 ms

nss-myhostname, libnss_myhostname.so.2英文描述:
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 providing hostname resolution for the locally configured system hostname as returned by gethostname(2). The precise hostnames resolved by this module are:

  • The local, configured hostname is resolved to all locally configured IP addresses ordered by their scope, or — if none are configured — the IPv4 address 127.0.0.2 (which is on the local loopback) and the IPv6 address ::1 (which is the local host).

  • The hostname “localhost” is resolved to the IP addresses 127.0.0.1 and ::1.

  • The hostname “gateway” is resolved to all current 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 configuration state.

myhostname详细URL:
http://www.freedesktop.org/software/systemd/man/nss-myhostname.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
YOLO高分设计资源源码,详情请查看资源内容中使用说明 YOLO高分设计资源源码,详情请查看资源内容中使用说明 YOLO高分设计资源源码,详情请查看资源内容中使用说明 YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值