Friday, September 7, 2007

Customizing VMware Network Subnets

VMware Server is a great, currently free tool for creating a virtual computer environment, great for testing various operating systems and configurations, or for operating within a protected Sandbox.

One area where I feel that VMware Server could use some improvement involves the configuration of its virtual network segments on the host. During installation, the VMware installer creates 2 virtual network adapters, "VMnet1" and "VMnet8". Additional adapters can be configured for a total of up to 8 virtual networks. The default VMnet1 is a "host only" network, with no communication paths outside of the host computer and any virtual machines. The default VMnet8 is a "NAT" network, hosting a NAT service to share the host computer's network connection and default gateway.

Both the VMnet1 and VMnet8 networks are configured by default with 2 different, private random Class C networks, with the pattern of 192.168.x.0, where x is a random byte. As the Wikipedia article states, "Classful" networks are obsolete in favor of Classless Inter-Domain Routing (CIDR). Rather than having VMware configure itself to 8-bit boundaries and 24-bit prefixes, I figured I should be able to configure the VMware networks with variable-length subnet masking. Unfortunately, VMware doesn't provide a clear configuration path to accomplish this. Documentation is equally lacking, even within the VMware knowledge base and forums.

Before attempting to change the VMware network configuration, it is good practice to stop all related VMware Windows services. They can be restarted after configuration changes are complete:

  • VMware Authorization Service ("VMAuthdService")
  • VMware Registration Service ("vmserverdWin32", dependent on and will stop automatically with the above Authorization Service)
  • VMware DHCP Service ("VMnetDHCP")
  • VMware NAT Service ("VMware NAT Service")

This example calls for configuring VMnet1 to 192.168.192.0/25 and VMnet8 to 192.168.192.128/25. There are 3 places where configuration is needed:

  • The host network adapters:

    The typical TCP/IP configuration of the host adapters, accessed from "Network and Dial-up Connections". See Microsoft's page for details, if needed.

    For VMnet1, use IP Address 192.168.192.1, Subnet 255.255.255.128, and no default gateway. For VMnet8, use IP Address 192.168.192.129, Subnet 255.255.255.128, and no default gateway.

  • The registry:

    HKLM\SOFTWARE\VMware, Inc.\VMnetLib\VMnetConfig, subkeys vmnet1 and vmnet8. Each should already have an IPSubnetAddress String value. Set vmnet1's to 192.168.192.0 and vmnet8's to 192.168.192.128. Missing, and undocumented as far as I can tell, are the IPSubnetMask String values. Microsoft/Sysinternals' Regmon was useful in determining this value. Create new String values for each network subkey, and set both to 255.255.255.128.

    Also hidden away is HKLM\SYSTEM\CurrentControlSet\Services\VMnetDHCP\Parameters\VirtualEthernetSegments\x\HostIpAddress, where 'x' is '1' or '8', the number of the VMnet interface. These values are DWORDs, the 4 bytes stored as hexadecimal in reverse-byte order. I.E., 192.168.192.1 for VMnet1 is 0x01c0a8c0. Alternatively, the undocumented vnetlib tool in the VMWare Server program folder can be used, which automatically updates this and some of the other values: vnetlib -- update dhcp vmnetx, replacing vmnetx with the proper vmnet-name.

  • The file system:

    %AllUsersProfile%\Application Data\VMware\. The vmnetdhcp.conf file needs to be edited, with the pertinent changes highlighted:

    vmnetdhcp.conf:

    #
    # Configuration file for VMware port of ISC 2.0 release running on
    # Windows.
    #
    # This file is generated by the VMware installation procedure; it
    # is edited each time you add or delete a VMware host-only network
    # adapter.
    #
    # We set domain-name-servers to make some clients happy
    # (dhclient as configued in SuSE, TurboLinux, etc.).
    # We also supply a domain name to make pump (Red Hat 6.x) happy.
    #
    allow unknown-clients;
    default-lease-time 1800;                # default is 30 minutes
    max-lease-time 7200;                    # default is 2 hours
    
    # Virtual ethernet segment 1
    subnet 192.168.192.0 netmask 255.255.255.128 {
    range 192.168.192.2 192.168.192.126;            # default allows up to 125 VM's
    option broadcast-address 192.168.192.127;
    option domain-name-servers 192.168.192.1;
    option domain-name "localdomain";
    default-lease-time 1800;
    max-lease-time 7200;
    }
    host VMnet1 {
        hardware ethernet 00:50:56:C0:00:01;
        fixed-address 192.168.192.1;
        option domain-name-servers 0.0.0.0;
        option domain-name "";
    }
    # End
    
    # Virtual ethernet segment 8
    subnet 192.168.192.128 netmask 255.255.255.128 {
    range 192.168.192.131 192.168.192.254;            # default allows up to 125 VM's
    option broadcast-address 192.168.192.255;
    option domain-name-servers 192.168.192.130;
    option domain-name "localdomain";
    option netbios-name-servers 192.168.192.130;
    option routers 192.168.192.130;
    default-lease-time 1800;
    max-lease-time 7200;
    }
    host VMnet8 {
        hardware ethernet 00:50:56:C0:00:08;
        fixed-address 192.168.192.129;
        option domain-name-servers 0.0.0.0;
        option domain-name "";
        option routers 0.0.0.0;
    }
    # End
    

    vmnetnat.conf: The ip variable under the [host] section in this file may also need to be edited, though I've not seen this variable take effect either way.

