Quick fix: Generate random MAC-address in bash
If you need too generate a random MAC address for whatever reason - say assigning them to virtual machines or when setting up bridge interfaces - you cay simply do this with bash only.
function genranmac() {
out=""
for i in 0 1 2 3 4
do
out=${out}$(printf %01X $((RANDOM % 256))):
done
out=${out}$(printf %01X $((RANDOM % 256)))
echo -n $out
}
Example:
alex@picobeast:~$ sudo ip link show dev virbr0
4: virbr0: <BROADCAST,MULTICAST> mtu 1500 qdisc noqueue state DOWN mode DEFAULT group default qlen 1000
link/ether 52:54:00:45:04:74 brd ff:ff:ff:ff:ff:ff
alex@picobeast:~$ sudo ip link set addr $(genranmac) dev virbr0
alex@picobeast:~$ sudo ip link show dev virbr0
4: virbr0: <BROADCAST,MULTICAST> mtu 1500 qdisc noqueue state DOWN mode DEFAULT group default qlen 1000
link/ether 4c:a5:fb:4c:dd:ed brd ff:ff:ff:ff:ff:ff
Bonus information: If you want to do it proper, use MAC-addresses from the
experimental/private ranges, such that the 2nd byte of the MAC-address is in
2,6,a,e
, e.g.:
x2:xx:xx:xx:xx:xx
x6:xx:xx:xx:xx:xx
xa:xx:xx:xx:xx:xx
xe:xx:xx:xx:xx:xx