Linux – Change interface mac (hw) address using udev rules

linuxudev

I want to set a specific ethernet MAC address for an interface using UDEV rules. I have the following rule:
SUBSYSTEM=="net", ACTION=="add", ATTRS{serial}=="50B123", ATTR{address}="00:22:33:44:55:AA", NAME="yolo0"

The rule matches and the interface is renamed to "yolo0" however the hw ether address remains unchanged from the one pre-set by the manufacturer. I can change the mac address manually of course using:

ifconfig yolo0 hw ether ..00:22:33:44:55:AA

Best Answer

You can use udev PROGRAM rules for that, by making the appropriate call to ip link set … address …. Like this:

/etc/udev/rules.d/10-network-persistent-custom-mac-address.rules

SUBSYSTEM=="net", ACTION=="add", ATTRS{serial}=="50B123", PROGRAM="/sbin/ip link set %k address 00:22:33:44:55:AA"
Related Topic