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?
On VirtualBox 6+, --natpf1
is not supported. @Lyndsy Simon's answer has just one change (--natpf1
is just changed to simply natpf1
). Changed command looks like this:
VBoxManage controlvm "VM name" natpf1 "guestssh,tcp,,2222,,22"
Obviously I am making a change in the running VM so I used controlvm
. If the VM is power off mode, use modifyvm
instead.
Now, with VirtualBox 7+, the command-line changed again. It is:
VBoxManage modifyvm "VM name" --nat-pf1="guestssh,tcp,,2222,,22"