VirtualBox command-line - setting up port forwarding

10

2

I know how to configure NAT-based port forwarding using the VirtualBox graphical interface (as in the example below).

How can I do the same via the command line?

Port forwarding via VirtualBox GUI

anol

Posted 2015-04-14T13:14:39.380

Reputation: 1 291

Answers

17

If the machine is powered off, you may use the modifyvm command:

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

If it's powered on, controlvm.

Lyndsy Simon

Posted 2015-04-14T13:14:39.380

Reputation: 286

1Thanks for the natfp<nic number> on controlvm. That helps automating the setup of my VMs. – Jari Turkia – 2018-04-18T11:28:16.147