我有一台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文件共享
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 -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