linux-ping,ssh等使用的IP地址与nslookup,主机,

新安装Ubuntu15.10后,我的命令(ping,ssh,…)使用的IP地址与nslookup,host,dig,…解析的IP地址不同.
怎么会这样

user@ubuntu-15-10:~$nslookup foobar.com
 Server:        127.0.1.1
 Address:   127.0.1.1#53

 Non-authoritative answer:
 foobar.com canonical name = foobar.homeip.net.
 Name:  foobar.homeip.net
 Address: 12.34.56.78

user@ubuntu-15-10:~$host foobar.com
 foobar.com is an alias for foobar.homeip.net.
 foobar.homeip.net has address 12.34.56.78

user@ubuntu-15-10:~$ping foobar.com
 PING foobar.com (192.168.1.3) 56(84) bytes of data.
 64 bytes from foobar.localdomain.home (192.168.1.3): icmp_seq=1 ttl=64 time=0.245 ms
 64 bytes from foobar.localdomain.home (192.168.1.3): icmp_seq=2 ttl=64 time=0.285 ms
 64 bytes from foobar.localdomain.home (192.168.1.3): icmp_seq=3 ttl=64 time=0.269 ms
 ^C
 --- foobar.com ping statistics ---
 3 packets transmitted, 3 received, 0% packet loss, time 2000ms
 rtt min/avg/max/mdev = 0.245/0.266/0.285/0.021 ms

user@ubuntu-15-10:~$

我的/etc/resolv.conf

# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 127.0.1.1
search localdomain.home

我的/etc/nsswitch.conf

# /etc/nsswitch.conf
#
# Example configuration of GNU Name Service Switch functionality.
# If you have the `glibc-doc-reference' and `info' packages installed, try:
# `info libc "Name Service Switch"' for information about this file.

passwd:         compat
group:          compat
shadow:         compat

hosts:          files mdns4_minimal [NOTFOUND=return] wins dns
networks:       files

protocols:      db files
services:       db files
ethers:         db files
rpc:            db files

netgroup:       nis

在/ etc / hosts中没有foobar.com的条目

有人知道吗?

解决方法:

经过一番调查,我发现了一个修复方法.
问题出在/etc/nsswitch.conf中:
在“主机”行:“ dns”条目应在“ wins”条目之前…
我不明白背后的原因,但是现在它的工作方式与预期的一样

上一篇:linux – Docker如何在/etc/resolv.conf中使用已定义的名称服务器启动容器


下一篇:5.k8s基本命令汇总