Virtual Machines with duplicate MAC addresses

I was recently asked if it would be possible for two virtual machines to be automatically assigned the same MAC addresses. Knowing that vCenter handles these assignments and ensures uniqueness, I figured it wouldn’t be possible…but it got me to thinking. Since I have multiple vCenters, what would prevent each vCenter from reusing MAC addresses? My search lead to this KB article: http://kb.vmware.com/kb/1024025 which in turn resulted in this blog post: http://enterpriseadmins.org/blog/scripting/multiple-vcenters-and-mac-address-conflicts/.

Question answered — this would not automatically happen.

A few days later, this same guy shows up with two guest names and one MAC address asking me who actually has that MAC? I check — then double check — only to confirm that both VMs have that same MAC address automatically assigned! One interesting thing to note was that each VM was in fact in a different vCenter.

Thats when I turned to some solid code I remembered seeing from mattboren on the VMware PowerCLI communities page (http://communities.vmware.com/thread/339358). A few slight modifications and I had the super fast code shown below to kick out a list of any duplicate MAC addresses:

[cc lang=”powershell”]
# http://communities.vmware.com/thread/339358
# Modified to find duplicate MAC addresses from virtual machines across vCenter environments.
$myreport = Get-View -ViewType VirtualMachine -Property Name, Config.Hardware.Device -Filter @{“Config.Template”=”False”} | %{
$viewThisVM = $_
$viewThisVM.Config.Hardware.Device | ?{$_ -is [VMware.Vim.VirtualEthernetCard]} | %{
New-Object -Type PSObject -Property @{
VMname = $viewThisVM.Name
NICtype = $_.GetType().Name
MacAddress = $_.MacAddress
AddressType = $_.AddressType
vCenterAPI = $viewThisVM.Client.serviceUrl -replace(“https://”,””) -replace(“:443/sdk”,””)
} ## end new-object
} ## end foreach-object
}
$myreport | group MacAddress |where {$_.Count -gt 1} |select -ExpandProperty Group | Select VMname, vCenterAPI, AddressType, MacAddress, NICtype
[/cc]
Side note, the Client.serviceUrl property was something I found pretty quick…I wouldn’t call that a ‘best practice’ on figuring out which vCenter an object is part of. Also, the code that is removing the https and 443/sdk is a very bad approach and isn’t going to work in all scenarios. I just wanted something quick and dirty to get the info I needed.

The above code showed that the problem was much larger than just 2 virtual machines — I had nearly 50 virtual machines sharing 25 MAC addresses!

After looking into several of the virtual machines, I started seeing a pattern — a pattern I created a few months back. I had moved a bunch of virtual machines from my production vCenter a disaster recovery site vCenter (separated for SRM) on the same network. To limit the amount of downtime, the move was completed by presenting one temporary LUN to hosts in each vCenter, using storage VMotion to move the data, then during a change window the VMs were removed from inventory in production and added to the disaster recovery inventory. Virtual machines were then storage VMotioned to the proper LUNs and the temporary LUN removed. During this move, virtual machines kept their original MAC addresses, but as they had been removed from production inventory, the production vCenter was able to reissue those unused addresses.

There were also a couple examples where a similar approach was used to ‘fail back’ select virtual machines after a disaster recovery test, leaving the production vCenter having MAC addresses generated by the disaster recovery site vCenter.

I have a little more information on this issue — including details on how vCenter generates MAC addressess — that I will share in another post. Stay tuned!

This entry was posted in Scripting, Virtualization. Bookmark the permalink.

5 Responses to Virtual Machines with duplicate MAC addresses

  1. Ed says:

    Been there, done that….

    Each vCenter instance must be assigned a unique ID. Go to vCenter Server Settings, down to the Advanced Settings, and change the instance.id variable. Make sure that no two of your vCenters have the same ID. You need to restart vCenter after changing the unique.id

    There are a few KB articles on this. Start with http://kb.vmware.com/kb/1024025

  2. Roberto says:

    I have the same problem, so when i recover machine from site A to site B the VM doesn’t change the mac address ( right) , but when i create another vm in site A the vcenter don’t find another machine POWERED ON in your DB and assign the same mac address to new VM.

    How can i fix that issue?? So i would like when the machine power on in SITE B from srm the mac address changed with a mac from class that vcenter 2. Is it possible??

  3. Bill says:

    What Ed said. Happened to us when we merged with a company that had the same vCenter unique ID. Had to change several hundred MACs, total PITA.

  4. Roberto says:

    I confirm that Vcenter ID are differente

  5. @Roberto – When you bring a machine up in site B, you could change the network adapter to use a manual MAC address and then reconfigure the adapter back to automatic. This will force vCcenter in Site B to generate a new MAC address.

    Alternatively, if you have a large number of these duplicates, you could use some PowerCLI code like the following which will also force vCenter to regenerate a MAC. You can run this command while the VM is running, but the guest operating system will not be aware of it until you power off/on the VM.

    $thisAdapter = Get-NetworkAdapter VMNAME
    $thisAdapter.ExtensionData.AddressType = "Generated"
    $thisAdapter.ExtensionData.MacAddress = ""
    Set-NetworkAdapter $thisAdapter -confirm:$false
    

Leave a Reply

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

*

Notify me of followup comments via e-mail. You can also subscribe without commenting.