Random MAC address for libvirt

Snippet for generating a random MAC address. Useful if adding interfaces to a libvirt xml define file.

MACADDR="52:54:$(dd if=/dev/urandom count=1 2>/dev/null | md5sum | sed 's/^\(..\)\(..\)\(..\)\(..\).*$/\1:\2:\3:\4/')";
echo $MACADDR
echo "
<interface type='bridge'>
<mac address='$MACADDR'/>
<source bridge='br233'/>
<model type='virtio'/>
</interface>
"

1 Comment

  1. Bookmarks for June 20th through December 13th — Somewhere out there! Said,

    December 13, 2011 @ 1:29 pm

    […] Random MAC address for libvirt — Somewhere out there! – blog: Random MAC address for libvirt: Snippet for generating a random MAC address. Useful if adding interfaces t… […]

RSS feed for comments on this post