在 Ubuntu 17.04 中,ping 无法解析主机名,但 nslookup 可以

在 Ubuntu 17.04 中,ping 无法解析主机名,但 nslookup 可以

那么,ping真的不使用DNS吗?

以下是我的情况:

$ nslookup maroon
Server:         192.168.2.102
Address:        192.168.2.102#53

maroon  canonical name = coral.
Name:   coral
Address: 192.168.2.102

$ dig maroon
;; ANSWER SECTION:
maroon.                 0       IN      CNAME   coral.
coral.                  0       IN      A       192.168.2.102

一切看起来都很好。现在:

$ ping maroon
ping: maroon: Name or service not known

但 ping IP 成功。因此,正如avahi:ping 无法解析主机名,但 nslookup 可以,我做了一个strace ping,它的输出附在底部,来自 Ubuntu 17.04 zesty。

下列的 ”Ping 无法找到主机,但 NSLookup 解析正常“,我也关闭了IPV6:

$ cat /proc/sys/net/ipv6/conf/all/disable_ipv6
1

但问题仍然存在。
请帮忙。

PS.strace ping输出:

7062  open("/sys/fs/kdbus/0-system/bus", O_RDWR|O_NOCTTY|O_CLOEXEC) = -1 ENOENT (N
o such file or directory)
7062  socket(AF_LOCAL, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0) = 5
7062  getsockopt(5, SOL_SOCKET, SO_RCVBUF, [212992], [4]) = 0
7062  setsockopt(5, SOL_SOCKET, SO_RCVBUFFORCE, [8388608], 4) = -1 EPERM (Operation not permitted)
7062  setsockopt(5, SOL_SOCKET, SO_RCVBUF, [8388608], 4) = 0
7062  getsockopt(5, SOL_SOCKET, SO_SNDBUF, [212992], [4]) = 0
7062  setsockopt(5, SOL_SOCKET, SO_SNDBUFFORCE, [8388608], 4) = -1 EPERM (Operation not permitted)
7062  setsockopt(5, SOL_SOCKET, SO_SNDBUF, [8388608], 4) = 0
7062  connect(5, {sa_family=AF_LOCAL, sun_path="/var/run/dbus/system_bus_socket"}, 33) = 0
7062  getsockopt(5, SOL_SOCKET, SO_PEERCRED, {pid=1, uid=0, gid=0}, [12]) = 0
7062  clock_gettime(CLOCK_MONOTONIC, {416062, 201194451}) = 0
7062  fstat(5, {st_mode=S_IFSOCK|0777, st_size=0, ...}) = 0
7062  getsockopt(5, SOL_SOCKET, SO_ACCEPTCONN, [0], [4]) = 0
7062  getsockname(5, {sa_family=AF_LOCAL, NULL}, [2]) = 0
7062  geteuid()                         = 0
7062  sendmsg(5, {msg_name(0)=NULL, msg_iov(3)=[{"\0AUTH EXTERNAL ", 15}, {"30", 2}, {"\r\nNEGOTIATE_UNIX_FD\r\nBEGIN\r\n", 28}], msg_controllen=0, msg_flags=0}, MSG_DONTWAIT|MSG_NOSIGNAL) = 45
7062  gettid()                          = 7062
7062  getrandom("B\t\26\262\335\6\f\33\337\321C\250\374\2779|", 16, GRND_NONBLOCK) = 16
7062  clock_gettime(CLOCK_MONOTONIC, {416062, 201935158}) = 0
7062  clock_gettime(CLOCK_MONOTONIC, {416062, 202039305}) = 0
7062  recvmsg(5, 0x7ffdff00f5e0, MSG_DONTWAIT|MSG_NOSIGNAL|MSG_CMSG_CLOEXEC) = -1 EAGAIN (Resource temporarily unavailable)
7062  clock_gettime(CLOCK_MONOTONIC, {416062, 202205684}) = 0
7062  ppoll([{fd=5, events=POLLIN}], 1, {24, 998989000}, NULL, 8) = 1 ([{fd=5, revents=POLLIN}], left {24, 998979401})
7062  clock_gettime(CLOCK_MONOTONIC, {416062, 202392820}) = 0
7062  recvmsg(5, {msg_name(0)=NULL, msg_iov(1)=[{"OK 46f9158405c271efea96759d59263"..., 256}], msg_controllen=0, msg_flags=MSG_CMSG_CLOEXEC}, MSG_DONTWAIT|MSG_NOSIGNAL|MSG_CMSG_CLOEXEC) = 52
7062  clock_gettime(CLOCK_MONOTONIC, {416062, 202572558}) = 0
7062  sendmsg(5, {msg_name(0)=NULL, msg_iov(1)=[{"l\1\0\1\0\0\0\0\1\0\0\0m\0\0\0\1\1o\0\25\0\0\0/org/fre"..., 128}], msg_controllen=0, msg_flags=0}, MSG_DONTWAIT|MSG_NOSIGNAL) = 128
7062  clock_gettime(CLOCK_MONOTONIC, {416062, 202751135}) = 0
7062  recvmsg(5, 0x7ffdff00f540, MSG_DONTWAIT|MSG_NOSIGNAL|MSG_CMSG_CLOEXEC) = -1 EAGAIN (Resource temporarily unavailable)
7062  clock_gettime(CLOCK_MONOTONIC, {416062, 202897197}) = 0
7062  ppoll([{fd=5, events=POLLIN}], 1, {24, 999038000}, NULL, 8) = 1 ([{fd=5, revents=POLLIN}], left {24, 997085204})
7062  clock_gettime(CLOCK_MONOTONIC, {416062, 205068245}) = 0
7062  recvmsg(5, {msg_name(0)=NULL, msg_iov(1)=[{"l\2\1\1\r\0\0\0\1\0\0\0E\0\0\0\6\1s\0\10\0\0\0", 24}], msg_controllen=0, msg_flags=MSG_CMSG_CLOEXEC}, MSG_DONTWAIT|MSG_NOSIGNAL|MSG_CMSG_CLOEXEC) = 24
7062  recvmsg(5, {msg_name(0)=NULL, msg_iov(1)=[{":1.59975\0\0\0\0\0\0\0\0\5\1u\0\1\0\0\0\10\1g\0\1s\0\0"..., 77}], msg_controllen=0, msg_flags=MSG_CMSG_CLOEXEC}, MSG_DONTWAIT|MSG_NOSIGNAL|MSG_CMSG_CLOEXEC) = 77
7062  sendmsg(5, {msg_name(0)=NULL, msg_iov(2)=[{"l\1\2\1 \0\0\0\2\0\0\0\242\0\0\0\1\1o\0\31\0\0\0/org/fre"..., 184}, {"\0\0\0\0\6\0\0\0maroon\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 32}], msg_controllen=0, msg_flags=0}, MSG_DONTWAIT|MSG_NOSIGNAL) = 216
7062  clock_gettime(CLOCK_MONOTONIC, {416062, 205502630}) = 0
7062  recvmsg(5, {msg_name(0)=NULL, msg_iov(1)=[{"l\4\1\1\r\0\0\0\2\0\0\0\225\0\0\0\1\1o\0\25\0\0\0", 24}], msg_controllen=0, msg_flags=MSG_CMSG_CLOEXEC}, MSG_DONTWAIT|MSG_NOSIGNAL|MSG_CMSG_CLOEXEC) = 24
7062  recvmsg(5, {msg_name(0)=NULL, msg_iov(1)=[{"/org/freedesktop/DBus\0\0\0\2\1s\0\24\0\0\0"..., 157}], msg_controllen=0, msg_flags=MSG_CMSG_CLOEXEC}, MSG_DONTWAIT|MSG_NOSIGNAL|MSG_CMSG_CLOEXEC) = 157
7062  recvmsg(5, 0x7ffdff00f670, MSG_DONTWAIT|MSG_NOSIGNAL|MSG_CMSG_CLOEXEC) = -1 EAGAIN (Resource temporarily unavailable)
7062  clock_gettime(CLOCK_MONOTONIC, {416062, 205942095}) = 0
7062  ppoll([{fd=5, events=POLLIN}], 1, {44, 999560000}, NULL, 8) = 1 ([{fd=5, revents=POLLIN}], left {44, 131613738})
7062  recvmsg(5, {msg_name(0)=NULL, msg_iov(1)=[{"l\3\1\1<\0\0\0.\241\3\0f\0\0\0\5\1u\0\2\0\0\0", 24}], msg_controllen=0, msg_flags=MSG_CMSG_CLOEXEC}, MSG_DONTWAIT|MSG_NOSIGNAL|MSG_CMSG_CLOEXEC) = 24
7062  recvmsg(5, {msg_name(0)=NULL, msg_iov(1)=[{"\6\1s\0\10\0\0\0:1.59975\0\0\0\0\0\0\0\0\4\1s\0\"\0\0\0"..., 156}], msg_controllen=0, msg_flags=MSG_CMSG_CLOEXEC}, MSG_DONTWAIT|MSG_NOSIGNAL|MSG_CMSG_CLOEXEC) = 156
7062  rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
7062  close(5)                          = 0
7062  open("/usr/share/locale/locale.alias", O_RDONLY|O_CLOEXEC) = 5

即,在我的 Ubuntu 17.04 zesty 中,似乎ping正在咨询/sys/fs/kdbus/0-system/bus,结果

资源暂时不可用

这似乎是 Ubuntu 17.04 特有的问题,因为我之前在 Ubuntu 16.04 中有相同的设置,当时没有出现问题。

有什么帮助吗?

答案1

尝试更改 /etc/nsswitch.conf,如下所示:

http://stuartfeeser.com/2013/02/11/ubuntu/

相关内容