Setting a static MAC address for a virtual NIC
search cancel

Setting a static MAC address for a virtual NIC

book

Article ID: 317478

calendar_today

Updated On:

Products

VMware vSphere ESXi

Issue/Introduction

I am having a MAC address conflict on one of my virtual machines, or I need to set the MAC address for one of my virtual network adapters manually. Why and how would I do this?

Note: This process detailed in this article applies to ESX 2.5 and earlier. For information on MAC address generation in later versions, see:



Environment

VMware ESX Server 1.x
VMware ESX Server 3.5.x
VMware ESXi 3.5.x Embedded
VMware ESXi 3.5.x Installable
VMware ESXi 4.0.x Embedded
VMware vSphere ESXi 5.0
VMware ESX Server 2.5.x
VMware vSphere ESXi 5.1
VMware ESX Server 2.1.x
VMware vSphere ESXi 5.5
VMware ESXi 4.1.x Installable
VMware ESX Server 1.5.x
VMware ESX Server 2.0.x
VMware ESX 4.1.x
VMware ESXi 4.1.x Embedded
VMware ESX 4.0.x
VMware ESXi 4.0.x Installable
VMware vSphere ESXi 6.0
VMware vSphere ESXi 7.0.x
VMware vSphere ESXi 7.0.0

Resolution

Note: This information applies only to ESX 2.5 and earlier, it is not applicable to ESX 3.0 and later. For information about MAC address management in later releases see the relevant documentation for the version of ESXi/ESX you are using.

MAC address management in VMware ESX 2.5 and earlier

VMware ESX Server automatically generates MAC addresses for the virtual network adapters in each virtual machine. In most cases, these MAC addresses are appropriate. However, there may be times when you need to set a virtual network adapter's MAC address manually. For example:
  • You have more than 256 virtual network adapters on a single physical server.
  • Virtual network adapters on different physical servers share the same subnet and are assigned the same MAC address, causing a conflict.
  • You want to ensure that a virtual network adapter always has the same MAC address.
This document explains how VMware ESX Server generates MAC addresses and how you can set the MAC address for a virtual network adapter manually.
 

How VMware ESX Server Generates MAC Addresses

Each virtual network adapter in a virtual machine gets its own unique MAC address. ESX Server attempts to ensure that the network adapters for each virtual machine that are on the same subnet have unique MAC addresses. The algorithm used by ESX Server puts a limit on how many virtual machines can be running and suspended at once on a given machine. It also does not handle all cases when virtual machines on distinct physical machines share a subnet.

A MAC address is a six-byte number. Each network adapter manufacturer gets a unique three-byte prefix called an OUI - organizationally unique identifier - that it can use to generate unique MAC addresses. VMware has two OUIs, one for automatically generated MAC addresses, and one for manually set addresses.

The VMware OUI for automatically generated MAC addresses is 00:0C:29. Thus the first three bytes of the MAC address that is automatically generated for each virtual network adapter have this value. ESX Server then uses a MAC address generation algorithm to produce the other three bytes. The algorithm guarantees unique MAC addresses within a machine and attempts to provide unique MAC addresses between ESX Server machines.

The algorithm that ESX Server uses is the following:

When the algorithm generates the last 24 bits of the MAC address, the first 16 bits are set to the same values as the last 16 bits of the console operating system's primary IP address.

The final eight bits of the MAC address are set to a hash value based on the name of the virtual machine's configuration file.

ESX Server keeps track of all MAC addresses that have been assigned to network adapters of running and suspended virtual machines on a given physical machine. ESX Server ensures that the virtual network adapters of all of these virtual machines have unique MAC addresses.

The MAC address of a powered-off virtual machine is not remembered. Thus it is possible that when a virtual machine is powered on again it can get a different MAC address.

For example, if a machine had IP address 192.34.14.81 (or in hex, 0xc0220e51) and the configuration file hashed to the value 95, the MAC address would have the following value:
 
00:0C:29:0e:51:95

Since there are only eight bits that can vary for each MAC address on an ESX Server machine, this puts a limit of 256 unique MAC addresses per ESX Server machine. This in turn limits the total number of virtual network adapters in all powered-on and suspended virtual machines to 256. This limitation can be eliminated by using the method described in the next section entitled "Setting MAC Addresses Manually".

Note: The use of parts of the console operating system's IP address as part of the MAC address is an attempt to generate MAC addresses that are unique across different ESX Server machines. However, there is no guarantee that different ESX machines with physical network adapters that share a subnet always generate mutually exclusive MAC addresses.
 

Setting MAC Addresses Manually

To work around both the limit of 256 virtual network adapters per physical machine and possible MAC address conflicts between virtual machines, the MAC addresses can be assigned manually by system administrators. VMware uses a different OUI for manually generated addresses: 00:50:56. To set the addresses open the virtual machine configuration file (.vmx) in a text editor.

Note: The default location is /vmfs/volumes/<datastore_name>/<vm_name>/<vm_name>.vmx.

Add these two lines to the virtual machine's configuration file:
 
ethernet0.addressType = "static"
ethernet0.address = 00:50:56:XX:YY:ZZ

Where XX is a valid hex number between 00 and 3F and YY and ZZ are valid hex numbers between 00 and FF. The value for XX must not be greater than 3F in order to avoid conflict with MAC addresses that are generated by the VMware Workstation and VMware GSX Server products. Thus the maximum value for a manually generated MAC address is:
 
ethernet0.address = 00:50:56:3F:FF:FF

VMware ESX Server virtual machines do not support arbitrary MAC addresses, hence the above format must be used. As long as you choose a hex value that is unique among your hard-coded addresses, conflicts between the automatically assigned MAC addresses and the manually assigned ones should never occur.

Additional Information

For translated versions of this article, see: