May 18 2009

Forwarding ports to a VirtualBox

Good afternoon,

If you want to forward ports to a virtualmachine in VirtualBox you should do this:

Create an interface “tap”

#sudo tunctl -u $USER

Set the tap address:

#sudo ip addr add 192.168.0.20/32 dev tap0
# sudo ip link set tap0 up

Enable Ip Forward

# sudo sysctl net.ipv4.ip_forward=1

Add route:

#sudo route add -host 192.168.0.150 dev tap0

Create nat:

# sudo iptables –flush
#sudo iptables -t nat –flush
#sudo iptables -t nat -A POSTROUTING –out-interface eth1 -j MASQUERADE
#sudo iptables -A FORWARD –in-interface eth1 -j ACCEPT

Redirecting port 3333 to 3389:

#iptables -t nat -A PREROUTING -i eth1 -p tcp -d 192.168.0.100 –dport 3333 -j DNAT –to 192.168.0.150:3389

eth1 – Ethernet connected to the router.
192.168.0.150 – IP of virtualmachine
192.168.0.20 – IP of tap
192.168.0.100 – IP of my real machine that receive the connections in 3333

After this configure manually your virtualmachine to:

IP: 192.168.0.150
Subnet Mask: 255.255.255.0
Default Gateway: 192.168.0.100

I had problems with ‘–’ so here is a file with the commands: Forward ports to a virtualmachine.

Hope this is usefull,
Matheus

References:
IPtables Tutorial
IPTables Port Redirect
VirtualBox, com nat
VBoxManage Port Forward

May 14 2009

Install Windows 7 in a VirtualBox

Hello,

Today in class one of my teachers was using Windows 7 as your “main” operational system. He said “Windows 7 never crashed”. So i decided to try it too in VirtualBox.

You have to access Microsoft Windows 7 page. Download the version you want to use. You will have to fill a form and then you will receibe a mail confirmation. When you confirm it you will be able to access a page with the link location and your cd-key.

Open your Virtual box go to “New”, choose a name. Change the options to Windows, version Windows 7 (32/64). Create, set the memory size. Create a new Virtual HardDisk. (I used 15GB). Start it, choose the image file and start the installation.

(Installation is so easy, i will not comment it here.)

Matheus

PS: I know I haven’t published regularly in the last days, but I’m sick (flu) and I’m testing some stuff that take a lot of time like IPV6.

Apr 25 2009

Ubuntu, VirtualBox 2.2 and USB

Hello,

Now, with this new version of ubuntu, i will post alot about it while I’m trying configurations. I don’t want to teach how to install VirtualBox 2.2, because it’s a package .deb and is so easy to install it (Download Sun VirtualBox). In this post I want to remember that we should select the option “Enable IO APIC” in “Settings – General – Advanced”. (My version of WinXp doesn’t work without it). So if you system is not booting, verify this option. Now let’s go to enable USB in your Virtual machine.

You have to install “Guest Additions”, use the menu “Devices – Install Guest Additions”. (Don’t forget to mount it on your cd in virtualbox)

After you install it go to console:

$ grep vbox /etc/group
The result is something similar to this: vboxusers:x:gid:user

(If your user is not there, add it “System – Administration – Users and groups”)

Edit the file “mountkernfs.sh”:
$ sudo pico /etc/init.d/mountkernfs.sh

Go to the end of do_start(), and before the } add this line:
domount usbfs “” /proc/bus/usb usbdevfs -onoexec,nosuid,nodev,devgid=GID,devmode=644

(Replace the GID with your GID)

Save the file, reboot the computer and use your usb in your virtualmachine.

The site that make me try this way is http://www.davidgrant.ca/virtualbox_usb_windows_xp_guest_ubuntu_hardy. This website don’t says it works on Ubuntu 9.04 (Jaunty), so i tried and it worked.

I hope this is useful,
Matheus

PS: You have to select the device you want to use in virtual machine in “Device – USB DEVICES”