I am using a NanoPi NEO 1.4 and also observed MAC changing with each reboot.
Linux npi-neo-1 5.10.21-sunxi #21.02.3 SMP Mon Mar 8 00:28:04 UTC 2021 armv7l GNU/Linux
While I was successful configuring `/etc/network/interfaces` (`armbianEnv.txt` didn't work, didn't try `dhclient.conf`), I wasn't quite satisfied by the results.
I thus looked for a different solution and stumbled over
https://epsilonrt.fr/2018/03/corriger-une-adresse-mac-aleatoire-dans-armbian-sur-nanopi/
The solution suggested by that three year old post doesn't work with my kernel.
But as it turned out, the analysis for the underlying problem was spot-on.
That prompted me to create a custom device tree overlay as `nanopi-neo-stable-mac.dts` as follows:
/dts-v1/;
/plugin/;
/ {
compatible = "allwinner,sun8i-h3";
/*
* uboot tries to write a MAC address from ${mac_node}
* to the device tree at 'local-mac-address' within 'ethernet0'
* fdt set ethernet0 local-mac-address ${mac_node}
* This obviously doesn't work if the device tree does not match the
* expected structure, resulting in the kernel creating a random MAC.
*
* This overlay adjusts the device tree to accept uboot's MAC address
* by adding
* - 'ethernet0' alias for symbol '/soc/ethernet@1c30000'
* (or change to whatever path your existing symbol 'emac' points to)
* - 'local-mac-address' to structure at 'emac'
*
* Tested to work on a NanoPi NEO 1.4 - adjust for other devices as required
*/
fragment@0 {
target-path = "/aliases";
__overlay__ {
ethernet0 = "/soc/ethernet@1c30000";
};
};
fragment@1 {
target = <&emac>;
__overlay__ {
local-mac-address = [00 00 00 00 00 00];
};
};
};
This custom overlay can be compiled with
sudo armbian-add-overlay nanopi-neo-stable-mac.dts
You may verify that `/boot/armbianEnv.txt` has been expanded by a new user_overlays option like:
user_overlays=nanopi-neo-stable-mac
After a reboot, a stable MAC will be used (likely starting with `02:81`)
You may verify that `local-mac-address` has indeed been set by running:
sudo dtc -qq -I fs /proc/device-tree | grep local-mac-address
This should return something like:
local-mac-address = [ 02 81 01 ba dc af ];
My initial complaints were also gone.
What remains to be verified is whether that stable MAC is specific for that device or identical across multiple devices of the same type.
As I only have that one device, I cannot test this.
It would be important if you would run multiple NanoPi NEOs on the same link.
Maybe a developer can shed some light on how uboot acquires that MAC address?