Score:0

How can I set the hardware mac address permanently?

gb flag

I have a headless ARM server running 20.04.4, which for reasons I cannot understand has all it's NICs with hardware macs of all zeros, and sets the current mac randomly on every reboot.

╰─ macchanger eth2
Current MAC:   2a:77:19:7c:b4:e4 (unknown)
Permanent MAC: 00:00:00:00:00:00 (XEROX CORPORATION)

I run a pi hole on my network and it also handles the DHCP service, and can only assign static IPs based on reported mac address. This means that my server gets a new IP address on every reboot, which is problematic when there is an issue with the pi hole.

I want my server to keep a mac address for a given interface even when reboots happen.

I've tried

ip link set eth2 address 2A:77:19:7C:B4:E4

but that got wiped during a reboot.

I've tried using a link file with systemd-networkd, but this appears to have no effect either.

sudo nano /etc/systemd/network/10-eth2.link 
[Match]
PermanentMACAddress=00:00:00:00:00:00

[Link]
MACAddress=2A:77:19:7C:B4:E4

Digging around, I found these log entries in

journalctl -b -u systemd-udevd.service
eth2: Could not generate persistent MAC: No data available
Feb 25 23:23:42 macchiatobin systemd-udevd[480]: ethtool: autonegotiation is unset or enabled, the speed and duplex are not writable.

How else can I set my mac address to the same value permanently, or on start up so it is the same value on every boot?

heynnema avatar
ru flag
I assume that you're running netplan. See https://netplan.io/ and search the reference and design pages for "mac address". Then you might try using the **match** (by name... eth0, eth1, etc.) and **macaddress** qualifiers.
Score:0
gb flag

I was able to solve this as follows.

I created this file:

/etc/netplan/config.yaml                  

with contents:

network:
    version: 2
    renderer: networkd
    ethernets:
        eth0:
            macaddress: ba:e4:64:bc:81:d7
        eth1:
            macaddress: c2:1c:fb:6b:fb:73
        eth2:
            macaddress: 2A:77:19:7C:B4:E4
        eth3:
            macaddress: ba:2a:5c:54:35:60

where eth0/1/2/3 are the interfaces on my machine. I was then able to apply these instantly using

sudo netplan apply

these settings are then persisted after reboots.

Note that there is a bug in the pihole dhcp server that doesn't remove a dynamic lease when using the UI. You can edit the file at /etc/pihole/dhcp.leases and remove the lease directly. Then use

sudo pihole restartdns

This setup now assigns the same mac address for the interfaces, and the dhcp server does the rest.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.