如何改变Linux的网卡的MAC地址
2013-01-01 11:16
821 查看
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.
Switch to root or use sudo, type:
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.
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:
Then restart the network subsystem:
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
相关文章推荐
- Red Hat Linux下如何修改网卡MAC地址
- Linux(Windows)下如何改变网卡的LinkSpeed工作模式
- 在Linux下,在网络没有配置好前,如何查看网卡的MAC地址?
- Linux学习教程之如何改变网卡的mac地址
- linux 如何更改网卡的顺序
- 直接复制的VMware虚拟机镜像如何更改网卡的MAC地址
- 在solaris系统中,如何查看本机的网卡mac地址啊?跪求答案啊!!
- Linux的网卡由eth0变成了eth1,如何修复
- linux下如何实现多网卡bonding
- 如何在linux网卡上添加多个IP
- centos 7下如何改变网卡名称
- 在VMware workstation 9中如何查看和更改虚拟机的网卡MAC地址?
- Linux下用libpcap如何对多网卡抓包,找不到打开多网卡的函数啊!!!!
- linux/centos如何查看网卡信息
- Linux下获得网卡MAC地址,IP地址及子网掩码
- Linux下获取eth网卡MAC地址的代码
- Linux下多网卡时,如何快速辨别网卡ID与物理网卡的对应关系(即ethtool命令)
- Linux的网卡由eth0变成了eth1,如何修复
- 如何在linux下配置网卡信息
- Linux下如何用C编程实现检测网卡与网线的连接状态