how to direct ports on a virtualbox guest to the host

In the default virtualbox network configuration, NAT mode, one cannot initiate connections to ports on the guest system. However, one can redirect ports on the host system to the guest. This can be used, for example to provide ssh access to the guest from the host system. The following example demonstrates this method to redirect port tcp/2222 on the host to tcp/22 on the guest named "centosguest". One can then ssh from the host to the guest with + ssh -p 2222 localhost +. Note that the network adapter name, + e1000 +, may vary, and may be named, for instance, + pcnet +.

VBoxManage setextradata centosguest "VBoxInternal/Devices/e1000/0/LUN#0/Config/ssh/Protocol" TCP
VBoxManage setextradata centosguest "VBoxInternal/Devices/e1000/0/LUN#0/Config/ssh/GuestPort" 22
VBoxManage setextradata centosguest "VBoxInternal/Devices/e1000/0/LUN#0/Config/ssh/HostPort" 2222

To check the configuration, use the following command:

VBoxManage getextradata centosguest enumerate