netplan should support setting MAC addresses in software

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

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:

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?

  version: 2
      addresses: []
      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,

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

     version: 2
     renderer: networkd
         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 (search for "Set the device's MAC") now indicates that this should be possible.

Daniel Axtens (daxtens) wrote :


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 although
with a slightly different presentation (mac vs mtu).


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.

Id2ndR (id2ndr) wrote :

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

        macaddress: <LINK_MAC_HERE>
      macaddress: <LINK_MAC_HERE>
        - 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

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

Other bug subscribers