It's easy to change the MAC address in Linux.
We can use the command
ifconfig to switch to a new MAC address temporarily
or change it permanently by editing the network configuration file.
Temporary change of MAC address
Switch to root or use
ifconfig eth0 down
ifconfig eth0 hw ether XX:XX:XX:XX:XX:XX
ifconfig eth0 up
where "eth0" is the name of your work device, and XX:XX:XX:XX:XX:XX is a new MAC address (same below). The above commands will take effect immediately. But if we reboot the system, these changes will be lost.
Permanent change of MAC address
To change the MAC address permanently, we have to edit the network configuration file.
In Red Hat/CentOS/Fedora, it is
Comment out the line start with HWADDR, and then add a MACADDR line like this:
To make the change take effect immediately, you should restart the network interface:
In debian/ubuntu, the network interface configuration is in the file
And the syntax is also different from those in a Redhat-like system.
But it is still easy to change the MAC address:
Add this line at the end of this file:
pre-up ifconfig eth0 hw ether XX:XX:XX:XX:XX:XX
Then restart the network subsystem: