[Lxc-users] updated lxc template for debian squeeze - with attachedscript ; )
Jäkel, Guido
G.Jaekel at dnb.de
Fri Feb 25 08:03:55 UTC 2011
Dear John,
> - generate random mac address for the guest so it gets always the same
> lease from a dhcp server
You suggest doing this by
macaddr=$(echo -n 00; hexdump -n 5 -v -e '/1 ":%02X"' /dev/urandom)
I think this is a "little bit to random". The german Wikipedia tells at http://de.wikipedia.org/wiki/MAC-Adresse about a reserved MAC range for private use (sorry, it's not in corresponding the English article):
["Neben der OUI existiert auch ein kleiner Adressbereich (IAB - Individual Address Block), der für Privatpersonen und kleine Firmen und Organisationen vorgesehen ist, die nicht so viele Adressen benötigen. Die Adresse beginnt mit 00-50-C2 und wird von drei weiteren Hex-Ziffern gefolgt (12 Bits), die für jede Organisation vergeben werden. Damit verbleibt der Adressbereich innerhalb der Bits 11 bis 0 nutzbar wodurch 212 = 4096 individuelle Adressen möglich sind."]
Maybe we should take respect to this and we should use
macaddr=$(echo -n "00:50:C2"; hexdump -n 3 -v -e '/1 ":%02X"' /dev/urandom)
for this. Another approach is to derive it from the designated name of the container (i.e. $hostname in terms of the script). Because there might be typical clustering naming schemes based on a name and some digits, I suggest to select the first and the last two characters of the hostname (filled by random for the unlikely case of a hostname shorter than 3 chars)
echo -n "00:50:C2"; echo "${hostname:0:1}${hostname: -2} $(head -c 3 /dev/urandom) " | hexdump -n 3 -v -e '/1 ":%02X"'
-> 00:50:C2:<first>:<nextlast>:<last> filled by random
@Daniel: Because this will have a common use for all, it might be included into the lxc-conf parser
["lxc.network.hwaddr: the interface mac address is dynamically allocated by default to the virtual interface ...]"
We maybe should have a special keyword for a "derived" semi-static MAC that would not change at every startup of the container but may be calculated by the formula given above.
Guido
More information about the lxc-users
mailing list