Linux – VirtualBox guest cannot resolve host’s name, but git can

dnslinuxmacosnetworkingvirtualbox

I have a Mac OS X machine running as VirtualBox host, and a Linux Mint guest. Using Bridged Adapter, both machines can access each other's network services.

This is the setup:

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

The host's network connection is mostly via Wifi, so both IP addresses are dynamic; especially the host. Since both machines have Samba and the naming daemon running, I would like to access the machines using hostnames, instead of IP address. This is verified by accessing the Samba shares on the Linux Mint guest from another physical machine on the same Wireless LAN. The following has been verified:

  • Access web server on mint15 from hanxue-Mac
  • Access web server on hanxue-Mac from mint15
  • Internet access from mint15
  • Access Samba file shares on mint15 from hanxue-Mac
  • Access Samba file share on mint15 from a separate Windows machine in the same LAN

Both Samba access uses the hostname, and not IP address. Looking up the VirtualBox host's hostname will fail in the 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

But strangely, I can clone/pull git repositories from the VirtualBox host by using it's hostname:

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.

I have verified that there is no ~/.gitconfig or /etc/gitconfig and nothing in ~/.ssh/known_hosts that contain the VirtualBox host's hostname. Certainly nothing in /etc/hosts too.

How can git resolve the hostname and how can I get the guest VM to resolve host VM's hostname without resorting to manually keying in the IP address/hostname to /etc/hosts every time?

Best Answer

The interesting thing amongst the response from nslookup is your nameserver, which appears to be the Mint box itself:

Server:     127.0.1.1
Address:    127.0.1.1#53

On my (admittedly non-Mint) VirtualBox, also in bridged mode, this is what my nameserver info looks like:

Server:     192.168.1.1
Address:    192.168.1.1#53

...which is what you'd expect if your VirtualBox is connecting to the wider network.

It seems likely that you're using dnsmasq, which may be used for speedier DNS resolution. But it also may be mis-configured, and thus the source of your nslookup failure. My guess is that git works because it relies on ssh, which may not use system DNS at all.

What do you get when you run cat /etc/resolv.conf?

Related Topic