[Lxc-users] How are pseudorandom MACs selected?

Trent W. Buck twb at cybersource.com.au
Thu Feb 3 00:37:35 UTC 2011


Daniel Lezcano <daniel.lezcano at free.fr> writes:

> On 02/02/2011 10:26 AM, Trent W. Buck wrote:
>> For each lxc.network.type = veth, if you DON'T specify an
>> lxc.network.hwaddr, you get one assigned at random (example below).
>>
>> Are these assignments made from a reserved range (a la 169.254/16 in
>> IPv4), or are they randomized across the entire address space?  AFAICT,
>> it MUST be the latter.
>>
>> Further, when manually allocating a static hwaddr (so I can map it to an
>> IP within the DHCP server),
>
> The dhcp relies on an identifier to map the IP, the default is to use
> the mac address but you can use another identifier like the hostname
> for example.

Good idea, although that would make configuring my DHCP server (dnsmasq)
a little more fiddly.  Currently I just populate ethers(5) on the DHCP
server, and dnsmasq automagically uses that mapping (as opposed to
adding lines into the dnsmasq.conf).

> AFAIR, there is an option in the system network configuration scripts
> to send the hostname for the dhcp requests.

There is; it's ``send host-name "foo";''

On Ubuntu this is even the default: they have patched their ISC dhclient
package to allow ``send host-name "<hostname>";'', which sends the same
string as `hostname' emits.

> This is how the kernel allocates the mac address.
>
> static inline void random_ether_addr(u8 *addr)
> {
>          get_random_bytes (addr, ETH_ALEN);
>          addr [0] &= 0xfe;       /* clear multicast bit */
>          addr [0] |= 0x02;       /* set local assignment bit (IEEE802) */
> }

Cool, thanks.

> Maybe you can use the mac address range used for the virtual nic of
> vmware.  Another solution would be to buy a cheaper nic, get its mac
> address, break and drop the nic :)

Hehe.  I'll try just assigning from the local unicast range, and see if
I run into problems.





More information about the lxc-users mailing list