linux - getaddrinfo 不解析主机名

标签 linux networking dns getaddrinfo

nc -zv cms-01 5061

失败: nc: getaddrinfo: 没有与主机名关联的地址

但是 ping/dig 工作正常。用getent可以看到最不一样的地方:

# getent hosts cms-01
172.17.2.108    cms-01.docker

但是使用“ahosts”而不是“hosts”,它什么都不返回。

# getent ahosts cms-01

"ahosts"和nc 一样使用getaddrinfo,那么为什么它无法解析主机名,即使它存在于dns 中?顺便说一句,如果我使用完整的主机名(“cms-01.docker”与“cms-01”),它不会改变。

最佳答案

域名会导致这种情况,尤其是当您的域名搜索不包括 docker 时。

将此添加到/etc/hosts:

192.168.1.1 terse.domain.com

现在试着查一下:

% getaddrinfo terse
getaddrinfo: Name does not resolve
% getaddrinfo terse.domain.com
dgram inet udp 192.168.1.1 0
stream inet tcp 192.168.1.1 0
seqpacket inet sctp 192.168.1.1 0

将/etc/hosts 更新为:

192.168.1.1 terse.domain.com terse

现在可以了:

% getaddrinfo terse
dgram inet udp 192.168.1.1 0
stream inet tcp 192.168.1.1 0
seqpacket inet sctp 192.168.1.1 0

如果使用 resolv.conf,您可以添加搜索行:

search domain.com docker

关于linux - getaddrinfo 不解析主机名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32338919/

相关文章:

ruby-on-rails - 具有自定义域的 Heroku 中的 SSL

c - 如何用espconn抓取HTTPS请求?

android - 从 Google Play 下载应用程序时,有效负载的 URL 是什么?

linux - 关于 Linux 内存类型的问题

linux - 如何通过程序根据汇编语句获取内存空间中的准确地址

linux - mongodb远程连接问题

php - 并发使用持久化 PHP 套接字

c - 在recvfrom 和socket 之后使用connect

ubuntu - 自指向名称服务器?

linux - 多行变量中导出的含义是什么