Set persistent MAC for RTL8111/8168/8411 (r8169) with udev
udev
, like IPFire!
The Linux kernel mod r8169
seems to set random MAC addresses for Realtek's ethernet cards 8111/8168/8411 every time this devices gets booted. This behaviour also seems to be intended like described in this kernel patch.
You can verify this by checking your (boot-) log, if it contains can't read MAC address, setting random one
on the device that uses the mod r8169
, you may be affected.
But it may break your system like when using IPFire that recognizes it's NICs from their MAC address.
Get PCI device information
Use the following command and determine your NIC and it's PCI address: (pciutils
is required)
lspci -v
The output may look like this:
Now take note of it's address, in this case 04:00.0
.
Create udev rules
Then add a udev
-rule for this NIC. Therefore create a new rule:
nano /etc/udev/rules.d/10-network-persistent-custom-mac-address.rules
And add the following content:
SUBSYSTEM=="net", ACTION=="add", KERNELS=="0000:<pci-address>", PROGRAM="/sbin/ip link set %k address <your-persistent-mac>"
Replace pci-address
with the NICs PCI address that you got from the step before (e.g. 0000:01:00.0
) and your-persistent-mac
with the MAC address that should always be assigned to this NIC. (both without <
and >
).
Finally save the file and reboot.
Resources used: serverfault.com - Change interface MAC HW address, packetpushers.net - udev