即使存在于/ etc / hosts中,也存在从DNS查找主机名的问题。
我有以下configuration:
/etc/host.conf档案:
order hosts,bind
/etc/nsswitch.conf中:
hosts: files dns
在/etc/resolv.conf:
nameserver <nameserver one> nameserver <nameserver two>
在主机上运行的应用程序会产生一些内部和外部的API请求。
从tcpdump,我看到一些在/ etc / hosts中列出的内部服务主机名的DNS查询。 我正在使用的tcpdump命令是:
tcpdump -tqAlU -s0 port 53 and host <nameserver one>
在转储我看到像下面这样的请求:
IP 10.0.80.11.domain > app004-private.51308: UDP, length 102 E...I2..>... .P. .........I.1E...:...Q.. localhost............ [email protected].. IP app004-private.33828 > 10.0.80.11.domain: UDP, length 39 E..Ca.@[email protected]. .2. .P..$.5./..3e.......... localhost.site.com..... IP 10.0.80.11.domain > app004-private.33828: UDP, length 96 E..|....>.T; .P. .2..5.$.hU.3e.......... localhost.site.com................-.ns10.dnshost.com...dns.8w.............u.....
请注意,本地主机正在发送到DNS以及localhost.site.com。 localhost的/ etc / hosts条目是:
127.0.0.1 localhost.localdomain localhost
和
IP 10.0.80.11.domain > app004-private.51664: UDP, length 93 E..yx...>.m. .P. .2..5...e.<N2...........api.site.com................-.ns10.dnshost...dns.5w.............u..... IP app004-private.51664 > 10.0.80.11.domain: UDP, length 48 E..L`.@[email protected]. .2. .P....5.8..n............api.site.com.site.com..... IP 10.0.80.11.domain > app004-private.48878: UDP, length 76 E..h&e..>..w .P. .2..5...TQ..............11.80.0.10.in-addr.arpa.............Q............p.... . :...Q. IP 10.0.80.11.domain > app004-private.51664: UDP, length 105 E...VX..>..g .P. .2..5...qJ.n............api.site.com.site.com................-.ns10.dnshost.'.dns.Aw.............u.....
其中api.site.com位于/ etc / hosts中。 运行getent查询api.site.com返回:
$ getent hosts api.site.com 10.36.176.114 api001-private api001-private.site.com api001 api.site.com api
我很难过 一切似乎configuration正确(据我所知)首先使用/ etc / hosts 然后 DNS。 任何有关为什么/etc/nsswitch.conf和/etc/host.conf不被尊重的见解?
在系统上运行的主要应用程序是http(apache 2.2.15和PHP 5.3.8,curl 7.30.0)。 操作系统是运行内核2.6.18-238.9.1.el5和glibc 2.5-58.el5_6.3的Centos 5.6。
提前致谢!
我们可以通过禁用ipv6来解决这个问题。 我们通过将以下内容添加到/etc/modprobe.conf并重新启动来禁用ipv6。
alias net-pf-10 off alias ipv6 off options ipv6 disable=1
重新启动后,我们不再看到/ etc / hosts中列出的主机的DNS查找。
我不清楚为什么这个问题能够解决。
有许多应用程序不使用OS-api来查询名称。 相反,他们做一个明确的DNS查询。
如果发生这种情况 – 他们不会通过parsing器库。
在Linux上,您可以在命令行上执行相同的操作:
host YOURHOST将尝试解决DNS – 无论如何。 gethostip YOURHOST将按照configuration顺序使用已定义的parsing器设置。 它看起来像你的应用程序使用curl库,它有自己的名称parsing设施错综复杂,见例如: