[Lxc-users] How are pseudorandom MACs selected?

Daniel Lezcano daniel.lezcano at free.fr
Wed Feb 2 11:20:39 UTC 2011


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. AFAIR, there is an option in the system network configuration 
scripts to send the hostname for the dhcp requests.

>   is there any particular range I should avoid
> or stick to?

This is how the kernel allocates the mac address.

/**
  * random_ether_addr - Generate software assigned random Ethernet address
  * @addr: Pointer to a six-byte array containing the Ethernet address
  *
  * Generate a random Ethernet address (MAC) that is not multicast
  * and has the local assigned bit set.
  */
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) */
}


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 :)

> For example, it wouldn't surprise me if some hardware/software did
> things like "hmm, your MAC indicates you're from<vendor>, and I know
> <vendor>  doesn't implement jumbo frames correctly, so I won't send you
> any" -- which could result in bizarro issues because my container isn't
> actually a<vendor>  NIC.
>
>      # ip -o l | grep veth | tr '\\' '\n' | grep link/ether | sort
>      link/ether 06:f7:5a:69:b8:e5 brd ff:ff:ff:ff:ff:ff
>      link/ether 12:89:2b:60:81:36 brd ff:ff:ff:ff:ff:ff
>      link/ether 1a:be:07:cb:81:50 brd ff:ff:ff:ff:ff:ff
>      link/ether 2e:ea:93:ef:0b:9a brd ff:ff:ff:ff:ff:ff
>      link/ether 46:aa:11:c4:94:ef brd ff:ff:ff:ff:ff:ff
>      link/ether 72:1e:8e:08:7b:e2 brd ff:ff:ff:ff:ff:ff
>      link/ether 7a:24:c3:dc:20:d4 brd ff:ff:ff:ff:ff:ff
>      link/ether 82:53:b7:5d:85:64 brd ff:ff:ff:ff:ff:ff
>      link/ether 86:f8:a4:a6:b0:03 brd ff:ff:ff:ff:ff:ff
>      link/ether 96:b8:59:76:66:02 brd ff:ff:ff:ff:ff:ff
>      link/ether c2:f3:df:47:e4:10 brd ff:ff:ff:ff:ff:ff
>      link/ether d6:df:18:81:12:c1 brd ff:ff:ff:ff:ff:ff
>      link/ether e6:41:f1:ee:7b:0f brd ff:ff:ff:ff:ff:ff
>      link/ether ea:99:00:37:d3:e8 brd ff:ff:ff:ff:ff:ff






More information about the lxc-users mailing list