Virtualbox port forwarding on a Linux Host

An excellent article on the subject: Source.

Run these 3 commands from shell. SUDO not required.

VBoxManage setextradata “name of vm” “VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/HostPort” 2222

VBoxManage setextradata “name of vm” “VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/GuestPort” 22

VBoxManage setextradata “name of vm” “VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/Protocol” TCP

Where…

  • name of vm” is your virtual machine name
  • ssh is the name of the service. This is _required_ to be unique among the three commands.
  • Ports 2222, 22, TCP respectively with your desired host port, guest port, and protocol.

…then shutdown your VM and Virtualbox host application, and restart them.

To Confirm the above settings are in place:

VBoxManage getextradata “name of vm” enumerate

To remove the settings made above from the VM: (again substituting the variables as appropriate).

VBoxManage setextradata “name of vm” “VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/HostPort”

VBoxManage setextradata “name of vm” “VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/GuestPort”

VBoxManage setextradata “name of vm” “VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/Protocol”

Leave a Reply