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

Apr 29 2009

Damn Small Linux, VirtualBox 2.2, Java

Hello,

A week ago I was thinking about banks autentications, here in Brazil, you have to register your computer to get access to the bank site with your computer. Do this every time you format your hard disk is sux, so i thought, why don’t use a virtual machine with a Damn Small linux and use it to access? It’s a good idea.

I created my virtual machine with virtualbox and downloaded the last version of Damn Small Linux. I started the virtualmachine and i saw it was running from cd. Searching around the internet i discovered it is dedicated to live-cd but you can install it if you want to. In portuguese version I translated this article about how to install damn small linux but in english i don’t have to.

So this is just a tip, if you have to register your computer to do some things, why don’t you install a Damn small linux and use it for this? Other advantage is that you can take it with you, and linux don’t have virus so you don’t have to worry about this kind of security

If you want to install Java to firefox follow this article.

If your mouse don’t work use “xsetup.sh” and choose a mouse that isn’t USB. It works for me, now i have my USB mouse working. (I think it’s something about Virtualmachin)

Matheus

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”