manski's blog

Assign DNS name to virtual machine (here: Parallels Desktop 7)

Assigning a DNS name to a virtual machine can be a convenient thing. Do this is not very complicated, it requires some technical skill though. This tutorial shows how to do this with a Ubuntu 11.10 Linux server running under Parallels Desktop 7 on Mac OS X Lion. The basic principals described in this article work as well for any other combination, but that’s beyond this article (and that’s where your technical skill comes into play).

Requirements

This article assumes that you…

  • … know your way around your operating system (Windows, Mac OS X, …)
  • … know what an IP address is and what’s it used for
  • … have installed a hyper visor (e.g. VMWare, Parallels, or Virtual Box) and created a virtual machine with it.

That’s basically it.

The Goal

The goal is to be able to do something like this:

$ ping ubuntu-server
PING ubuntu-server (10.211.55.2): 56 data bytes
64 bytes from 10.211.55.2: icmp_seq=0 ttl=64 time=0.479 ms
64 bytes from 10.211.55.2: icmp_seq=1 ttl=64 time=0.348 ms
64 bytes from 10.211.55.2: icmp_seq=2 ttl=64 time=0.452 ms

Here, we used the DNS name of our virtual server (called ubuntu-server) to do a ping. We didn’t need to know its IP address – which is the point of using DNS names. So, how does one assign such a name to a virtual server? That’s what this article is about.

The Short Version

If you really know your way around your OS, here’s the short version of what we’re going to do:

  1. Assign a static IP address to the virtual machine (from within the virtual machine; see reasoning below)
  2. Add an entry to the OS’ hosts file

The remainder of this article describes the points above in more detail.

Assign a static IP address

To assign a static IP address (i.e. one that stays the same every time you start your virtual machine) one can think of two ways of doing this:

  1. Let the virtual machine (i.e. the simulated computer) decide what IP address to use.
  2. Let the hyper visor (i.e. the simulating program) decide what IP address to use.

In my opinion that latter would be the cleaner way. Simply tell your hyper visor software what IP address to assign to the virtual machine. Unfortunately that’s no that simple. A virtual machine could itself simulate multiple network adapters where each one would acquire an IP address. Which of these adapters then would the hyper visor assign the static IP address to? That’s probably why none of the hyper visors I used provided an option for this (at least none that’s easily reachable).

So, the way to go is to let the virtual machine (i.e. the simulated computer) decide which IP address to use.

Free some IP addresses (from the DHCP server)

To use an IP address we first need to make sure that there are IP addresses free to be used. By default, at least in Parallels Desktop, the DHCP server take up all available IP addresses in the specified IP range. So let’s change that. (This probably requires all virtual machines to be shut down.)

Parallels Network Settings 1
Parallels Desktop Network Settings 2

In Parallels Desktop, go to the program’s settings (not the settings of the virtual machine), then to Advanced and click on Change Settings... (as shown in the first screenshot). This will open the network settings. There you select the network type you used for your virtual machine (either Shared or Host-Only) and change the last number group of the IPv4 DHCP start address. I’ve set it to 20 in the screenshot above. This will free the first 20 IP addresses (1 – 19) so that they can be used as static IP addresses.

Assign the static IP address in the virtual machine

Next, start the virtual machine you want to assign a name to. Here you need to assign it one of the IP addresses we’ve just freed. This procedure highly depends on the operating system your virtual machine is running. So, I’ve compile a small list of how to do this on some of the popular operating systems:

What to enter:

  • IP address: The IP address you want to assign to the virtual machine. It doesn’t really matter which one you choose as long as it’s not used for any other virtual machine. (You may start with number 1 for the last number block.) In my case, I’ve assigned the address “10.211.55.2” to the virtual machine.
  • Subnet Mask: Should be “255.255.255.0”, unless you know what you’re doing.
  • Gateway: The IP address of the virtual router of your hyper visor. In Parallels Desktop this is the first IP address of the IP range specified in the options. In my case, this is “10.211.55.20” (see the screenshot above).
  • DNS Server: This is usally the same address as the gateway.

Add IP address to hosts

The last step is to add the newly assign static IP address to the hosts file of the host OS (i.e. not the guest OS). Fortunately, this file has the same format on most operating systems (including Windows, Mac OS, and Linux). Only the directory where to find it is different:

The format of the hosts is quite simple. Each line contains of a IP address and the DNS name(s) that are assigned to it. For example:

10.211.55.2  ubuntu-server

On Mac OS X I recommend using TextWrangler. It’s a free text editor for Mac OS X that allows you to edit hidden and locked files (both applies to the hosts file). I’ve created an article for this topic here.

After you’ve changed the hosts file, you may need to run the following command (from the “Terminal”):

$ dscacheutil -flushcache

Now you should be able to ping your virtual machine by using its name rather than its IP address.

5 comments

  1. ryan said:

    thanks, man. this was helpful.

  2. Pingback: How to run Plesk on your local network and access virtual domains on your Mac | The WP Guru

  3. xx said:

    address 10.211.55.2 is reserved on Parallels desktop 10

  4. joelFu said:

    Excellent aport, very helpful, love u page.

  5. lechuan said:

    Thank you! This page was extremely valuable for setting up an Ubuntu test webserver with Parallels.

    Some notes for getting this to work with Parallels 11 and Ubuntu 14.04

    1) You have to have Parallels 11 Pro subscription, otherwise the network settings are not available

    3) For some reason, the suggested settings of Start Address was not working from me. Instead I used a start address of 10.211.55.1, end address of 10.211.55.199, and the following addresses for configuring Ubuntu:

    address 10.211.55.201
    net mask 255.255.255.0
    network 10.211.55.0
    broadcast 10.211.55.255
    gateway 10.211.55.1
    dns-nameservers 10.211.55.1

    3) Once setup, I was getting really frustrated that I could ping the ubuntu server from parallels, but could not ping anything from ubuntu. Once I shut down ubuntu, exited parallels, started parallels, then restarted ubuntu, then everything worked well.

Leave a Reply

Your email address will not be published. Required fields are marked *