Sun xVM VirtualBox on a Mac has been great for running multiple "client" vm's which use NAT networking, but rubbish for running "server" vm's because it wasn't easy to give a vm a real IP address which other machines on the network can connect to.
All this has changed with the introduction of Host Interface Networking for the Mac in VirtualBox 2.0 and this entry attempts to show you how to convert an existing vm configured for NAT networking into a full blown server that I can run Apache on.
So here's my starting setup on my home network:
- Router connected to set-top box: 10.0.1.1
- Host: Mac OS X 10.5.4: 10.0.1.200
- Guest: OpenSolaris 2008.05 : 10.0.2.15 (VirtualBox NAT engine assigned)
The VirtualBox config looks like this:
And the guest sees the world thus:
What I want to do is configure VirtualBox and OpenSolaris to be a server with IP address 10.0.1.199, say.
Step 1. - Reconfigure VirtualBox
Shutdown your guest if it is running and go to the VirtualBox Console GUI.
Here is the Before config:
And here is the After Config:
We changed 2 things:
- Attached to: Host Interface
- Host Interfaces: Airport (I don't use wired Ethernet in my house)
You might also have expected to have to change the NIC to a Server variant such as:
- Adapter Type: Intel PRO/1000 T Server
...but I found that OpenSolaris got stuck during the boot sequence when I did this. (OpenSolaris experts out there, please explain. Random number generation?)
Now boot up the vm.
Step 2 - Configure OpenSolaris
Fat Bloke is not an OpenSolaris expert but he blindly followed the instructions in this excellent Observatory blog as follows:
1 . Set IP address:
pfexec vi /etc/nwam/llp
and change from:
e1000g0 static 10.0.1.199
and restart nwam:
pfexec svcadm restart nwam
2. Get DNS Working:
pfexec vi /etc/resolv.conf
and add the address of the wireless router:
Also tell nsswitch.con to use dns to resolve hosts:
pfexec cp /etc/nsswitch.dns /etc/nsswitch.conf
Configure the default router to be the wireless router:
pfexec vi /etc/defaultrouter
Add the line:
And restart the routing service:
pfexec svcadm restart network/routing-setup
So in summary here is my new OpenSolaris config:
Step 3 - Test it
Test it as a client
Simply firing up Firefox shows that things appear to be working:
And in actual fact Fat Bloke found Host Interface networking to be about xx% faster than NAT networking using exactly the same guest.
Test it as a server
An easy test is simply:
(BTW you can easily add an entry to the Mac /etc/hosts file to give your server a name rather than using the IP address)
from a Mac Terminal window like this:
or why not install a real server application such as an Apache web server, glassfish or whatever.
Here I've installed Sun Secure Global Desktop Software which provides remote access to a server via a browser based interface. I'm accessing it from my Mac, so I have a client and server all contained on one box.
Sun xVM VirtualBox is now great for running client and server vm's on Mac and Solaris hosts. The configuration interface is very simple and the performance improvement over NAT in Fat Bloke's tests is about 30% quicker.
But don't take my word for it