我有一个问题,即从DNS中查找主机名,即使它们存在于/ etc / hosts中.
我有以下配置:
/etc/host.conf档案:
order hosts,bind
/etc/nsswitch.conf中:
hosts: files dns
在/etc/resolv.conf:
nameserver <nameserver one> nameserver <nameserver two>
在主机上运行的应用程序会发出一些内部和外部API请求.
从tcpdump,我看到DNS查询到/ etc / hosts中列出的一些内部服务主机名.我正在使用的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............ ..@.a.root-servers.net..nstld.verisign-grs.com.w.. IP app004-private.33828 > 10.0.80.11.domain: UDP,length 39 E..Ca.@.@.B. .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.....
请注意,localhost正在发送到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`.@.@.C. .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
我很难过.似乎所有东西都正确配置(据我所知)首先使用/ etc / hosts然后使用DNS.有关为什么/etc/nsswitch.conf和/etc/host.conf没有被尊重的任何见解?
在系统上运行的主应用程序是http(apache 2.2.15和PHP 5.3.8 with curl 7.30.0).操作系统是运行内核2.6.18-238.9.1.el5和glibc 2.5-58.el5_6.3的Centos 5.6.
提前致谢!