Here is a table describing the IP network layout for both interfaces, using the above configuration:

IP Config VMnet1 VMnet8
Network Subnet Address: 192.168.192.0 192.168.192.128
Network Subnet Mask: 255.255.255.128 255.255.255.128
Network Broadcast Address: 192.168.192.127 192.168.192.255
Network - CIDR Notation: 192.168.192.0/25 192.168.192.128/25
Host IP Address: 192.168.192.1 192.168.192.129
Default Gateway / NAT Server Binding: N/A 192.168.192.130

Restart the services and hopefully everything will work smoothly. Good luck!

Response to the anonymous comment left August 7, 2008 7:21 AM:

Comments such as this make me rethink allowing anonymous comments. Posting anonymously certainly doesn't help credibility.

This post details the free VMware Server edition. Other editions may provide more/better configuration options.

Within VMware Server, the related configuration pretty much allows as follows:

  1. Host Virtual Adapters: This tab simply allows for additions and deletions of virtual adapters. No properties are offered. When added, a random Class C network is configured, with a network ID of 192.168.x.0, where x is a random byte. As described above, further configurations must be made through the Windows properties.
  2. DHCP: Simply allows for configuration of the start and end IP addresses for the leases. Subnet, Netmask, and Broadcast address are all greyed-out/disabled, and must be configured using the methods described above.
  3. NAT: Simply allows for configuration of the Gateway IP address. The Netmask field is the only other IP addressing configuration displayed, and is also greyed-out/disabled. Further configuration must be made using the methods described above.

If I'm missing something, please feel free to email me, or post a more detailed comment as a logged-in user. Links to instructions and/or screenshots would also be noteworthy.

10 comments:

Anonymous said...

Not really sure what you mean by you cannot do this in the GUI of VMWare. I Was able to accomplish this all within the GUI no registry editing or anything like that sounds like you just don't know anything about VMWare.

Mark A. Ziesemer said...

See the update to my post in response to the last anonymous comment.

Anonymous said...

Sorry My Bad mark, Here you go...

This is for VMWare Free Server edition.

Open Your VMWare Server Console.

1. Go to the Menu Host>Virtual Network Settings.

2. Click on the Host Virtual Network Mappings Tab.

3. See the little arrow on the buttons on the right hand side of the virtual adapters. Click Them.

4. They will pop up a menu that will allow you to configure the subnet, dhcp and on the adapter 8 with NAT enabled The Nat services.

5. You can configure all as you stated in your article from these locations. Without the need to edit any registries or conf files.

Cheers...

Mark A. Ziesemer said...

The above anonymous comment is correct.

I may have missed it all along, or it may have been added since an earlier version of VMware Server.

Either way, now you know where these settings are stored, and could use the information to script the process if desired.

(BTW, the correct spelling/capitalization is VMware, not VMWare.)

Anonymous said...

lol.. all this work to have someone say doh you didnt see the gui u noob.

its alright anonymous you were able to accomplish a great things. We are all happy to know you feel better now.

if anyone has a way to script the nat configuration, especially port mapping, that would be really useful.

Unknown said...

Wow that option was well hidden. Thanks anon. Good article Mark.

Anonymous said...

Well done Mark,

I have to add - the methode you describe works very well on VMware Workstation and VMware player, most likely on all VMware editions.
I have been using this for a long time to synchronize VMware installations on multiple systems to simplify the use of virtual machines with fixed IP-addresses. What I dislike about VMware is that you have to redo it after each update.

James said...

Is anyone aware of a utility, or scripts that could do this?

Thanks

Mark A. Ziesemer said...

James - as mentioned in my replies to Mr. Anonymous, this is surely scriptable. vmnetdhcp.conf could probably be edited with some multi-line regular expressions. There are several ways of scripting access and modifications to the registry. Configuring the host network adapters may be the most difficult, but is certainly possible through WMI and possibly other command-line tools. I'd probably choose WSH / JScript, which includes support for everything mentioned, including regular expressions, reading & writing of files, registry access, and WMI.

AlexP said...

Hi Mark, thanks for this helpful info. It is still usable for VMware Player.

After updating to the newest version, the IPs were changed to some stupid random 192.168.219.x network. And VMware Player does not come with any helpful tool to change that back....

-Alex