netplan should support setting MAC addresses in software

Bug #1718607 reported by Oliver Grawert
40
This bug affects 7 people
Affects Status Importance Assigned to Milestone
Netplan
Fix Released
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)
description: updated
Revision history for this message
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.

Revision history for this message
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 ...

Revision history for this message
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?

Revision history for this message
Dmitriusan (dmitriusan) wrote :

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

Revision history for this message
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 ...

Revision history for this message
Daniel Axtens (daxtens) wrote : Re: [Bug 1718607] Re: netplan should support setting MAC addresses in software

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.

Revision history for this message
Dmitriusan (dmitriusan) 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

Revision history for this message
Daniel Axtens (daxtens) wrote :

The documentation fix is now in the GitHub repo.

Changed in netplan:
status: New → Fix Committed
Revision history for this message
Roland Kaufmann (rlndkfmn+launchpad) wrote :

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.

Revision history for this message
Roland Kaufmann (rlndkfmn+launchpad) wrote :

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.

Revision history for this message
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

Revision history for this message
Yancy Burns (beowuff) wrote :

Adding a match for the original mac worked for me.

Revision history for this message
Frédéric LECHAIGNE (flechaig) wrote :

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

Revision history for this message
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.

Revision history for this message
Id2ndR (id2ndr) wrote :

The match stanza workarounds should be written like this (here with eno1 interface):

network:
  ethernets:
    eno1:
      match:
        macaddress: <LINK_MAC_HERE>
      [..]
  bridges:
    br0:
      macaddress: <LINK_MAC_HERE>
      interfaces:
        - eno1
      [..]

<LINK_MAC_HERE> can be get with the following command, just after "link/ether": $ sudo ip link show eno1

After setting this, you need either to reboot, or doing the following commands:
$ sudo ip link set br0 down
$ sudo brctl delbr br0
$ netplan apply

Lukas Märdian (slyon)
Changed in netplan:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.