ENC28J60 fixed MAC address on Radxa Zero

Hi Everyone

How to create a fixed enc28j60 LAN eth0 MAC address?
I followed the Raspberry PI forum ticket #188009: https://forums.raspberrypi.com/viewtopic.php?t=188009
However, the Radxa Zero still generated a random mac address from each booting up.

// Custom MAC address service file
pi@radxa-zero:~$ cat /etc/systemd/system/custommac.service
[Unit]
Description=DSet the MAC address for the ENC28J60 enet adapter at eth0
Wants=network-pre.target
Before=network-pre.target
BindsTo=sys-subsystem-net-devices-eth0.device
After=sys-subsystem-net-devices-eth0.device

[Service]
Type=oneshot
ExecStart=/usr/bin/custommac.sh
ExecStart=/sbin/ip link set dev eth0 up

[Install]
WantedBy=multi-user.target

// Custom mac address bash file
pi@radxa-zero:~$ cat /usr/bin/custommac.sh
#!/bin/sh
sudo /sbin/ip link set dev eth0 address sed -n "s/0x..\(..\)\(..\)\(..\)/d4:9c:ac:\1:\2:\3/p" /sys/devices/platform/soc/ffe07000.mmc/mmc_host/mmc2/mmc2:0001/serial

Thanks in advance

This is the approach I used in LibreELEC:

Along with the systemd service:

You might need to modify the before/after dependencies to suit the distro you’re using.

Thanks @chewitt for the advice.
I need to modify the before/after dependencies. The eth0 was up before the debian linux os calls the custommac.service.

For testing purpose, I set the eth0 down before writing the mac address, the service could write the mac address.
[Service]
Type=oneshot
ExecStart=/sbin/ip link set dev eth0 down
ExecStart=/usr/bin/aptc_py/custommac.sh
ExecStart=/sbin/ip link set dev eth0 up

Adding dhcpcd.service to “Before” solved the issue. Probably the eth0 was up during running dhcpcd.service.
[Unit]

Before=network-pre.target dhcpcd.service