MAC addresses for virtual machines

Solution 1:

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.

Solution 2:

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...