I’ve been a big proponent of hardware virtualization for a long time. I use it every day in testing, development, and production environments. Today I realized that understanding a problem domain too well can lead a person to overlook simple solutions.
I’m using KVM on my production servers right now (for various reasons and with mixed results), but on the desktop I’ve never been able to really find a well rounded solution I like.
In the past, I used Vmware Server. I stuck with it over a couple of revisions, I was very happy with it. However, I was annoyed/disappointed by the recent change to a web-based, client-server architecture. When I first tried it, it was slow, it was buggy. So I jumped ship.
At that time, VirtualBox had just been bought by Sun, and everything about it was new(ish) and different. I liked how it seemed to be less crash-prone. It had an easier to use UI and was snappier. The guest additions were easier to install.
This is where I got stuck. VMware sets up its NAT on a virtual network, so the VMs act like they’re plugged into a virtual router. VirtualBox doesn’t. In Vbox’s case, NAT’tted machines are on a 10.x.x.x network. I believe they can talk to each other, but can’t communicate with the host.
This subtle difference made VirtualBox almost unusable for me. I could set up port forwarding, but there wasn’t a nice UI for it like Vmware had. In fact, it requires a cryptic command line that edits cryptic XML.
I could use bridged networking, which worked OK at home, where I had a wireless router between the VM and the internet, but at work, where we all have static IPs, I had to register the virtual device, and that seemed impractical for a lot of reasons (examples: too many VMs to keep track of, the VMs were no longer sandboxed, etc)
I settled on just setting up port forwarding for port 22 so I could SSH and use SSH tunneling to do any other forwarding I needed. For a 3-client plone site with 3 Apache virtual hosts (SSL, HTTP, and 8080 for the load balancer), that got messy in a hurry. Needless to say I tried to do all of my development on as few VMs as I could.
It was a lot of futzing and difficult work, because, honestly, I ignored the simplest answer.
I just got a new laptop for work, a swank PC to replace an old Mac. For the sake of playing nice, it’s running Windows 7 (yeah, I know). I decided to try VMware again due to the hassles I had with VirtualBox’s networking.
What I wanted was a virtual network that I could connect to a VM through that allowed the VM to get out to the internet. Vmware provided this, VirtualBox did not. (there are other virtualization solutions, I know, but for one reason or another they wouldn’t work for me).
After hours of toil, I realized that Vmware’s NAT doesn’t work in Windows 7 (If you’re on the east coast of the US, you may have heard a faint moan in the distance, that was me screaming into my desk chair when I found that out).
The question I failed to ask before this afternoon was, “Why do they have to the same network?”… you know what? They don’t. Eureka!
So the solution, that I’m frankly a little embarrassed at, is use two network connections. One’s configured as NAT, to provide Internet access and sandboxing, and the other is a Host Only connection, which creates a nice little 192.x.x.x network that you can connect to from the host (but not from outside of the host machine).
Here’s what it looks like (the adapters have to be added while the VM is shut down, or when its initially created):
I suppose this is evidence that time wasted is never more valuable than knowledge gained (at least, while you’re wasting time to gain it).