【发布时间】: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-scalarepo/.git中的 .git (push) 文件也不包含 IP 地址。
标签: linux macos networking dns virtualbox