Changing the MAC (Media Access Control) address of NICs (Network Interface Cards)
Last modified on July 24, 2026 • 3 min read • 538 words
In some networks, computers have to be registered to get connected. Upon registration, the computer will receive a name and an IP address. Every time it connects to the network, the DHCP server assigns it the same name and IP address. The DHCP server identifies computers based on the MAC address, which is unique to every NIC. However, if you know the MAC address of a registered computer, you can use it to connect to the network, faking the MAC address:
ifconfig eth0 down
macchanger --mac=00:B0:D0:20:A5:D9 eth0
ifconfig eth0 upIf you need to execute this change every time the machine is booting you can put it into a script. Under Ubuntu Trusty Tahr (14.04), ifconfig didn’t work for me anymore. Changing the MAC still works, however, by adding the following three lines to the end of file /etc/rc.local (but before the “exit 0” line):
dhclient -r eth0
macchanger -m 00:21:5a:76:44:b0 eth0
dhclient eth0Unfortunately, on MacOSX, this seems almost impossible. Or rather, the way to do so seems to change with every OS update. An easier way is to use a router since most of these support MAC address cloning. And with Ubuntu 16.04 and later, the easiest way seems to be to use systemd:
sudo touch /etc/systemd/system/macchange@.service
sudo emacs /etc/systemd/system/macchange@.servicePaste the following content into the file:
[Unit]
Description=changes mac for %I
Wants=network.target
Before=network.target
BindsTo=sys-subsystem-net-devices-%i.device
After=sys-subsystem-net-devices-%i.device
[Service]
Type=oneshot
ExecStart=/usr/bin/macchanger --mac=00:B0:D0:20:A5:D9 %I
RemainAfterExit=yes
[Install]
WantedBy=multi-user.targetThen, enable the service. Remember to replace the enp2s0 with the name of your network interface!
sudo systemctl enable macchange@enp2s0.serviceUPDATE: The various ways to make a MAC change permanent with systems have changed with almost every Ubuntu version, and recently, above methods have not worked anymore. One way that worked with Ubuntu 22.04 and higher was described here: https://askubuntu.com/questions/1394904/how-can-i-set-the-hardware-mac-address-permanently . However, after some experimenting, I think that macchanger is not the right tool for the default Ubuntu desktop setup, which uses NetworkManager. NetworkManager needs to be disabled so as not to interfere. And most people want to have the convenience of changing settings with a simple click instead of issuing commands in a terminal. So, how do you do a MAC change with NetworkManager? First, you need to get to know the name of your wired configuration (in this case, “Wired”):
nmcli con showThen you simply change the mac address:
nmcli con modify Wired ethernet.cloned-mac-address XX:XX:XX:XX:XX:XX(BTW: The configuration files are in /etc/NetworkManager/system-connections.) If you want to edit the MAC address of Ubuntu server 24.04, you only need to edit the file /etc/netplan/50-cloud-init.yaml (just add the last line starting with macaddress):
network:
version: 2
ethernets:
enp3s0:
dhcp4: true
macaddress: xx:xx:xx:xx:xx:xxTo apply the change (which is permanent):
sudo netplan applyBe aware that many routers will disconnect you when they see that the MAC address has changed and connect you with a new IP address. However, in some environments (where IP addresses have to be registered), you might get locked out!
Some people think that using macchanger is close to illegal, but as a matter of fact, your Andropid or iPhone (if it’s a recent model) does exactly the same - changing its MAC address in regular intervals. Because the MAC address is worldwide unique to your device, you can be identified and localized/tracked using your phone’s MAC address.