Linux – ping can’t resolve hostname, but nslookup can, in Ubuntu 17.04

dnslinuxnetworkingpingUbuntu

So, does ping really don't use DNS?

Here is my case:

$ 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

All look good. Now:

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

But pinging the IP works. So as suggested in avahi: ping can't resolve hostname, but nslookup can, I did a strace ping, and its output is enclosed at the bottom, from Ubuntu 17.04 zesty.

Following "Ping fails to find host but NSLookup resolves okay", I turned off IPV6 as well:

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

But the problem remains the same.
Please help.

PS. The strace ping output:

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

I.e., in my Ubuntu 17.04 zesty, the ping seems to be consulting /sys/fs/kdbus/0-system/bus, which results in

Resource temporarily unavailable

This seems to be a Ubuntu 17.04 specific problem, as I have the same setup in Ubuntu 16.04 before, and there were not problems then.

Any help?

Best Answer

Try changing /etc/nsswitch.conf as shown here:

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

Related Question