Tag Archive: virtualbox


In a previous post I have commented about the bridge mode on VirtualBox. Now, I will explain how to access your virtual machine using NAT network mode.

Before start your virtual machine, we have to set these configurations:

$ VBoxManage setextradata diablo "VBoxInternal/Devices/e1000/0/LUN#0/Config/ssh/GuestPort" 22
$ VBoxManage setextradata diablo "VBoxInternal/Devices/e1000/0/LUN#0/Config/ssh/HostPort" 9090
$ VBoxManage setextradata diablo "VBoxInternal/Devices/e1000/0/LUN#0/Config/ssh/Protocol" TCP

  • diablo is the name of the virtual machine
  • e1000 is the network card of the virtual machine (it can be pcnet – usually when host machine is not a genuine Intel)
  • ssh is the name of the service (you can choose any name)
  • 22 is the port of the service inside the virtual machine
  • 9090 is the port that will be binded in host machine
  • TCP is the protocol used by the service (SSH)

PS.: It’s not necessary to be root to apply these configurations.

Let’s see if the virtual machine is configured correctly:

$ VBoxManage getextradata diablo enumerate
Key: GUI/AutoresizeGuest, Value: on
Key: GUI/Fullscreen, Value: off
Key: GUI/LastCloseAction, Value: powerOff
Key: GUI/LastWindowPostion, Value: 56,35,720,451
Key: GUI/MiniToolBarAlignment, Value: bottom
Key: GUI/MiniToolBarAutoHide, Value: on
Key: GUI/SaveMountedAtRuntime, Value: yes
Key: GUI/Seamless, Value: off
Key: GUI/ShowMiniToolBar, Value: yes
Key: VBoxInternal/Devices/e1000/0/LUN#0/Config/ssh/GuestPort, Value: 22
Key: VBoxInternal/Devices/e1000/0/LUN#0/Config/ssh/HostPort, Value: 9090
Key: VBoxInternal/Devices/e1000/0/LUN#0/Config/ssh/Protocol, Value: TCP

It seems OK. Now start your virtual machine and run the command bellow in host machine:

$ netstat -anl | grep 9090
tcp        0      0 0.0.0.0:9090            0.0.0.0:*               LISTEN

How you see, when the virtual machine is started, the VirtualBox binds the GuestPort forwarding all connections to HostPort inside the virtual machine.

To access the virtual machine just run the command bellow :

$ ssh -p 9090 localhost

If you wish access some service of the host machine through the virtual machine (assuming you are using NAT mode), just access it by the IP address 10.0.2.2.

My 2 cents.

In this post I’ll show how to configure a VirtualBox appliance with bridge network on a Gentoo linux.

First, we’ll need tunctl to create a TUN/TAP device and brctl to setup a ethernet bridge:

emerge sys-apps/usermode-utilities
emerge net-misc/bridge-utils

Now, just add the lines bellow to your /etc/conf.d/net:

####################
# VirtualBox Bridge
####################
config_eth0="null"

tuntap_vbox0="tap"
tunctl_vbox0="-u <user>"
config_vbox0="null"

rc_need_br0="net.vbox0"
bridge_br0="vbox0 eth0"
config_br0="172.16.1.2/24"
routes_br0="default via 172.16.1.1"

brctl_br0="setfd 0 sethello 0 stp off"
  • Change “<user>” by the your user, i.e., the user that will use the VirtualBox.
  • The host machine (your Gentoo linux) will assume the IP address 172.16.1.2
  • If you have more than one vbox appliance that you want to use in bridge mode, just create an additional interface (vbox1, vbox2, etc)  configuration to each vbox host and include these interfaces to the variable bridge_br0

Create a symbolic link to these new interfaces (vbox0 and br0):

ln -s /etc/init.d/net.lo /etc/init.d/net.vbox0
ln -s /etc/init.d/net.lo /etc/init.d/net.br0

Start the new interfaces:

/etc/init.d/net.vbox0 start
/etc/init.d/net.br0 start

Check if the following lines are included in /etc/modules.autoload.d/kernel-2.6:

vboxdrv
vboxnetflt
vboxnetadp

After all infrastructure configuration, now we’ll configure the vbox appliance. Open the VirtualBox program, select the appropriate appliance, go to “Settings“  and change its newtork settings:

Attached to: Bridged Adapter
Name: vbox0

It’s exemplified in figure bellow:

click to enlarge

Now, you can boot the appliance and configure its IP address inside the range (172.16.1.3-172.16.1.254) and access it from the host machine (your Gentoo linux).

Note: this procedure was tested only on VirtualBox 3.1.6


Follow

Get every new post delivered to your Inbox.