CentOS6 虚拟机迁移后网卡名更改问题解决

前端之家收集整理的这篇文章主要介绍了CentOS6 虚拟机迁移后网卡名更改问题解决前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

实验过程中,我们经常需要复制虚拟机,以模仿生产过程中同等配置的条件。

但无论是初次打开,选择"我已复制该虚拟机“也好,还是在虚拟机设置>网络适配器>高级中重新生成Mac地址,开机后选择”我已移动该虚拟机“也罢。开机后查询IP时,我们都会很遗憾的发现,网卡的名字,不一样了。

这是因为原Mac地址占用旧网卡,新Mac地址只能使用新的网卡名称。复制虚拟机为了不与原虚拟机冲突,也是生成了新的Mac地址。

[root@centos6~]#ifconfig
eth2Linkencap:EthernetHWaddr00:50:56:22:C9:22
inetaddr:192.168.234.187Bcast:192.168.234.255Mask:255.255.255.0
inet6addr:fe80::250:56ff:fe22:c922/64Scope:Link
UPBROADCASTRUNNINGMULTICASTMTU:1500Metric:1
RXpackets:4errors:0dropped:0overruns:0frame:0
TXpackets:8errors:0dropped:0overruns:0carrier:0
collisions:0txqueuelen:1000
RXbytes:806(806.0b)TXbytes:1152(1.1KiB)
eth3Linkencap:EthernetHWaddr00:50:56:3A:FD:74
inetaddr:172.17.251.174Bcast:172.17.255.255Mask:255.255.0.0
inet6addr:fe80::250:56ff:fe3a:fd74/64Scope:Link
UPBROADCASTRUNNINGMULTICASTMTU:1500Metric:1
RXpackets:2565errors:0dropped:0overruns:0frame:0
TXpackets:61errors:0dropped:0overruns:0carrier:0
collisions:0txqueuelen:1000
RXbytes:243027(237.3KiB)TXbytes:9974(9.7KiB)
loLinkencap:LocalLoopback
inetaddr:127.0.0.1Mask:255.0.0.0
inet6addr:::1/128Scope:Host
UPLOOPBACKRUNNINGMTU:65536Metric:1
RXpackets:4errors:0dropped:0overruns:0frame:0
TXpackets:4errors:0dropped:0overruns:0carrier:0
collisions:0txqueuelen:0
RXbytes:240(240.0b)TXbytes:240(240.0b)

虽然不影响使用,但怎么看都不舒服啊。而且有些实验中网卡名不统一也只有麻烦。正所谓没有标准化就很难进行自动化管理。

那么,如何更改迁移后的虚拟机的网卡名呢?


(1).修改配置文件/etc/udev/rules.d/70-persistent-net.rules

[root@centos6~]#vim/etc/udev/rules.d/70-persistent-net.rules
#Thisfilewasautomaticallygeneratedbythe/lib/udev/write_net_rules
#program,runbythepersistent-net-generator.rulesrulesfile.
#
#Youcanmodifyit,aslongasyoukeepeachruleonasingle
#line,andchangeonlythevalueoftheNAME=key.
#PCIdevice0x8086:0x100f(e1000)
SUBSYSTEM=="net",ACTION=="add",DRIVERS=="?*",ATTR{address}=="00:0c:29:13:d6:94",ATTR{type}=="1",KERNEL=="eth*",NAME="eth0"

#PCIdevice0x8086:0x100f(e1000)
SUBSYSTEM=="net",ATTR{address}=="00:0c:29:13:d6:9e",NAME="eth1"

#PCIdevice0x8086:0x100f(e1000)
SUBSYSTEM=="net",ATTR{address}=="00:50:56:22:c9:22",NAME="eth2"

#PCIdevice0x8086:0x100f(e1000)
SUBSYSTEM=="net",ATTR{address}=="00:50:56:3a:fd:74",NAME="eth3"

删除原Mac,更改NAME值,搞定。改好后是这个样子。

[root@centos6rules.d]#vim/etc/udev/rules.d/70-persistent-net.rules
#Thisfilewasautomaticallygeneratedbythe/lib/udev/write_net_rules
#program,NAME="eth0"
#PCIdevice0x8086:0x100f(e1000)
SUBSYSTEM=="net",NAME="eth1"
~

(2).重启或重装网卡驱动,使配置文件生效

查看网卡驱动名:ethtool -i eth2或dmesg|grep -i eth

卸载网卡驱动:modprobe -r e1000 或rmmod e1000

装载网卡驱动:modprobe e1000

[root@centos6rules.d]#dmesg|grep-ieth
e10000000:02:01.0:eth0:(PCI:66MHz:32-bit)00:50:56:3a:fd:74
e10000000:02:01.0:eth0:Intel(R)PRO/1000NetworkConnection
e10000000:02:02.0:eth1:(PCI:66MHz:32-bit)00:50:56:22:c9:22
e10000000:02:02.0:eth1:Intel(R)PRO/1000NetworkConnection
udev:renamednetworkinterfaceeth1toeth2
udev:renamednetworkinterfaceeth0toeth3
e1000:eth3NICLinkisUp1000MbpsFullDuplex,FlowControl:None
8021q:addingVLAN0toHWfilterondeviceeth3
e1000:eth2NICLinkisUp1000MbpsFullDuplex,FlowControl:None
8021q:addingVLAN0toHWfilterondeviceeth2
eth2:noIPv6routerspresent
eth3:noIPv6routerspresent
#阿拉的网卡驱动只有e1000一块,所以阿拉卸载一块就够了。有的网卡名不一样,要分别卸载
[root@centos6rules.d]#rmmode1000
#再用ifconfig查看会发现原网卡信息不见了。(阿拉这一步就不粘代码了)
#装载网卡驱动
[root@centos6rules.d]#modprobee1000
#再次查看,修改成功
[root@centos6~]#ifconfig
eth0Linkencap:EthernetHWaddr00:50:56:22:C9:22
inetaddr:192.168.234.187Bcast:192.168.234.255Mask:255.255.255.0
inet6addr:fe80::250:56ff:fe22:c922/64Scope:Link
UPBROADCASTRUNNINGMULTICASTMTU:1500Metric:1
RXpackets:3errors:0dropped:0overruns:0frame:0
TXpackets:8errors:0dropped:0overruns:0carrier:0
collisions:0txqueuelen:1000
RXbytes:746(746.0b)TXbytes:1152(1.1KiB)

eth1Linkencap:EthernetHWaddr00:50:56:3A:FD:74
inetaddr:172.17.251.174Bcast:172.17.255.255Mask:255.255.0.0
inet6addr:fe80::250:56ff:fe3a:fd74/64Scope:Link
UPBROADCASTRUNNINGMULTICASTMTU:1500Metric:1
RXpackets:475errors:0dropped:0overruns:0frame:0
TXpackets:50errors:0dropped:0overruns:0carrier:0
collisions:0txqueuelen:1000
RXbytes:48665(47.5KiB)TXbytes:7289(7.1KiB)

loLinkencap:LocalLoopback
inetaddr:127.0.0.1Mask:255.0.0.0
inet6addr:::1/128Scope:Host
UPLOOPBACKRUNNINGMTU:65536Metric:1
RXpackets:80errors:0dropped:0overruns:0frame:0
TXpackets:80errors:0dropped:0overruns:0carrier:0
collisions:0txqueuelen:0
RXbytes:6148(6.0KiB)TXbytes:6148(6.0KiB)
原文链接:https://www.f2er.com/centos/376029.html

猜你在找的CentOS相关文章