Getting a stable MAC with Ethernet Mezzanine

Background:
We have a multi-dragonboard system implementing PoE Mezzanines where it would be very nice if the DB units had persistent MAC addresses. It’s understood that the PoE Mez does not have hardware for a non-volatile MAC, so we handle it in software. A random (non-OEM conforming) address is fine since the units operate on a closed network so long as the addresses persist on each board (it doesn’t randomize on reboot or reconnect).

Problem:
The default method of generating the MAC is such that the value does not persist across cold reboots forcing our DHCP server to issue a new IP each time. While NetworkManager is supposed to support generating a MAC based on some device specific values (see assigned-mac-address here), altering the the NM profile to implement this simply causes NM to generate a new profile on reboot and use that instead. :smirk: How cheeky.

To complicate matters the solution must be implemented via configs on the rootfs image, not after first boot which is why I’m attempting the NM method rather than something like macchanger. While running macchanger is not itself forbidden, I need a solution that runs on first boot and persists thereafter without interactive configuration. If a macchanger solution, bonus if the generated MAC had something to do with some device specific variable, increasing the odds of real uniqueness.

Some info:

$ uname -r && apt list network-manager

4.14.0-qcomlt-arm64
Listing... Done
network-manager/testing,now 1.14.6-2 arm64 [installed]

$ cat /etc/NetworkManager/NetworkManager.conf

[main]
plugins=ifupdown,keyfile

[ifupdown]
managed=false

[logging]
level=TRACE

$ cat /etc/NetworkManager/conf.d/00-macfix.conf

[device]
wifi.scan-rand-mac-address=no
ethernet.assigned-mac-address=stable

[connection]
connection.stable-id=${CONNECTION}-${DEVICE}

$ cat /etc/network/interfaces

# interfaces(5) file used by ifup(8) and ifdown(8)
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d

/etc/network/interfaces.d/ is empty.

TIA!

Hmnn…

The the built-in WiFi and BT MAC addresses, if the bootloader cannot
find proper MAC addresses it will generate local MAC addresses using the
eMMC unique ID and place them in the DT.

The PoE is a USB device so these won’t work since there is no DT used to
configure it.

However… if you change what you call the problem, from initializing
the MAC (which only crazy embedded people do) to MAC address spoofing
(which is rather more common) then the search engines will do a better
job helping you out:
https://wiki.archlinux.org/index.php/MAC_address_spoofing

To be honest I think you are in the right lines with macchanger, it’s
just a matter of when you call it and what you call it with. For those
I’d recommend searching the above doc for network-pre-target for the
former, and deriving a MAC address from
/sys/bus/mmc/devices/mmc0\:0001/serial for the later. Make sure the
result doesn’t colide with the WiFi MAC. For example you could convert
0xaabbccdd to 96:b0:aa:bb:cc:dd (e.g. pick any “locally allocated”
prefix that differs from the prefix of the WiFi address).

With the doc above it should be easy to create a systemd service to
handle this!