【问题标题】:Could not resolve hostname, ping works无法解析主机名,ping 正常
【发布时间】:2013-02-10 02:28:13
【问题描述】:

我已经安装了 RasPi Raspbian,现在我不能做 ssh 或 git clone,似乎只能解析本地主机名。然而 ping 工作:

pi ~ $ ssh test.com
ssh: Could not resolve hostname test.com: Name or service not known

pi ~ $ git clone gitosis@test.com:test.git
Cloning into 'test'...
ssh: Could not resolve hostname test.com: Name or service not known
fatal: The remote end hung up unexpectedly

pi ~ $ ping test.com
PING test.com (174.36.85.72) 56(84) bytes of data.

我通过使用http://github.com 而不是git://github.com 为 github 解决了这个问题,但这不正常,我想找出问题所在。

谷歌搜索类似问题,但提供的解决方案要么是错字更正,要么是向主机文件添加域。

【问题讨论】:

  • 如果可以ping通,请尝试使用IP地址。 git clone gitosis@174.36.85.72:test.git。我还要看看 nslookup test.com 以确保它正确解析。
  • 当然我可以使用 IP 地址,但我想一劳永逸地修复它。最重要的是 - 了解导致它的原因。

标签: networking


【解决方案1】:

这听起来像是 DNS 问题。尝试切换到另一个 DNS 服务器,看看它是否有效。

OpenDNS

  • 208.67.222.222
  • 208.67.220.220

GoogleDNS

  • 8.8.8.8
  • 8.8.4.4

【讨论】:

  • 谁能想到!使用 nslookup 后,我看到有一些递归:;; Got recursion not available from 203.144.206.49, trying next server,更改为 Google DNS 修复了它。谢谢!
  • 哈哈,它有时会发生,尤其是当一件事似乎奏效时。很高兴你成功了!
  • 在我的例子中,我已经在 /etc/resolv.conf 中添加了打击线:nameserver 8.8.8.8 nameserver 8.8.4.4
【解决方案2】:

如果您安装了网络管理器

检查 /etc/nsswitch.conf

如果你有一条线

hosts:          files mdns4_minimal [NOTFOUND=return] dns mdns4

remove the **[NOTFOUND=return]**

restart /etc/init.d/networking

the [NOTFOUND=return] prevents futher lookups if the first nameservwe doesn't respond correctly

【讨论】:

    【解决方案3】:

    有同样的错误,我只需要指定一个文件夹:

    localmachine $ git pull ssh://someusername@127.0.0.1:38765
    ssh: Could not resolve hostname : No address associated with hostname
    fatal: The remote end hung up unexpectedly
    
    localmachine $ git pull ssh://someusername@127.0.0.1:38765/
    someusername@127.0.0.1's password:
    

    那个错误信息只是误导。

    【讨论】:

      【解决方案4】:

      尝试重置 DNS 客户端解析器缓存的内容。 (对于 Windows)启动命令提示符并输入:

      ipconfig /flushdns
      

      如果您是 linux 或 mac 用户,他们有自己的方式刷新 dns。

      【讨论】:

        【解决方案5】:

        这可能是代理的问题。请取消设置并尝试。

        git config --global --unset http.proxy
        git config --global --unset https.proxy
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2021-05-18
          • 2018-07-14
          • 2017-03-26
          • 1970-01-01
          • 2013-11-05
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多