VirtualBox – Host SSH to Guest in VirtualBox

virtualbox

I have a mac host, and a VirtualBox Linux guest, currently using Bridged mode.

I need to be able to easily SSH into the guest from the host. It would be nice to use a hostname, but a never-changing IP address would be fine too (currently, the IP changes with each new network I join, and the hostname has never worked).

I also need internet access from the guest.

Other machines on the network do not need access to the guest.

What is the best way to configure my VirtualBox network?

Best Answer

First, you'll have to create the vboxnet0 interface.

VirtualBox > File > Preferences > Network > Host-only Networks > Add (you will get vboxnet0)

Then, run this on the host machine. You'll see a new interface, vboxnet0, appeared.

ifconfig

Shutdown your VM and do:

VM's Settings > System > check "Enable I/O APIC."
VM's Settings > Network > Adapter 2 > host-only vboxnet0

Start VM, on guest run

ifconfig

and check ip

Check these links:

  1. https://forums.virtualbox.org/viewtopic.php?f=8&t=40076
  2. http://www.wiredrevolution.com/virtualbox/setup-ssh-access-between-virtualbox-host-and-guest-vms

There is also solution for NAT but I haven't checked it.

Configuring port forwarding with NAT in your host machine

VBoxManage modifyvm "VM name" --natpf1 "guestssh,tcp,,2222,,22"

connect to your linux via the port 2222 of your host machine

ssh -l -p 2222 localhost

For host-only networking with static ip check this:

https://stackoverflow.com/questions/5906441/how-to-ssh-to-a-virtualbox-guest-externally-through-a-host/27152153#27152153

It's for Solaris 10 and Ubuntu 16.04 but should be easy to adapt.

Related Question