WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-users

Re: [Xen-users] slightly less random random macs

To: tim.post@xxxxxxxxxxxxxxx
Subject: Re: [Xen-users] slightly less random random macs
From: Mike Wright <xktnniuymlla@xxxxxxxxxxxxxx>
Date: Wed, 29 Nov 2006 11:39:17 -0800
Cc: xen-users@xxxxxxxxxxxxxxxxxxx
Delivery-date: Wed, 29 Nov 2006 11:39:33 -0800
Envelope-to: www-data@xxxxxxxxxxxxxxxxxx
In-reply-to: <1164793951.8377.174.camel@tower>
List-help: <mailto:xen-users-request@lists.xensource.com?subject=help>
List-id: Xen user discussion <xen-users.lists.xensource.com>
List-post: <mailto:xen-users@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-users>, <mailto:xen-users-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-users>, <mailto:xen-users-request@lists.xensource.com?subject=unsubscribe>
References: <1164793951.8377.174.camel@tower>
Sender: xen-users-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Mozilla Thunderbird 1.0.2-6 (X11/20050513)
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

<Prev in Thread] Current Thread [Next in Thread>