How to change MAC address on Ubuntu from command line

View network settings:

ifconfig

Temporary change of MAC address (until system reboot):

sudo ifconfig eth0 hw ether XX:XX:XX:XX:XX:XX

Where eth0 is the name of the network interface, and XX:XX:XX:XX:XX:XX is the MAC address.

Permanent MAC Address Change:
Create any file in the /etc/network/if-pre-up.d/ directory, for example mac:

cd /etc/network/if-pre-up.d/
touch file mac
sudo nano /etc/network/if-pre-ud.d/mac

Add the lines to it:

#!/bin/sh
ifconfig eth0 hw ether XX:XX:XX:XX:XX:XX

The nano editor uses the keyboard shortcut Ctrl+O to save and Ctrl+X to exit.

See also my article:
Configuring the Network in Linux

Leave a comment

Leave a Reply