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).