86

I am running a fresh install of Linux Mint Nadia (14). I am following the instructions on Vagrant Getting Started but have gotten stuck on the Provisioning. It seems the Vagrant box cannot connect outside and so I can't install anything using either Chef or Puppet.

In the basic Vagrant resolve.conf contains nameserver 10.0.2.3. But with that set I can't ping us.archive.ubuntu.com.

If I change it to 8.8.8.8 then I can ping us.archive.ubuntu.com but it does not stay set, and after a reboot it changes back to 10.0.2.3 - so provisioning fails again.

Ideally I would like for 10.0.2.3 to work on my setup. Failing that I would like a way to permanently change resolv.conf so that I can do provisioning.

techraf
  • 4,163
  • 8
  • 27
  • 44
Rudolf Vavruch
  • 1,215
  • 2
  • 11
  • 16
  • 2
    FYI that I just hit this same problem with the `ubuntu/xenial64` box, and it turned out to be [a bug with the box itself](https://bugs.launchpad.net/cloud-images/+bug/1621393). – Aidan Feldman Sep 17 '16 at 02:56
  • @AidanFeldman same for me. Just switched to `bento/ubuntu-16.04` and DNS works fine without any further fixes. – HenningCash Jan 11 '17 at 16:58

4 Answers4

87

You can work around this issue in one of two ways, both of which are in the VirtualBox manual:

Enabling DNS proxy in NAT mode

The NAT engine by default offers the same DNS servers to the guest that are configured on the host. In some scenarios, it can be desirable to hide the DNS server IPs from the guest, for example when this information can change on the host due to expiring DHCP leases. In this case, you can tell the NAT engine to act as DNS proxy using the following command:

VBoxManage modifyvm "VM name" --natdnsproxy1 on

Using the host's resolver as a DNS proxy in NAT mode

For resolving network names, the DHCP server of the NAT engine offers a list of registered DNS servers of the host. If for some reason you need to hide this DNS server list and use the host's resolver settings, thereby forcing the VirtualBox NAT engine to intercept DNS requests and forward them to host's resolver, use the following command:

VBoxManage modifyvm "VM name" --natdnshostresolver1 on

Note that this setting is similar to the DNS proxy mode, however whereas the proxy mode just forwards DNS requests to the appropriate servers, the resolver mode will interpret the DNS requests and use the host's DNS API to query the information and return it to the guest.

Michael Hampton
  • 237,123
  • 42
  • 477
  • 940
77

Following up on https://serverfault.com/a/453260/14832, if you're using a version 2 Vagrantfile config format, the one which starts:

Vagrant.configure("2") do |config|

Then you might want to add this to that config file:

config.vm.provider :virtualbox do |vb|
  vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
end

If you're using the old config format, but are using Vagrant 1.1+, you can append this at the end of the file:

Vagrant.configure("2") do |config|
  config.vm.provider :virtualbox do |vb|
    vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
  end
end
JonTheNiceGuy
  • 883
  • 7
  • 9
  • 2
    Adding this to my `Vagrantfile` fixed the problem where I could not run `gem install...` without getting silly DNS errors :) Thanks! – Nick Feb 23 '15 at 23:37
  • 2
    did not work for me... not sure what I'm missing – jenkizenki Mar 09 '20 at 19:47
  • @NickHall Check the VM inside if it has static IP assigned; if so -- check the reachablitiy of the nameserver from `/etc/resolv.conf`; if it's `10.0.2.3`, check my answer ;) – P Marecki Jun 12 '20 at 09:55
4

Necromancing this one as in my opinion none of the answers shed any light on the root cause of this problem, which seems quite interesting. For modern context -- the issue also happens with Debian 10, and VirtualBox 6.0.14; after default install of Deb 10 (GUI-less), with one "NAT" adapter (not "NAT Network", but the default "NAT") all seems OK with DNS. Then upon changing /etc/network/interfaces (which seems still relevant in this distro) to static IP:

#iface enp0s3 inet dhcp
iface enp0s3 inet static
address 10.0.2.15
netmask 255.255.255.0
gateway 10.0.2.2

(note -- the VM would have got 10.0.2.15 from dhcp anyway), and powering off/on the VM,

  • DNS does not work (host google.com etc, timeout)
  • can't telnet 10.0.2.3 53 (resolv.conf has nameserver 10.0.2.3, per default after installation).

If I revert to iface enp0s3 inet dhcp and reboot the VM, DNS and telnet 10.0.2.3 53 work.

Now it gets really exciting/bizzare: if you again go for inet static, and just reboot the VM, the DNS & telnet still work OK; only if you do power off/on the VM (via virtualbox), the 10.0.2.3 disappears.

So my guess at the moment is, that VirtualBox automagically turns on the DNS server/proxy at 10.0.2.3 once it gets a dhcp request; and this 10.0.2.3 lives for as long as the VM is not power-off-ed (but can be rebooted).

(I would check this if I knew how to fake a dhcp request on the 10.0.2.0/24; does anyone know how?)

__

Bottom line for those who do want to change IP to static (in the "NAT" adapter): just find a way to paste proper nameserver into /etc/resolv.conf (can be after startup in some init scripts).

P Marecki
  • 161
  • 4
0

On the VagrantVM, try:

resolvectl dns eth0 your_server_dns_ip_address

for example

resolvectl dns eth0 8.8.8.8