MAC Address Spoofing on Linux

Intro

MAC address (Media Access Control) is an identifier for our network devices that we use. It’s unique identifier, every network devices has different identities.

Mostly, MAC address are available at IEEE 802 networking technology such as Ethernet, Wi-Fi, and Bluetooth. And every devies that we uses such as Laptop, Computer, or even Smartphone has MAC address on top of it.

For this guide, i will show you how to automatically change MAC address of your Linux system using systemd-networkd service and using the NetworkManager application.

Check MAC address

Before going any further, check the MAC address on the system using the ip command as below.

1
ip a

And you will be shown the MAC address of your machine as link/ether 12:9a:5b:0d:xx:xx ....

If you want to know what a vender of your MAC address you used, visit the site https://macvendors.com/, copy and paste your MAC address on the page, and you will get details vender of your MAC address you’re using.

Spoof MAC address with systemd-networkd service

The systemd-networkd is a services that manages networking configuration. As networking devices appears, the service will automatically detects and configure your networking devies. Also, it can create virtual network devices.

The systemd-networkd is part of systemd, so ensure you’re using an operating system with systemd running on top of your OS.

Run the systemd-networkd services and add it to start automaticall on the system boot using following commands.

1
2
sudo systemctl start systemd-networkd
sudo systemctl enable systemd-networkd

Next, create a new configuration for your devices on the /etc/systemd/network directory. For example below I create the configuration wlan0.link to change my wlan0 interface MAC address.

1
sudo nano /etc/systemd/network/wlan0.link

Change MACAddress=xx:xx:xx:xx:xx:xx with your real MAC address, copy and paste to your configuration.

[Match]
MACAddress=xx:xx:xx:xx:xx:xx

[Link]
MACAddressPolicy=random
NamePolicy=kernel database onboard slot path

Save.

NOTE:

Instead of random MAC address on every boot, you can use pre-defined static MAC address by changing the MACAddressPolicy=random to static configuration MACAddress=Static Spoofed MAC.

Now restart the systemd-networkd services to apply.

1
sudo systemctl restart systemd-networkd

Check again your MAC address usin gthe ip a command and it has been changed. Otherwise, you can reboot your system.

Spoof MAC Address with NetworkManager

The second way to change MAC address is by using the NetworkManager application, mostly available on every Linux Desktop.

Edit the /etc/NetworkManager/NetworkManager.conf configuration file.

1
sudo vim /etc/NetworkManager/NetworkManager.conf

Now paste the following configuration to the end of the line.

[device-mac-randomization]
# "yes" is already the default for scanning
wifi.scan-rand-mac-address=yes
 
[connection-mac-randomization]
# Randomize MAC for every ethernet connection
ethernet.cloned-mac-address=random
# Generate a random MAC for each WiFi and associate the two permanently.
wifi.cloned-mac-address=random

Save and close.

Next, restart the NetworkManager services to apply.

1
sudo systemctl restart NetworkManager

As a result, you will get random MAC address everytime you make connection to the network, on Wi-Fi and Ethernet.

Reference

Archwiki

Gnome NetworkManager