blog

Image of a server room. Photo by Taylor Vick on Unsplash

Static Hosting with VMWare

by

Virtualization is one of the many benefits of the excess (metaphorical) horsepower available to us with modern hardware. Need to test against (Windows XP/7/8/NT || Fedora || Mint || Ubuntu || FreeBSD || MacOSX || etc)? Fire up the VM. Need a Linux environment for the packages your server relies on, but need to test in the iPad simulator? VM’s to the rescue.

But let’s look closer at that last example – how do we get at the server running in one VM from the host, or another VM? We might want to test in a specfic OS, or we just might not have any browser’s installed/installable in the VM serving us; and we want a predictable point of access. We want a static ip address.

The following concerns itself with VMWare (particularly VMWare workstation) – I expect you can do something similar with Virtualbox, but I’ve never used it myself – please feel free to hit the comments and contribute if you have!

So, for our example, let’s assume the following:
Host OS: Windows 7
Guest OS: Ubuntu 11.10 (named Ubuntu 11.10 in the vmx configuration file – ie. ‘Ubuntu 11.10.vmx’)

First, head into the VM and determine the MAC of the virtual machine’s ethernet adapter. If you’re running linux, head into the terminal and type:
ifconfig

Look for the HWAddr field in the output from that command, and copy what you see there. It should something like 00:0c:29:c1:90:02.

Now, shut down the guest machine completely, and head to the host machine and find your vmnetdhcp.conf file (on Windows 7, this will likely be in your /programdata/vmware/ directory). On linux, this file will likely be named dhcp.conf, and there may be more than one (one for each virtual ethernet segment). Open it in a text editor.

You should see some blocks that define virtual ethernet segments used by vmware. These will give you an idea of what ip address block to use for the static address. For instance, if you have an ethernet segment defined as:

subnet 192.168.152.0 netmask 255.255.255.0 {
range 192.168.152.128 192.168.152.254;
option broadcast-address 192.168.152.255;
option domain-name-servers 192.168.152.2;
option domain-name "localdomain";
option netbios-name-servers 192.168.152.2;
option routers 192.168.152.2;
default-lease-time 1800;
max-lease-time 7200;
}

Then the first three octets of your address will be 192.168.152. You’ll notice this block reserves .2 for name-servers, and defines the range .128 – .254 for automatic assignation. .1 is also reserved for the host machine. So, we’ll want to specify a static address for the guest machine somewhere between .2 and .127.

Below the ethernet segment declaration block, you should see another block that reserves the .1 address for the host machine. It should look something like:

host VMnet8 {
hardware ethernet 00:0c:29:c1:90:02;
fixed-address 192.168.152.1;
option domain-name-servers 0.0.0.0;
option domain-name "";
option routers 0.0.0.0;
}

We’ll add our static block beneath that, following the same format. The host name must NOT have any spaces in it – thus, if our virtual machine’s name is Ubuntu 11.10, our block will look like:

host Ubuntu11.10 {
hardware ethernet 00:0c:29:c1:90:02;
fixed-address 192.168.152.70;
}

The hardware ethernet field is where you should fill in the HWAddr you copied earlier, and fixed-address is where you should enter your desired static ip.

Now, if you’re host machine is windows, open up a cmd window and type:

net stop VMnetDHCP
net start VMnetDHCP

Restarting this service will cause our changes to take effect. All done! If you’d like, you can alter your hosts file to give this static ip a name. Add a line to make it look similar to the following:

# localhost name resolution is handled within DNS itself.
127.0.0.1 localhost
192.168.152.70 name.lan

That should do it! Being able to host a linux machine in one VM, and test in another has come in handy more times than I can count. Hope you find it helpful too.

+ more