[Lxc-users] How are pseudorandom MACs selected?
Trent W. Buck
twb at cybersource.com.au
Thu Feb 3 02:25:09 UTC 2011
"Brian K. White" <brian at aljex.com> writes:
> I just use 02:00:<ip address> which ends up being automatically unique
> enough to not collide with anything else on your subnet assuming you
> already know the ip's you want to use
>
> IP=192.168.0.50 # container nic IP
> HA=`printf "02:00:%x:%x:%x:%x" ${IP//./ }` # generate a MAC from the IP
I think I'll adopt a slight variation of this -- computing the MAC from
the hostname, which are guaranteed by my site policy to be [a-z]{5}.
Where 06 is an arbitrarily chosen local unicast range,
$ f () { python -c "print '06%010x' % int('$(LC_ALL=C tr <<<"$1" a-z 0-9a-p)',26)"; }
$ f zorba
060000b240be
This allows my DHCP server to continue mapping MAC->IP, while actually
getting it from a hostname (which policy says won't change).
And I'll do this for all my containers, so that even containers that
have automatically assigned IPs will be relatively persistent (because
dnsmasq remembers MAC->IP leases and re-uses them preferentially).
More information about the lxc-users
mailing list