VirtualBox: easily access your NAT configured Guest from the Host
This is a placeholder for the actual post: VirtualBox: give Host-Only access to internet. The post deserved two titles.
This is a placeholder for the actual post: VirtualBox: give Host-Only access to internet. The post deserved two titles.
This post describes a simple trick for VirtualBox to give host-only virtual machines access the internet or access your host from the guest using NAT. The title could also have been: “Easily access your NAT configured virtual machine.”
The original problem or requirements:
Yes, you can use port-forwarding using NAT network interface for the virtual machine. But configuring this is just way to complicate and error prone. A few googles more, and I couldn’t find anything good.
The solution I came up with: configure 2 network interfaces for your Virtual Box host. Simple, isn’t it?
First, we need to make a new network in VirtualBox. You can do this in the GUI preference, which is a bit platform specific, but it’s not easy to miss.
Create a new network in VirtualBox, named like vboxnet2 with following settings (change to suit your needs):
Setup your virtual machine using 2 network adapters. The order doesn’t really matter, but you’ll need one NAT and one Host-Only:
Boot your virtual machine, and configure the network interfaces in your guest OS (same order as previous point):
Guest has access to outside, and host can access services running on guest. This is handy when you have a demo or develop using a service running in the virtual machine, and the virtual machine needs to access the outside world.
(If the above has been posted somewhere else: I was either blind, or it was not visible or indexed enough.)
It took me a while figuring out why in using VirtualBox I couldn’t get network in a machine configured with 2 network adapters. One was set up to be bridged with the host, the other is a host-only one.
The problem was that in CentOS I configured both assuming that eth0 equals to ‘Adapter 1′, and eth1 ‘Adapter 2′. This is not (always?) the case and juggling it again around made it work. Now ‘Adapter 2′ is eth0.
Now off to the real work and playing again with DRBD and MySQL, virtually!
The manual of VirtualBox has a section called Using a raw host hard disk from a guest which explains in detail how to use raw disks from the guest host. However, it’s a bit tricky on Mac OS as you have the disks automatically mounting. Here is a small HOWTO showing how to mount a USB stick (using Mac OS 10.5) so it can be used as the IDE Primary Master in VirtualBox.
Warning: this is probably for more advanced users. Careful what you do with mounting and umounting manually!
Start by inserting the USB stick and see if gets mounted in Finder. If you would Eject the device, it gets u(n)mounted, but you can’t use it anymore in VirtualBox. The trick here is to use diskutil (which replaces disktool) in a Terminal session. I assume the volume (e.g. USB stick) is empty.
Preparing the volume:
To make the volume available to VirtualBox we need to create a VMDK file. This is described fully in the manual, but here it is in a few steps:
At this point, you should have the new Virtual Hard Disk available which you can use to make a new virtual machine. Use the disk you created as the primary hard disk just like you would do with hard disk images.
Some errors you might run into:
A caveat doing the above: you’ll need to remake the VMDK file if the disk is on a different device. This can for example happen when you first insert a DVD, and then the USB Stick. Maybe there is a solution for this using /etc/fstab or similar in Mac OS.
I had to do the above to make an installation on a USB stick. Ubuntu somehow failed during the installation (not sure why..); now I’m trying OpenSolaris.
Whatever you do, make sure your USB Stick is fast: I got a slow, cheap one now and it takes forever to format..
Recent Comments