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}
network:
version: 2
ethernets:
eth0:
dhcp4: true
match:
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:Let me know if it helps.