TL;DR :
- reboot the VM making sure the VPN status (either connected or disconnected) of the host doesn't change in the meantime;
- let VirtualBox NAT engine intercept the DNS requests and forward them to the host's resolver, that is to use the host's DNS API to query the information and return it to the guest. You set this by:
VBoxManage modifyvm "VM name" --natdnshostresolver1 on
Running a VM in a host connected to a VPN can lead to DNS problems everytime the VPN status changes.
There are two scenarios:
- the VM is spawn in a VPN-connected host and at a certain point the VPN disconnects;
- the VM is spawn in a non-VPN-connected host and at a certain point the VPN connects
1) VPN-connected --> VPN-disconnected
In this case the VM will probably have received a DNS address that is part of the VPN provider network. This will usually be an internal private IP address.
Check the content of cat /etc/resolv.conf
. In my case I get the following:
nameserver 10.8.8.1
<--- This is internal to the VPN Provider network
nameserver 192.168.178.1
<--- This is my home-gateway(router)
Now disconnect the host from the VPN connection:
- the DNS configuration in the VMs doesn't change --> VM will still be
sending DNS requests to destination IP 10.8.8.1 which cannot be
reached as the host is no more connected to the VPN
In more details:
- the packet will be sent to the def GW defined by the VirtualBox NAT
network, source NATTed (with the host IP address), and finally
handled by the host's routing table that will forward it to your
home-gateway.
- Here the packet will be dropped as your home gateway has no entry for 10.8.8.1 in the LAN side (private addresses) and cannot forward it on the WAN side (public addresses) as it a private address.
2) VPN-disconnected --> VPN-connected
In this case the VM won't receive the DNS address that is part of the VPN network provider as the host wasn't connected to the VPN when the VM started.
Check the content of cat /etc/resolv.conf
. In my case I get the following:
nameserver 192.168.178.1
<--- This is my home-gateway(router)
Now connect the host to the VPN connection:
- the DNS configuration in the VMs doesn't change --> VM will still be sending DNS requests to destination IP 192.168.178.1 which cannot be reached (ping to it still works though) as now the DNS request from the VM is being handled by the VPN Tap interface that will forward the packets to the VPN network where 192.168.178.1 (your internal home-gateway IP address) cannot be reached.
In more details:
- the packet will be sent to the def GW defined by the VirtualBox NAT network, sent to the VPN Tap interface that will modify the IP header replacing the VM IP source address with an IP address assigned to the host by the VPN Network, while the destination address remains the DNS address 192.168.178.1.
- this packet is then going to be encapsulated in an outer IP Header that will have the host IP address as source (that btw will be later replaced by source NAT on the home-gateway) and the VPN Server as destination address.
- when the packet reaches the VPN network, it is decapsulated. The destination IP address is now again the DNS address 192.168.178.1 that the VPN Provider Network has no way to reach (unless in the extraordinary conicidence where this is exactly the same IP address used by your VPN network provider for its DNS server).