|
|
|
|
|
|
|
|
|
|
xen-users
Re: [Xen-users] slightly less random random macs
Tim Post wrote:
Hello all,
There's been many posts lately about problems that stem from either
duplicate macs, non static macs and other networking issues that would
be averted if a mac was specified upon vm creation.
I've been using this little function I wrote in my shell scripts that
setup dom-u's from a csv file and its worked rather well, lets you
control the prefix and characters used in making the mac.
As far as I know there is no "standard" mac prefix to denote a virtual
nic.
I seem to recall that the xen folks requested a mac prefix for virtuals
and was awarded "00:16:3e:xx:xx:xx".
Anyway here's the snippet / function which is very self explanatory and
should work with bash / dash / etc. This can be accomplished with python
using only a few lines of code, but bash seems more widely used when
creating back end helpers.
Hope someone finds it of use.
Best,
-Tim
# creates a random mac address and sets a global _MAC variable
# to contain it.
makemac()
{
# edit prefix to suit, ideally matches the manufacturer
# prefix of the type of nic your using.
local prefix="00:00:6d"
local hextet[3]=""
local hextet[4]=""
local hextet[5]=""
local tmp=""
local i=3;
# these characters are used in making the mac
local digi='0a1b2c3d4e5f6789h'
local offset=$((${#digi} - 1))
_MAC="$prefix"
while [ "$i" -le 5 ]; do
tmp[1]="${digi:$(($RANDOM%${offset})):1}"
tmp[2]="${digi:$(($RANDOM%${offset})):1}"
hextet[$i]="${tmp[1]}${tmp[2]}"
_MAC="${_MAC}:${hextet[i]}"
let "i += 1"
done
unset octet
unset tmp
unset prefix
}
# When done, the variable $_MAC will contain the generated mac address.
Sample use :
#!/bin/sh
echo "I will make a mac address."
makemac
echo "The MAC address is ${_MAC}, Have a nice day."
unset _MAC
exit 0
_______________________________________________
Xen-users mailing list
Xen-users@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-users
|
|
|
|
|