I want to permanently change MAC address of my network card on Ubuntu 18.04 LTS server, so I tried to follow some internet tutorials as well as similar answers on here, but they seem to all be for the older versions of Ubuntu.

The tutorials recommend changing the mac in /etc/network/interfaces, but when I open it it says:

# ifupdown has been replaced by netplan(5) on this system.  See
# /etc/netplan for current configuration.
# To re-enable ifupdown on this system, you can run:
#    sudo apt install ifupdown

But I found another file there called 50-cloud-init.yaml, which contains the following:

# This file is generated from information provided by
# the datasource.  Changes to it will not persist across an instance.
# To disable cloud-init's network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
    version: 2
            dhcp4: true
                macaddress: b6:22:eb:7b:92:44
            set-name: eth0

At first I thought all I had to do was just edit the mac here, but it says on top that the changes won't be saved between reboots.

I found this command works:

sudo ip link set dev <your device here> address <your new mac address>

But it resets the mac back to the original after a reboot.

So how do I change the mac address for the eth0 permanently?


I would recommend to create a udev rule which resets the mac address for you on each reboot.

Create file /etc/udev/rules.d/75-mac-spoof.rules with following content:

ACTION=="add", SUBSYSTEM=="net", ATTR{address}=="XX:XX:XX:XX:XX:XX", RUN+="/usr/bin/ip link set dev %k address YY:YY:YY:YY:YY:YY"

Let me know if it helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.