The Computer Oracle

How to get VirtualBox VMs to use host's DNS?

--------------------------------------------------
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Life in a Drop

--

Chapters
00:00 How To Get Virtualbox Vms To Use Host'S Dns?
00:48 Answer 1 Score 6
01:26 Accepted Answer Score 131
01:54 Answer 3 Score 7
02:22 Answer 4 Score 3
02:50 Thank you

--

Full question
https://superuser.com/questions/641933/h...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#networking #virtualbox #dns #virtualization

#avk47



ACCEPTED ANSWER

Score 131


To enable DNS Proxy Mode using the host's resolver, run the following command:

VBoxManage modifyvm "<VM name>" --natdnshostresolver1 on

As a result, guest OS DNS requests will be intercepted and resolved using host DNS API, rather than having guest OS connect to external DNS servers as with --natdnsproxy1 on.

You can get the name of the VM by running VBoxManage list runningvms.




ANSWER 2

Score 7


This was a top Google result, so I wanted to clarify for others. Josiah's solution worked for me with the addition of adding the line:

hosts: files dns to /etc/nsswitch.conf

As others pointed out, the original solution does not work above Ubuntu 16.04. My guest VM is Ubuntu 16.04.

Reference Creating Linux Server




ANSWER 3

Score 6


Yes it is possible. There are many modes available in VirtualBox to establish networking between the guest and the host. Rather than using the NAT mode (which is default), you can use the bridge-mode in which your guest machine can be treated as entirely separate entity on your network. So, not only your host, but any other machine (such as your DNS server) will see your guest as a separate machine.

Once you setup the bridge-mode, just go to your ubuntu guest and get it to use your company's DNS server name or ip. Read this tutorial for more info: http://prahladyeri.wordpress.com/2012/08/02/how-to-setup-a-virtual-lan-on-your-machine-using-oracle-virtualbox/




ANSWER 4

Score 3


I've also noticed my VPN connection interferes with vagrant internet connection.

Thanks to this stackexchange, I was able to resolve by embedding into my Vagrantfile

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

And avoided the tedium of having to shutdown box to modify via command line, then reprovision

export PATH=$PATH:/c/Program\ Files/Oracle/VirtualBox/
VBoxManage list runningvms
export vbox=`VBoxManage list runningvms | cut -d '"' -f 2`
VBoxManage controlvm $vbox poweroff
VBoxManage modifyvm $vbox --natdnshostresolver1 on
vagrant.exe up --provision