.-- .. - .... .-.. --- ...- .

home archive about

How to change MAC address in Linux

15 Jul 2011

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 sudo, then:

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 /etc/sysconfig/network-scripts/ifcfg-eth0:

vi /etc/sysconfig/network-scripts/ifcfg-eth0

Comment out the line start with HWADDR, and then add a MACADDR line like this:

#HWADDR=XX:XX:XX:XX:XX:XX
MACADDR=YY:YY:YY:YY:YY:YY

To make the change take effect immediately, you should restart the network interface:

/etc/init.d/network restart

In debian/ubuntu, the network interface configuration is in the file /etc/network/interface. And the syntax is also different from those in a Redhat-like system. But it is still easy to change the MAC address:

vi /etc/network/interface

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:

/etc/init.d/networking restart
Creative Commons License
comments powered by Disqus