How do I identify the MAC Address of a Docker container interface?

A default MAC address of Docker container interface is between 02:42:00:00:00:00 and 02:42:ff:ff:ff:ff.
Mac address generation follows these guidelines:
  • The first part is prefixed by 02:42
  • The last four octets are the hex representation of the IPv4 address allocated to the container.

Here's the code snippet used by Docker v19.03 to generate a MAC address.


func genMAC(ip net.IP) net.HardwareAddr {
            hw := make(net.HardwareAddr, 6)
	// The first byte of the MAC address has to comply with these rules:
	// 1. Unicast: Set the least-significant bit to 0.
	// 2. Address is locally administered: Set the second-least-significant bit (U/L) to 1.
	hw[0] = 0x02
	// The first 24 bits of the MAC represent the Organizationally Unique Identifier (OUI).
	// Since this address is locally administered, we can do whatever we want as long as
	// it doesn't conflict with other addresses.
	hw[1] = 0x42
	// Fill the remaining 4 bytes based on the input
	if ip == nil {
            rand.Read(hw[2:])
	} else {
            copy(hw[2:], ip.To4())
	}
	return hw
}