2009-12-10

VirtualBox strange port-80 forwarding

Task: Develop iPhone-adapted webpage in VirtualBox Gnu/Linux virtual machine. Test it from an iPhone. Get up quick.

OS X has a built in Apache. VirtualBox can share folders. Let Apache serve a shared folder, then the iPhone can surf to the Mac and I can develop in Gnu/Linux.

System > Sharing > Web Sharing turns on Apache.

/Library/WebServer/Documents contains index.html.en. Rename to hello.html. Now if you go to localhost you will see a list of files instead of It Works!

Make a folder (I called it vbox-web).

Go to VirtualBox, shared Folders. Add this folder, click make-permanent.

On the virtual machine:
sudo mkdir /mnt/vbox-web
sudo mount -t vboxsf vbox-web /mnt/vbox-web/

Ok, this does not work perfectly, I can't use symlinks and I have to work as a root. But it is a start, I can surf with the iPhone and develop on the virtual machine which is what I wanted.

Apprently from the VirtualBox Faq you should add some parameters to the mount command to make it work better.
Improved command:
sudo mount -t vboxsf -o uid=1000,gid=1000 vbox-web /mnt/vbox-web/

Also, not that if you want to do this each time it should not be added to fstab but to a script (see faq).

VirtualBox how-to access guest (ip, webserver)

I needed to do some iPhone development and the SDK requires Snow Leopard. So I installed it:
Carbon Clone Copier to make a mirror of my internal HD to an external USB Drive.
Remove USB Drive.
Wipe the internal HD.
Install Snow Leopard.
Attach the USB Drive, import settings from it.

Most things went well, however VmWare Fusion 2 did not start. Rather than mess with Fusion, I decided to give VirtualBox a go.
I copied the .vmdk file (inside the virtual machine folder), and imported it to VirtualBox. No problems.
Uninstalled vmware tools, installed VirtualBox tools. Very smooth so far. But I want to develop webpages on Linux in the guest, then access them from the Mac host. And I could not reach the guest from the host.

Here is how I fixed it partially (so far):

Info from virtualbox forum

Add two network cards (first host-only, second NAT) using VirtualBox gui (when guest is turned off).
reboot.
run dhclient as root (on Ubuntu sudo dhclient)

Now the host only gets ip address, see what dhclient outputs as inet for the eth (I also have eth2 (NAT) and eth0 (loopback). Mine was 192.168.56.3

In order to get a stable adress all the time, I want to configure a static ip for my vm. I choose 192.168.56.56 because it is a nice number (and I guess the the dhcp server in Virtualbox will not use it).

Now I edit /etc/network/interfaces

#This is a host-only static interface for VirtualBox
iface eth1 inet static
address 192.168.56.56
netmask 255.255.255.0

reboot.
This does not work. I still have to do sudo dhclient and I get ip 192.168.56.3
Anway, I can live with a dynamic address for a while. And I need to get some work done.

However I found a good link to read when I want to fix this sometime in the future.
Ubntugeek, I think the solution is in here somwhere