http://gnailuy.com/2011/07/15/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:
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 our changes active immediately, we should restart the network interface:
/etc/init.d/network restart
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:
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