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 up
where “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:
Comment out the line start with HWADDR, and then add a MACADDR line like this:
To make our changes active immediately, we should restart the network interface:
In 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:
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:
© 2011, Yuliang Jin. All rights reserved.
This post is under a Creative Commons Attribution-ShareAlike 3.0 Unported License.