我对 DNS 的了解很少。尽管如此,为了安装 Wordpress MU 的本地开发副本,我需要创建一个假域名,我将其命名为 local.dev。它和所有子域名都解析为 127.0.0.1。然后 Apache 会指向正确的文件夹。
我安装了 PowerDNS,并让它与 MySQL 后端正常工作。我感觉不太舒服,但既然它能正常工作,我就不再问任何问题了。奇怪的是,它需要互联网连接才能正确解析,现在我需要离线使用它。
如果我处于离线状态,Chrome 会出现以下错误:
Error 105 (net::ERR_NAME_NOT_RESOLVED): The server could not be found.
/etc/hosts
127.0.0.1 localhost
/etc/resolv.conf
nameserver 127.0.0.1
nameserver 8.8.8.8
nameserver 8.8.8.4
当我进行挖掘时,无论在线还是离线,我都会得到同样的东西:
dig local.dev
; <<>> DiG 9.6.1-P2 <<>> local.dev
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 10635
;; flags: qr aa rd; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
;; WARNING: recursion requested but not available
;; QUESTION SECTION:
;local.dev. IN A
;; ANSWER SECTION:
local.dev. 120 IN A 127.0.0.1
;; Query time: 0 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Thu Apr 22 15:32:51 2010
;; MSG SIZE rcvd: 43
nslookup 在任何情况下都找不到 local.dev
nslookup local.dev
;; Got recursion not available from 127.0.0.1, trying next server
;; Got recursion not available from 127.0.0.1, trying next server
Server: 8.8.8.8
Address: 8.8.8.8#53
** server can't find local.dev: NXDOMAIN
PowerDNS 配置(删除了评论):
allow-recursion=127.0.0.1
allow-recursion-override=on
如果您需要更多信息,我很乐意提供。
答案1
听起来您要么需要 DNS 服务器的本地主机条目,要么您的 PowerDNS 设置为在检查其内部数据库之前在外部解析地址。
答案2
忘记 PowerDNS。只需将必要的条目添加到您的 hosts 文件中。如下所示:
127.0.0.1 local.dev
如果您拥有的子域名数量较少,这比尝试维护 DNS 服务要简单得多。
答案3
我刚刚注意到我们也遇到了这种情况。我有几个项目(约 30 个)的主机条目,我正在处理这些项目。例如:
127.0.0.1 localhost.example.com
127.0.0.1 localhost.mydomain.com
127.0.0.1 localhost.some-other-project.net
...等等。
当我没有连接到网络时,我无法在 Google Chrome 中解析这些名称。在 Firefox 和 Lynx 中运行良好。我可以 ping localhost.example.com。看来是 Google Chrome 的 HostResolver 拒绝使用 hosts 文件。
我在 Ubuntu 10.04 上使用 Gogole Chrome 5.0.357.53。(但快速的 Google 搜索表明 Windows 中也存在这种情况)
按照以下步骤进行重现(需要在本地主机上运行并响应“localhost.example.com”的网络服务器):
- 添加主机文件条目:127.0.0.1 localhost.example.com
- 断开网络连接(拔掉网络电缆、关闭无线电
等) - 打开 Google Chrome
- 前往:chrome://net-internals/hostresolver.trace
- 点击“启用追踪”
- 打开新标签页到 localhost.example.com 以查看此错误:
--
Error 105 (net::ERR_NAME_NOT_RESOLVED): The server could not be found.
- 重新加载 chrome://net-internals/hostresolver.trace 选项卡。显示:
--
t=2085005: "Received request r608 for {hostname='localhost.example.com', port=80, priority=1, speculative=1, address_family=0, allow_cached=1, referrer=''}"
t=2085005: "Created job j325 for {hostname='localhost.example.com', address_family=1}"
t=2085005: "Attached request r608 to job j325"
t=2085005: "Starting job j325"
t=2085005: "[resolver thread] Running job j325"
t=2085006: "[resolver thread] Completed job j325"
t=2085006: "Completing job j325 (took 0 milliseconds)"
t=2085006: "Finished request r608 with error=-105"
t=2085207: "Received request r609 for {hostname='clients1.google.com', port=80, priority=3, speculative=0, address_family=0, allow_cached=1, referrer=''}"
t=2085207: "Created job j326 for {hostname='clients1.google.com', address_family=1}"
t=2085207: "Attached request r609 to job j326"
t=2085207: "Starting job j326"
t=2085207: "[resolver thread] Running job j326"
t=2085207: "[resolver thread] Completed job j326"
t=2085207: "Completing job j326 (took 0 milliseconds)"
t=2085207: "Finished request r609 with error=-105"
t=2085869: "Received request r610 for {hostname='localhost.example.com', port=80, priority=0, speculative=0, address_family=0, allow_cached=1, referrer=''}"
t=2085869: "Finished request r610 with error=-105"
t=2085889: "Received request r611 for {hostname='linkhelp.clients.google.com', port=80, priority=2, speculative=0, address_family=0, allow_cached=1, referrer=''}"
t=2085889: "Created job j327 for {hostname='linkhelp.clients.google.com', address_family=1}"
t=2085889: "Attached request r611 to job j327"
t=2085889: "Starting job j327"
t=2085889: "[resolver thread] Running job j327"
t=2085889: "[resolver thread] Completed job j327"
t=2085889: "Completing job j327 (took 0 milliseconds)"
t=2085889: "Finished request r611 with error=-105