How to change MAC address in Linux
In order to get access to the campus network in my college, one have to configure his/her network device to a pair of binding IP and MAC addresses. The most disgusting part is that the IP/MAC pairs were assigned fixedly to different rooms. So I have to change the IP/MAC on my laptop when I move between my dorm and my lab.
Changing an IP address is easy in Linux. We can either use the command “ifconfig” to switch to a new IP address temporarily, or change it permanently by editing our network configuration file.
In this post, we focus on how to change the MAC address.
Temporary change of MAC address
Switch to root or use sudo, type:
ifconfig eth0 down
ifconfig eth0 hw ether XX:XX:XX:XX:XX:XX
ifconfig eth0 upwhere “eth0″ is the name of our network device, and XX:XX:XX:XX:XX:XX is a new MAC address(the same below). The above commands will take effect immediately. But if we reboot the system, these changes will not be retained.
Permanent change of MAC address
In order to change the MAC address permanently, we have to edit the network configuration file. In Red Hat/CentOS/Fedora, the configuration file is /etc/sysconfig/network-scripts/ifcfg-eth0:
vi /etc/sysconfig/network-scripts/ifcfg-eth0Comment 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:YYTo make our changes active immediately, we should restart the network interface:
/etc/init.d/network restartIn debian/ubuntu, the network interface is configured in file /etc/network/interface. And the syntaxes in this file are totally different with those in Redhat-like system. But it is also very easy to change the MAC address:
vi /etc/network/interfaceAdd this line at the end of this file:
pre-up ifconfig eth0 hw ether XX:XX:XX:XX:XX:XXThen restart the network subsystem:
/etc/init.d/networking restart© 2011, Yuliang Jin. All rights reserved.
This post is under a Creative Commons Attribution-ShareAlike 3.0 Unported License.



July 15th, 2011 at 5:22 PM
英语真好,佩服
[Reply]
Yuliang Reply:
July 15th, 2011 at 5:28 PM
@RichL0e, o(∩∩)o…其实很一般,就是练习练习,肯定能挑出不少毛病的哈……
[Reply]
July 20th, 2011 at 7:52 AM
light light realy like looks, I ask good good like you study.
[Reply]
Yuliang Reply:
July 20th, 2011 at 8:27 AM
@Lei, What? Sorry I cannot understand what you said…
[Reply]
Yuliang Reply:
July 20th, 2011 at 8:30 AM
@Lei, Oh man…it’s you!!!
[Reply]
August 17th, 2012 at 4:54 PM
thank you yuliang
[Reply]
Yuliang Jin Reply:
August 17th, 2012 at 8:15 PM
ur welcome~^_^
[Reply]