For some reason, NAT quit working for me in Virtual Box. Everything works fine, but the machines won’t connect to the Internet unless I change them to bind to a particular adapter. The problem is that I use different adapters based on my location. At the office, I have a docking station and the network goes through the USB connector. At home, I use wireless. So, when I bind, I have to remember to change the adapter for it to work. If I use NAT, it doesn’t matter.
So, here’s how I found I could fix NAT to work again.
Listing the VMs
First, I need the exact name of images. This will make a nice list of the images:
vboxmanage list vms
Or, this list will also show the network settings.
vboxmanage list --long vms | grep -i '^name:\|^nic [1234567890]*:' | grep -iv disabled
Fixing the NAT
So, let’s assume that my virtual machine is called “My Virtual Machine”. Here’s the command that I found that does the trick:
vboxmanage modifyvm "My Virtual Machine" --natdnshostresolver1 on
Or, I found that I could switch it to NAT from the command-line at the same time:
skp@chestnut:~$ vboxmanage modifyvm "My Virtual Machine" --nic1 nat skp@chestnut:~$ vboxmanage modifyvm "My Virtual Machine" --natdnshostresolver1 on