VirtualBox guest无法解析主机名,但git可以

时间:2013-10-22 14:45:57

标签: linux macos networking dns virtualbox

我有一台运行为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 guest虚拟机上的Samba共享来验证这一点。以下内容已经过验证:

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

两个Samba访问都使用主机名,而不是IP地址。查看VirtualBox主机的主机名将在guest虚拟机中失败(Linux Mint):

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如何解析主机名,如何让guest虚拟机解析主机VM的主机名,而无需每次都手动将IP地址/主机名键入/etc/hosts

1 个答案:

答案 0 :(得分:2)

来自nslookup的回复中有趣的是你的名字服务器,它似乎是Mint盒本身:

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时会得到什么?

相关问题