[Lxc-users] How are pseudorandom MACs selected?

Trent W. Buck trentbuck at gmail.com
Mon Feb 7 00:41:25 UTC 2011


Nirmal Guhan <vavatutu at gmail.com> writes:

> On Wed, Feb 2, 2011 at 6:25 PM, Trent W. Buck <twb at cybersource.com.au> wrote:
>> "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).
>
> Provided container's hostname are unique across different hosts?

Certainly; mine are.





More information about the lxc-users mailing list