netplan should support setting MAC addresses in software

Bug #1718607 reported by Oliver Grawert on 2017-09-21
34
This bug affects 6 people
Affects Status Importance Assigned to Milestone
netplan
Undecided
Unassigned

Bug Description

when using ifupdown it is possible to spoof your mac address via /etc/network/interfaces with something like:

hwaddress ether <mac>

netplan currently has no option like this so one has to run a script or some such on boot to run something like:

ip link set <device> address <addr>

since Ubuntu Core exclusively uses netplan for the network configuration and some users want to be able to modify the MACs on their IoT devices the missing feature is a problem.

for reference:

https://forum.snapcraft.io/t/dragonboard-lib-firmware-ethmacaddr0/2133

Oliver Grawert (ogra) on 2017-09-21
description: updated
Daniel Axtens (daxtens) wrote :

Hi Oliver,

It looks like there's an undocumented macaddress option that is supported by both the network manager and networkd backends but just isn't talked about in the docs.

I don't know when it was added but it is certainly in the latest git version.

Does a file like this work?

network:
  version: 2
  ethernets:
    eth0:
      addresses: [1.2.3.4/8]
      macaddress: 52:54:00:6b:3c:59

I will send a patch to document this option.

Oliver Grawert (ogra) wrote :

I can test it once it got backported to 16.04 and landed in Ubuntu Core :)

It is good to see that it finally made it into the master git tree but core is based on LTS so we need to get the binary deb in there first ...

Daniel Axtens (daxtens) wrote :

Looking at the git history, it should be supported in the version in xenial-updates. I don't know what version is in Ubuntu Core, but it looks like it was supported from 0.22 onward.

What versions do you have access to?

Dmitrius (ldsupport) wrote :

Is it possible to set the mac address for bridge in the same way?

Oliver Grawert (ogra) wrote :

Ah, ok,

https://launchpadlibrarian.net/357705057/core_16-2.31+git583.0e8bcef_amd64.manifest

shows we have:

nplan 0.32~16.04.3-1

i''ll give it a try then ...

I​t should be - the code certainly supports parsing macaddress for a
bridge, and I think the backends support it to, but I haven't tried. Please
do try it and let us know if it doesn't work.

Dmitrius (ldsupport) wrote :

Yes, setting mac address on bridge seems to work. Though I have issue with cloud-init on digital ocean when trying to add interface to bridge. Through it is an offtopic.
Thanks, Daniel

Daniel Axtens (daxtens) wrote :

The documentation fix is now in the GitHub repo.

Changed in netplan:
status: New → Fix Committed

Trying this with the latest beta version of Ubuntu Bionic (`apt show nplan` returns Version: 0.33), it does not seem to work: I have /etc/netplan/01-netcfg.yaml

   network:
     version: 2
     renderer: networkd
     ethernets:
       enp0s25:
         macaddress: 12:34:56:78:AB:CD
         dhcp4: true

but `ip link show enp0s25` still returns the old MAC address (after both `sudo netplan apply` and after reboot), whereas `sudo ip link set enp0s25 address 12:34:56:78:AB:CD && sudo systemctl restart systemd-networkd` works as expected.

This also applies to Ubuntu Bionic point release 18.04.1, with netplan version 0.39, even though the reference at https://netplan.io/reference#common-properties-for-all-device-types (search for "Set the device's MAC") now indicates that this should be possible.

Daniel Axtens (daxtens) wrote :

Hi,

Could you try adding a 'match' stanza to your definition of enp25s0
that matches on the original mac? I think you're probably hitting a
similar sort of issue to
https://bugs.launchpad.net/ubuntu/+source/nplan/+bug/1724895 although
with a slightly different presentation (mac vs mtu).

Regards,
Daniel

Yancy Burns (beowuff) wrote :

Adding a match for the original mac worked for me.

Adding a match for the original mac worked for me too.

Christoph (christopherson) wrote :

Would you mind explicitly describing how to add a match stanza for changing mac addresses?
Do I match for the hardware mac, then specify the new mac in an indented line? Sorry, I'm new to netplan.

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers