VirtualBox Host ssh to Guest

Between two Linux machines (a 32-bit Ubuntu host and a 64-bit Ubuntu VM), I managed to get ssh working using this Port Forwarding:

enter image description here

Then from your host system run

ssh -p 5679 127.0.0.1

Substitute 5679 with the "Host Port" entered into the Port Forwarding Rules.


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.

  • http://www.eldemonionegro.com/blog/archivos/2008/05/18/howto-access-a-virtualbox-guest-machine-throught-ssh-or-how-to-port-forwarding

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.


If you don't want to mess around with port forwarding, you can set up a host-only adapter which appears as a host interface and then add an IP address inside that subnet in the guest.

Steps:

  • Create a host-only network in Virtualbox (GUI -> settings -> network). Type ifconfig in the host and see something like vboxnet0 with inet 192.168.50.1
  • in guest, add an IP address: ifconfig eth1 192.168.50.101 netmask 255.255.255.0 up
  • in host, execute ssh [email protected]

Further reading:

  • https://stackoverflow.com/a/10410527/4200039
  • https://web.archive.org/web/20170701174835/http://christophermaier.name/2010/09/01/host-only-networking-with-virtualbox/
  • https://web.archive.org/web/20160523035053/https://muffinresearch.co.uk/howto-ssh-into-virtualbox-3-linux-guests/

Tags:

Virtualbox