BitterSweetJaVa

November 29, 2009

Port forwarding in VirtualBox

Filed under: Operating Systems — Tags: , , — .|2ic|K @ 5:00 PM

Here are useful commands to setup the port forwarding in a VirtualBox VM.

-- Forward local port 8888 to VM port 80 (Apache httpd)
VBoxManage setextradata "Ubuntu" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/httpd/Protocol" TCP
VBoxManage setextradata "Ubuntu" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/httpd/GuestPort" 80
VBoxManage setextradata "Ubuntu" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/httpd/HostPort" 8888

-- Forward local port 9090 to VM port 8080 (Apache Tomcat)
VBoxManage setextradata "Ubuntu" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/tomcat/Protocol" TCP
VBoxManage setextradata "Ubuntu" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/tomcat/GuestPort" 8080
VBoxManage setextradata "Ubuntu" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/tomcat/HostPort" 9090

-- Forward local port 2222 to VM port 22 (SSH)
VBoxManage setextradata "Ubuntu" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/Protocol" TCP
VBoxManage setextradata "Ubuntu" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/GuestPort" 22
VBoxManage setextradata "Ubuntu" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/HostPort" 2222

  • Ubuntu: Represents the name of the VM.
  • pcnet: Represents the driver of the network interface configured in the VM:
    • pcnet corresponds to the PCnet FAST II and PCnet FAST III devices
    • e1000 corresponds to the Intel PRO/1000 devices
  • 0: Represent the network interface number (you can configure multiple network interfaces.
  • “httpd”, “tomcat”, “ssh” are custom (and identifier) names for a particular configuration.
  • Protocol: The protocol to be used, can be TCP or UDP
  • GuessPort: The target port (in our VM)
  • HostPort: The source port (in the PC hosting the VM)

Note: These commands need to be executed from the command line of the host operating system while the VM is off.

Advertisement

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Theme: Shocking Blue Green. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.