How does a NIC inside a VM get a MAC address assigned?

Hi, 

If you add a NIC to a VM, it needs a MAC address that should be unique (at least in the network segment) to avoid duplicate MAC conflicts.

In the properties for the VM you choose between a Dynamic or Static assignment. In case you select a Static MAC, it is your responsibility that they are unique.

 

As this is a FAQ, let me explain how your VM’s get a dynamic MAC address:

 

Each host has a pool of MAC Addresses. By default the Pool holds 256 Addresses, and when asked gives them out in a Round Robin fashion.

The address range is generated when the Hyper-V Role is added, based on the IP Address of the Hyper-V host. Also see https://blogs.technet.com/b/jhoward/archive/2008/07/15/hyper-v-mac-address-allocation-and-apparent-network-issues-mac-collisions-can-cause.aspx

 

The Pool is controlled by the following values:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Virtualization

MinimumMacAddress, MaximumMacAddress

 

The last given Address is:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Virtualization\Worker

CurrentMacAddress

 

So the MAC address has 3 bytes fixed “00-15-5d”, followed by 2 bytes specific to the current host, and one byte as the individual MAC in this Pool.

 

This algorithm works fine on a standalone host until you create less than 256 NIC’s. Due to the Round Robin method, addresses are given out again.

 

Every time a VM is started, the dynamic MAC address assigned to the NIC is checked against this pool. If the MAC is outside of this pool, a new MAC is taken from the Pool and assigned to the NIC.

Again, this check is done during VM startup only. Not after a LiveMigration or VM resume. Unfortunately, your MAC Pool might get exhausted earlier when you frequently restart the VMs on a different Host, due to this check.

 

 

Knowing this, you might go and check the remaining MAC addresses on your host, ensure it hasn’t wrapped already, and you might consider to enlarge the Pool, or use static MAC Addresses.

 

If you are using SCVMM, it has a default Pool of 1024 MAC Addresses. If you choose to set a static MAC Address from inside SCVMM, you can “Generate” one out of the SCVMM Pool.

 

Cheers

Robert

Comments

  • Anonymous
    June 14, 2011
    Hello! Do you know where are those mac's stored for each VM?  I suppose that each nic will take it's MAC just once and not every time the VM starts. Thanks!

  • Anonymous
    June 24, 2011
    The MAC is stored in the machines XML config file. But as said the value is checked on each restart of the VM and corrected in case the range does not match

  • Anonymous
    November 16, 2012
    hi is there some way to check the given MACs history for a VM??? Thanks