Hyper-V and Dynamic MAC Address Regeneration

In my house I have all of my computers and sundry network connected devices configured to use DHCP.  For devices that need to have static IP addresses I use DHCP reservations.

The reason why I do this is that it gives me a single place to look at my entire network configuration, and it allows me to make major network configuration changes easily.

A couple of weeks ago used SCVMM to quick migrate my FTP server from one Hyper-V server to another.  Everything appeared to work correctly.  But two days later I could no longer access the FTP server from an external computer.

After a bit of investigation I discovered that the virtual machines MAC address had changed, which had stopped my DHCP reservation from working, which had in turn stopped my port forwarding configuration on my router from working.

To figure out why this appeared to work at first and then later failed I needed to talk to our developers about when and why dynamic MAC addresses get regenerated in Hyper-V.

Before I explain the root cause – let me define some terms / concepts:

  • With Hyper-V you can configure a virtual machine to use a dynamic or a static MAC address for any given network adapter. 

    The default option is to use a dynamic MAC address – which means that Hyper-V will generate an initial MAC address for the network adapter, and it will regenerate the MAC address if it believes it is necessary. 

    If you use static MAC addresses you need to manually specify the MAC address to use, but Hyper-V will never change it.

  • Each Hyper-V server has a MAC address range that it uses for generating new dynamic MAC addresses.  You can configure this range yourself if you want to.

A dynamic MAC address will get regenerated if:

  • The virtual machine is being turned on and the current MAC address is outside of the MAC address range configured for the current Hyper-V server.

  • The virtual machine is being turned on, or is restored from a saved state, and Hyper-V detects that another virtual machine is already using the specified MAC address.

  • The virtual machine is being turned on, or is restored from a saved state, and Hyper-V detects that the dynamic MAC address value in the virtual machine configuration has been set to zero.

Some more notes about dynamic MAC address regeneration:

  • If a virtual machine is coming back from a saved state and Hyper-V determines that the MAC address needs to be regenerated – the network adapter will be disconnected until the virtual machine is rebooted.  This is done because Hyper-V cannot change the MAC address of a running virtual machine.

  • The only time you should expect to have a virtual machine with the MAC address set to zero is if you have imported the virtual machine and specified that you are copying (and not moving) the virtual machine.

So in my situation – my FTP server was moved to a Hyper-V server with a different MAC address range.  Because the FTP server came across in a saved state; Hyper-V did not regenerate the MAC address until the first time the virtual machine rebooted.  This is why everything appeared to work immediately after the virtual machine was moved – but then stopped working a couple of days later.