【问题标题】:VirtualBox guest cannot resolve host's name, but git canVirtualBox 来宾无法解析主机名,但 git 可以
【发布时间】:2013-10-31 12:20:59
【问题描述】:

我有一台作为 VirtualBox 主机运行的 Mac OS X 机器和一台 Linux Mint 来宾。使用Bridged Adapter,两台机器都可以访问对方的网络服务。

这是设置:

Mac OS X     | hanxue-Mac.local    |   VirtualBox host  
Linux Mint   |      mint15         |   VirtualBox guest

主机的网络连接主要是通过Wifi,所以两个IP地址都是动态的;尤其是主人。由于两台机器都运行了 Samba 和命名守护程序,我想使用主机名而不是 IP 地址来访问机器。这可以通过从同一无线 LAN 上的另一台物理机器访问 Linux Mint 来宾上的 Samba 共享来验证。以下内容已经过验证:

  • 从 hanxue-Mac 访问 mint15 上的 web 服务器
  • 从 mint15 访问 hanxue-Mac 上的 Web 服务器
  • 从 mint15 访问互联网
  • 从 hanxue-Mac 访问 mint15 上的 Samba 文件共享
  • 从同一 LAN 中的单独 Windows 计算机访问 mint15 上的 Samba 文件共享

两种 Samba 访问都使用主机名,而不是 IP 地址。在来宾 (Linux Mint) 中查找 VirtualBox 主机的主机名将失败:

hanxue@mint15 ~ $ nslookup hanxue-Mac
Server:     127.0.1.1
Address:    127.0.1.1#53

** server can't find hanxue-Mac: NXDOMAIN

hanxue@mint15 ~ $ nslookup hanxue-Mac.local
Server:     127.0.1.1
Address:    127.0.1.1#53

** server can't find hanxue-Mac.local: NXDOMAIN

但奇怪的是,我可以使用 VirtualBox 主机的主机名克隆/拉取 git 存储库:

mint15 $ git clone git@hanxue-Mac.local:hanxue-rti-scala.git
Cloning into 'hanxue-rti-scala'...
remote: Counting objects: 26, done.
remote: Compressing objects: 100% (20/20), done.
remote: Total 26 (delta 7), reused 0 (delta 0)
Receiving objects: 100% (26/26), 10.09 KiB, done.
Resolving deltas: 100% (7/7), done.

我已经验证没有~/.gitconfig/etc/gitconfig 并且~/.ssh/known_hosts 中没有包含VirtualBox 主机名的任何内容。当然/etc/hosts 也没有。

git 如何解析主机名以及如何让访客虚拟机解析主机虚拟机的主机名,而无需每次都手动将 IP 地址/主机名键入/etc/hosts

【问题讨论】:

  • git 远程魔法:D。 Git 将远程仓库的地址存储在其数据结构中。在你的 shell 上尝试 git remote -v
  • @BigMike 谢谢!我希望git remote -v 显示 IP 地址,但没有 $ git remote -v origin git@hanxue-Mac.local:hanxue-rti-scala.git (fetch) origin git@hanxue-Mac.local:hanxue-rti-scala repo/.git 中的 .git (push) 文件也不包含 IP 地址。

标签: linux macos networking dns virtualbox


【解决方案1】:

nslookup 的响应中有趣的是您的名称服务器,它似乎是薄荷盒本身:

Server:     127.0.1.1
Address:    127.0.1.1#53

在我的(不可否认的非 Mint)VirtualBox 上,也处于桥接模式,这是我的名称服务器信息的样子:

Server:     192.168.1.1
Address:    192.168.1.1#53

...如果您的 VirtualBox 连接到更广泛的网络,这就是您所期望的。

您似乎正在使用dnsmasqwhich may be used for speedier DNS resolution。但它也可能配置错误,从而导致您的nslookup 失败。我的猜测是git 有效,因为它依赖于sshwhich may not use system DNS at all

当你运行cat /etc/resolv.conf时你会得到什么?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-03
    • 1970-01-01
    • 1970-01-01
    • 2014-04-14
    • 1970-01-01
    相关资源
    最近更新 更多