Sunday, July 26, 2009

Accessing the guest OS from the host using VirtualBox

To be able to access the guest OS via ssh fro the host, type the following on the host

$ VBoxManage setextradata Centos\ 5.3\ x86\ bis "VBoxInternal/Devices/pcnet/0/LUN#0/Config/SSH/HostPort" 3333
 $ VBoxManage setextradata Centos\ 5.3\ x86\ bis "VBoxInternal/Devices/pcnet/0/LUN#0/Config/SSH/GuestPort" 22
$ VBoxManage setextradata Centos\ 5.3\ x86\ bis "VBoxInternal/Devices/pcnet/0/LUN#0/Config/SSH/Protocol" TCP

(SSH is just a string, you can type anything really). Then you can login to the guest OS by typing this on the host:

$ ssh -p 2222 -X root@localhost

note the same principle applies to other services, example for httpd:

$ VBoxManage setextradata GuestName "VBoxInternal/Devices/pcnet/0/LUN#0/Config/Apache/HostPort" 8888
$ VBoxManage setextradata GuestName "VBoxInternal/Devices/pcnet/0/LUN#0/Config/Apache/GuestPort" 80
$ VBoxManage setextradata GuestName "VBoxInternal/Devices/pcnet/0/LUN#0/Config/Apache/Protocol" TCP

then you can point the host browser to http://localhost:8888. Note that you can’t use a host port lower than 1024 without running VirtualBox with escalated privileges.

To see settings use:

$ VBoxManage getextradata guestname enumerate

To clear a setting (by giving it a clear value) use:

$ VBoxManage setextradata "VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/GuestPort"

No comments: