虚拟机中的VirtualBox客户机无法解析主机名,但Git可以。

3

我有一台Mac OS X机器作为VirtualBox主机,另外一台机器是Linux Mint。通过使用“桥接适配器”,两台机器都能够访问彼此的网络服务。

以下是设置:

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

主机的网络连接主要通过Wifi实现,因此两个IP地址均为动态的,尤其是主机。由于两台机器都安装了Samba和命名守护进程,所以我希望使用主机名而不是IP地址来访问这些机器。从同一无线局域网中的另一台物理机器上访问Linux Mint客户端上的Samba共享已得到验证。以下已经得到验证:
  • 从hanxue-Mac访问mint15上的Web服务器
  • 从mint15访问hanxue-Mac上的Web服务器
  • 在mint15上访问互联网
  • 从hanxue-Mac访问mint15上的Samba文件共享
  • 从同一局域网中的单独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 如何解析主机名?我该如何让客户 VM 能够解析主机 VM 的主机名而不是每次手动输入 IP 地址/主机名到 /etc/hosts 中?

git remote magik :D。Git在其数据结构中存储远程仓库的地址。请在您的shell上尝试使用git remote -v。 - BigMike
@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.git (push)repo/.git 中的文件也没有包含 IP 地址。 - Hanxue
1个回答

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连接到更广泛的网络,那么这就是你所期望的。

看起来你正在使用dnsmasq它可以用于更快速的DNS解析。但它也可能被错误配置,因此导致nslookup失败。我猜想git能够工作是因为它依赖于ssh它可能根本不使用系统DNS

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


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接