Feb 23 2009

Port forwarding from Host to Guest in VirtualBox using NAT

VirtualBox’s GUI doesn’t expose this functionality, but the VBoxManage command line utility does. Before starting, remember to close your virtual machine before changing it’s configuration.

You need five pieces of information:

  • your virtual machine’s name in VirtualBox
  • a descriptive name for your port forward
  • the guest port
  • the host port
  • the protocol to use (TCP or UDP).

These three terminal commands are used to set up the port forward (replace bold sections with your information):
VBoxManage setextradata GuestName “VBoxInternal/Devices/pcnet/0/LUN#0/Config/DescriptiveName/HostPort� HostPort

VBoxManage setextradata GuestName “VBoxInternal/Devices/pcnet/0/LUN#0/Config/DescriptiveName/GuestPort� GuestPort

VBoxManage setextradata GuestName “VBoxInternal/Devices/pcnet/0/LUN#0/Config/DescriptiveName/Protocol� Protocol

For Example:

fenris@thinkbuntu:~/Documents$ VBoxManage setextradata OpenSolaris “VBoxInternal/Devices/e1000/0/LUN#0/Config/SSH/HostPort” 2222
VirtualBox Command Line Management Interface Version 2.1.4
(C) 2005-2009 Sun Microsystems, Inc.
All rights reserved.

fenris@thinkbuntu:~/Documents$ VBoxManage setextradata OpenSolaris “VBoxInternal/Devices/e1000/0/LUN#0/Config/SSH/GuestPort” 22
VirtualBox Command Line Management Interface Version 2.1.4
(C) 2005-2009 Sun Microsystems, Inc.
All rights reserved.

fenris@thinkbuntu:~/Documents$ VBoxManage setextradata OpenSolaris “VBoxInternal/Devices/e1000/0/LUN#0/Config/SSH/Protocol” TCP
VirtualBox Command Line Management Interface Version 2.1.4
(C) 2005-2009 Sun Microsystems, Inc.
All rights reserved.

In this case, you could now connect via SSH to the guest though port 2222 on the host:
ssh -p 2222 localhost

The guest is available from other machines on the network as well though the same port at the host’s IP address (if your firewall allows it).

You can set up as many port forwards as you wish, just keep changing your DescriptiveName value. To remove a port forward, repeat the same three commands again, but without the values:
VBoxManage setextradata OpenSolaris "VBoxInternal/Devices/pcnet/0/LUN#0/Config/SSH/HostPort"
VBoxManage setextradata
OpenSolaris "VBoxInternal/Devices/pcnet/0/LUN#0/Config/SSH/GuestPort"
VBoxManage setextradata
OpenSolaris "VBoxInternal/Devices/pcnet/0/LUN#0/Config/SSH/Protocol"

You can view the configuration for a virtual machine, including port forwards, with this command:
VBoxManage getextradata GuestName enumerate

fenris@thinkbuntu:~/Documents$ VBoxManage getextradata OpenSolaris enumerate
VirtualBox Command Line Management Interface Version 2.1.4
(C) 2005-2009 Sun Microsystems, Inc.
All rights reserved.

Key: GUI/SaveMountedAtRuntime, Value: yes
Key: GUI/LastCloseAction, Value: powerOff
Key: GUI/LastWindowPostion, Value: 231,5,720,447
Key: GUI/Fullscreen, Value: off
Key: GUI/Seamless, Value: off
Key: GUI/AutoresizeGuest, Value: on
Key: VBoxInternal/Devices/e1000/0/LUN#0/Config/SSH/HostPort, Value: 2222
Key: VBoxInternal/Devices/e1000/0/LUN#0/Config/SSH/GuestPort, Value: 22
Key: VBoxInternal/Devices/e1000/0/LUN#0/Config/SSH/Protocol, Value: TCP

One restriction you should be aware of is that you can’t use a host port lower than 1024 without running VirtualBox with escalated privilages.

Extra note: You can always access your host from inside your guest using the IP address 10.0.2.2 if you need to do the reverse of this.


Feb 19 2009

Upgrading OpenSolaris 2008.05 to OpenSolaris 2008.11

fenris@thinkbuntu:~/Documents$ ssh 10.x.x.234
The authenticity of host ’10.x.x.234 (10.x.x.234)’ can’t be established.
RSA key fingerprint is bf:f4:91:6e:29:ce:16:12:7d:a7:71:05:fd:8f:08:7c.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added ’10.x.x.234′ (RSA) to the list of known hosts.
Password:
Last login: Thu Feb 19 11:21:37 2009
Sun Microsystems Inc.   SunOS 5.11      snv_86  January 2008
-bash-3.2$ BUILD=`uname -v | sed -e “s/snv_//” -e “s/[a-z]//”`
-bash-3.2$ pfexec pkg refresh
-bash-3.2$ pfexec pkg install entire@0.5.11-0.${BUILD}
PHASE                                        ACTIONS
Update Phase                                     1/1
Install Phase                                    3/3
-bash-3.2$ pfexec pkg install SUNWipkg@0.5.11-0.${BUILD}
DOWNLOAD                                    PKGS       FILES     XFER (MB)
Completed                                    3/3     270/270     2.91/2.91

PHASE                                        ACTIONS
Removal Phase                                  18/18
Update Phase                                 126/126
Install Phase                                179/179

-bash-3.2$ pfexec pkg install SUNWinstall-libs
PHASE                                          ITEMS
Indexing Packages                            527/527
DOWNLOAD                                    PKGS       FILES     XFER (MB)
Completed                                    1/1         4/4     0.07/0.07

PHASE                                        ACTIONS
Removal Phase                                    6/6
Install Phase                                    5/5
Update Phase                                     4/4
Reading Existing Index                           9/9

Indexing Packages                                1/1
-bash-3.2$ pfexec pkg image-update
Creating Plan

DOWNLOAD                                    PKGS       FILES     XFER (MB)
Completed                                603/603 48770/48770 632.69/632.69

PHASE                                        ACTIONS
Removal Phase                            15487/15487
Install Phase                            27493/27493
Update Phase                             66731/66731
PHASE                                          ITEMS
Reading Existing Index                           9/9
Indexing Packages                            603/603
stage1 written to partition 0 sector 0 (abs 16065)
stage2 written to partition 0, 267 sectors starting at 50 (abs 16115)

A clone of opensolaris exists and has been updated and activated.
On the next boot the Boot Environment opensolaris-1 will be mounted on ‘/’.
Reboot when ready to switch to this updated BE.

—————————————————————————
NOTE: Please review release notes posted at:

http://opensolaris.org/os/project/indiana/resources/relnotes/200811/x86/

—————————————————————————


Get Adobe Flash playerPlugin by wpburn.com wordpress themes