VMWARE安装虚拟机后,为了避免重新安装,一般会选择直接复制虚拟机,但当打开心得拷贝后网卡信息会变化,原来是eth0 eth1 就会变成eth2 eth3,如果不想使用eth2 eth3下面的方法就可以更改网卡名称。CentOS为例

1.使用ip link 命令

ip link set eth0 name eth2
ip link set eth1 name eth0
ip link set eth2 name eth1

即可随意更改名字,不过重启后会失效。

2.更改配置文件(重启不会失效)

直接可以在modprobe 中修改模块别名,如使用udev的情况下,

 

 
  
  1. # vi /etc/udev/rules.d/70-persistent-net.rules  
  2.  
  3. 其中会有  
  4. # PCI device 0x8086:0x100f (e1000) (custom name provided by external tool)  
  5. SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:42:e7:61", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0" 
  6.  
  7. # PCI device 0x8086:0x100f (e1000)  
  8. SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:42:e7:66", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1" 
  9.  
  10. # PCI device 0x8086:0x100f (e1000) (custom name provided by external tool)  
  11. SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:42:e7:6c", ATTR{type}=="1", KERNEL=="eth*", NAME="eth2" 
  12.  
  13. # PCI device 0x8086:0x100f (e1000)  
  14. SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:42:e7:76", ATTR{type}=="1", KERNEL=="eth*", NAME="eth3" 

 

为了避免MAC地址和其他虚拟机重复,我们可以选择更改下MAC地址,然后将eth0 eth1两行注释掉,将最后两行中的eth2 和eth3更改为eht0 和 eth1 。

完成后重启,就会发现虚拟机网卡又变成eth0和eth1了。