Last year, when I worked at Engine Yard, I wrote a blog post on using a Virtual Machine as a local development environment. I built that virtual machine (which is still available on Engine Yard’s S3 account) for students wanting to learn Ruby on Rails without having to set it up.
After the blog post, I received messages and comments from people who were using the Virtual Machine image for every day development. Today I created a virtual machine for the same reasons. Those reasons are:
- Ruby is hard to configure on Windows, and can be nasty elsewhere too.
- My system stays nice and clean
- I can create and destroy as many environments as I want
- I can snapshot an image and go back to it quickly if I mess up along the way
- It’s easy to organize VMs by what I am doing (NodeJS VM, Rails VM, Etc.)
- There are VMs available online to make my life easier
Last year I used VirtualBox to do all of this work, but as an employee of VMWare, I am compelled to eat my own dog food. When it came time to browse the Guest VM website from the host I looked around for Fusion’s Port Forwarding settings, but came up empty handed. Did VirtualBox offer something that Fusion did not?
Maybe. But as I learned more about Fusion, I realized that I didn’t need to use Port Forwarding a year ago and I didn’t need to use it now. Both VirtualBox and Fusion use NAT, which means you just need the guest’s IP to browse from the host.
The only hitch in using NAT is that the guest IP address might change, so you can’t create a host name on the host and type “my-guest” in your browser. And so, let’s make the IP fixed. And let’s create that host name. Then we can use the Ubuntu image and be happy.
Here’s what you do:
Login it your guest.
Open a terminal
Display your routing table:
/sbin/route -n
You should see something like this…
mreider@ubuntu:~$ /sbin/route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 192.168.114.0 0.0.0.0 255.255.255.0 U 1 0 0 eth0 0.0.0.0 192.168.114.2 0.0.0.0 UG 0 0 0 eth0
Edit your network interfaces:
sudo nano /etc/network/interfaces
Add the settings
Find the line iface eth0 inet dhcp and remove it (ctrl-k)
Create a static IP address. It has to be in the range of xxx.xxx.xxx.3 to xxx.xxx.xxx.127 – your current IP will not be in this range as it was assigned via DHCP, but use the same nine numbers (xxx.xxx.xxx)
iface eth0 inet static address 192.168.114.3 netmask 255.255.255.0 network 192.168.114.0 broadcast 192.168.1.255 gateway 192.168.114.2
Restart your network
sudo /etc/init.d/networking restart
Assuming you have a web server running, you should now be able to open a browser from your host and view 192.168.114.3, which is your guest VM’s IP address.
Now let’s create an easy to remember name for the guest.
Open your local hosts file (this is for OSX – for Winblows go here)
sudo nano /etc/hosts
Add your IP and a host name to the bottom and save the file:
192.168.114.3 my-guest









