Configure Virtualbox guest with static IP, SSH and internet access from host

virtualbox

I have an Ubuntu Server 12 virtualbox guest running on a Windows 7 host which has a dynamic IP (and I don't wanna change this considering it's a laptop and I'm changing network frenquently).

I want to have a static IP for my VM and a SSH access from my host but I still want to have the internet access on my VM.

I tried added a second host only adapter and configured /etc/network/interface to set eth1 to a static ip, but I can't connect via SSH to it.

Setting only adapter1 to host only works for SSH and static IP but I lose the internet access.

Best Answer

Having two virtual adapters, one set to NAT and the other to Host-only, is the correct way to proceed. You may have had firewall or other connectivity issues with the guest is my guess.

Could you provide a little more information? The Host-only adapter should work with DHCP by default - though static IP addresses are fine too as long as it matches the configuration in your VirtualBox preferences. The screenshot below shows how my Host-only network is configured - any valid address in the 192.168.56.1-99 range should be acceptable for static use.

VirtualBox Host-only network configuration

You can find the network configuration under File -> Preferences (Ctrl+G), then selecting the Network section and clicking the "screwdriver" button to view/alter the configuration for the selected network.