25.6. Generating a new unique MAC address
In some case you will need to generate a new and unique
for a guest. There is no command line tool available to generate a new MAC address at the time of writing. The script provided below can generate a new MAC address for your guests. Save the script to your guest as
. Now from that directory you can run the script using
. and it will generate a new MAC address. A sample output would look like the following:
# macgen.py script to generate a MAC address for Red Hat Virtualization guests
mac = [ 0x00, 0x16, 0x3e,
random.randint(0x00, 0xff) ]
return ':'.join(map(lambda x: "%02x" % x, mac))
Another method to generate a new MAC for your guest
You can also use the built-in modules of
python-virtinst to generate a new MAC address and
UUID for use in a guest configuration file:
# echo 'import virtinst.util ; print\
virtinst.util.uuidToString(virtinst.util.randomUUID())' | python
# echo 'import virtinst.util ; print virtinst.util.randomMAC()' | python
The script above can also be implemented as a script file as seen below.
# -*- mode: python; -*-
print "New UUID:"
import virtinst.util ; print virtinst.util.uuidToString(virtinst.util.randomUUID())
print "New MAC:"
import virtinst.util ; print virtinst.util.randomMAC()