Recently I copied a script from user deltaray to generate random local MAC addresses for virtual machines. I like this script because it's the easiest and most effective bash script for generating a MAC address.
However, all available private MAC addresses have four different OUI octets available for use, and my question is:
How to randomize the first set of octets for private MAC addresses and never have to worry about colliding with another VM?
x2-xx-xx-xx-xx-xx
x6-xx-xx-xx-xx-xx
xA-xx-xx-xx-xx-xx
xE-xx-xx-xx-xx-xx
Where the "x" in x2, x6, xA and xE are randomized.
I did modify deltaray's script for a static private MAC address, but I would like to be thorough and have the best solution, and not just a single solution.
My mods:
#!/bin/bash
hexchars="0123456789ABCDEF"
mac=$( for i in {1..10} ; do echo -n ${hexchars:$(( $RANDOM % 16 )):1} ; done | sed -e 's/\(..\)/:\1/g' )
echo 02$mac
Thank you
Please see the answer to my question below.