MAC addresses for virtual machines

19

3

As I understand it, MAC addresses are assigned to every physical device by the manufacturer. By extension, how are MAC addresses assigned to virtual machines - for example if I create a new virtual machine with an ISO of linux assigned?

If it is assigned during creating a new virtual machine - don't we run the risk of having a MAC address assigned that is already in use?

Bendy

Posted 2015-06-25T12:03:53.960

Reputation: 343

That question is better suited for serverfault/superuser. – None – 2015-06-25T15:46:10.983

Answers

18

Yes, the MAC address ranges that are used by virtual machines all over the world are reused.

However, MAC addresses only need to be unique on the local layer 2 network. Anything on the other side of a router doesn't know or care what your local MAC addresses are. Only devices that are connected directly or through switches know each other's MAC addresses.

Inside your network, MAC address conflicts can be a problem. Most hypervisors allow you to set what range of MAC addresses they automatically assign to new virtual machines, so if you have several hosts, you configure them to each use a different range. Care must also be taken to ensure a new MAC address is generated when cloning a virtual machine.

Grant

Posted 2015-06-25T12:03:53.960

Reputation: 1 744

11

how are MAC addresses assigned to virtual machines

They're made up. Oh, not completely; they use specific OUIs (the first 3 octets, sometimes called a vendor ID) to not conflict with known hardware vendors. But they're generated locally, there's no central database or anything like that.

If it is assigned during creating a new virtual machine - don't we run the risk of having a MAC address assigned that is already in use?

Yes, but the risk is pretty low. The OUI should be separate from non-VM devices. Even if we take two VM hosts assigning from the same OUI, there are 2^24 possible choices, or 16777216 possible MAC addresses. Since MAC only matters on the local network, those are generally good odds...

gowenfawr

Posted 2015-06-25T12:03:53.960

Reputation: 1 427

To put that in perspective, the probability of a collision is only about 3% when you have 1000 VMs. http://www.wolframalpha.com/input/?i=1+-+%2816777216+permute+1000%29%2F%2816777216%5E1000%29

– Ajedi32 – 2015-06-25T13:48:22.137

…or, similar to those of winning the lottery ;) – Tetsujin – 2015-06-25T17:39:36.257

2

Typically, the virtualization platform will generate a new, random MAC address for each virtual network interface at creation (depending on the software, you might override that random MAC with one of your chosing).

In the context of ethernet, a MAC addresses only have to be unique on a specific network segment to work so it's actually quite simple to generate statistically unique MACs.

Stephane

Posted 2015-06-25T12:03:53.960

Reputation: 391