1. 程式人生 > >CentOS6 虛擬機遷移後網卡名更改問題解決

CentOS6 虛擬機遷移後網卡名更改問題解決

linux

實驗過程中,我們經常需要復制虛擬機,以模仿生產過程中同等配置的條件。

但無論是初次打開,選擇"我已復制該虛擬機“也好,還是在虛擬機設置>網絡適配器>高級中重新生成Mac地址,開機後選擇”我已移動該虛擬機“也罷。開機後查詢IP時,我們都會很遺憾的發現,網卡的名字,不一樣了。

這是因為原Mac地址占用舊網卡,新Mac地址只能使用新的網卡名稱。復制虛擬機為了不與原虛擬機沖突,也是生成了新的Mac地址。

[[email protected] ~]# ifconfig
eth2      Link encap:Ethernet  HWaddr 00:50:56:22:C9:22  
          inet addr:192.168.234.187  Bcast:192.168.234.255  Mask:255.255.255.0
          inet6 addr: fe80::250:56ff:fe22:c922/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1 
          RX packets:4 errors:0 dropped:0 overruns:0 frame:0
          TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:806 (806.0 b)  TX bytes:1152 (1.1 KiB)
eth3      Link encap:Ethernet  HWaddr 00:50:56:3A:FD:74  
          inet addr:172.17.251.174  Bcast:172.17.255.255  Mask:255.255.0.0
          inet6 addr: fe80::250:56ff:fe3a:fd74/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:2565 errors:0 dropped:0 overruns:0 frame:0
          TX packets:61 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:243027 (237.3 KiB)  TX bytes:9974 (9.7 KiB)
lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:4 errors:0 dropped:0 overruns:0 frame:0
          TX packets:4 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:240 (240.0 b)  TX bytes:240 (240.0 b)

雖然不影響使用,但怎麽看都不舒服啊。而且有些實驗中網卡名不統一也只有麻煩。正所謂沒有標準化就很難進行自動化管理。

那麽,如何更改遷移後的虛擬機的網卡名呢?


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

[[email protected] ~]# vim /etc/udev/rules.d/70-persistent-net.rules 
# This file was automatically generated by the /lib/udev/write_net_rules
# program, run by the persistent-net-generator.rules rules file.
#
# You can modify it, as long as you keep each rule on a single
# line, and change only the value of the NAME= key.
# PCI device 0x8086:0x100f (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:13:d6:94", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

# PCI device 0x8086:0x100f (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:13:d6:9e", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"

# PCI device 0x8086:0x100f (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:50:56:22:c9:22", ATTR{type}=="1", KERNEL=="eth*", NAME="eth2"

# PCI device 0x8086:0x100f (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:50:56:3a:fd:74", ATTR{type}=="1", KERNEL=="eth*", NAME="eth3"

刪除原Mac,更改NAME值,搞定。改好後是這個樣子。

[[email protected] rules.d]# vim /etc/udev/rules.d/70-persistent-net.rules 
# This file was automatically generated by the /lib/udev/write_net_rules
# program, run by the persistent-net-generator.rules rules file.
#
# You can modify it, as long as you keep each rule on a single
# line, and change only the value of the NAME= key.
# PCI device 0x8086:0x100f (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:50:56:22:c9:22", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
# PCI device 0x8086:0x100f (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:50:56:3a:fd:74", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"
~

(2).重啟或重裝網卡驅動,使配置文件生效

查看網卡驅動名:ethtool -i eth2或dmesg|grep -i eth

卸載網卡驅動:modprobe -r e1000 或rmmod e1000

裝載網卡驅動:modprobe e1000

[[email protected] rules.d]# dmesg|grep -i eth
e1000 0000:02:01.0: eth0: (PCI:66MHz:32-bit) 00:50:56:3a:fd:74
e1000 0000:02:01.0: eth0: Intel(R) PRO/1000 Network Connection
e1000 0000:02:02.0: eth1: (PCI:66MHz:32-bit) 00:50:56:22:c9:22
e1000 0000:02:02.0: eth1: Intel(R) PRO/1000 Network Connection
udev: renamed network interface eth1 to eth2
udev: renamed network interface eth0 to eth3
e1000: eth3 NIC Link is Up 1000 Mbps Full Duplex, Flow Control: None
8021q: adding VLAN 0 to HW filter on device eth3
e1000: eth2 NIC Link is Up 1000 Mbps Full Duplex, Flow Control: None
8021q: adding VLAN 0 to HW filter on device eth2
eth2: no IPv6 routers present
eth3: no IPv6 routers present
#阿拉的網卡驅動只有e1000一塊,所以阿拉卸載一塊就夠了。有的網卡名不一樣,要分別卸載
[[email protected] rules.d]# rmmod e1000
#再用ifconfig查看會發現原網卡信息不見了。(阿拉這一步就不粘代碼了)
#裝載網卡驅動
[[email protected] rules.d]# modprobe e1000
#再次查看,修改成功
[[email protected] ~]# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:50:56:22:C9:22  
          inet addr:192.168.234.187  Bcast:192.168.234.255  Mask:255.255.255.0
          inet6 addr: fe80::250:56ff:fe22:c922/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:3 errors:0 dropped:0 overruns:0 frame:0
          TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:746 (746.0 b)  TX bytes:1152 (1.1 KiB)

eth1      Link encap:Ethernet  HWaddr 00:50:56:3A:FD:74  
          inet addr:172.17.251.174  Bcast:172.17.255.255  Mask:255.255.0.0
          inet6 addr: fe80::250:56ff:fe3a:fd74/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:475 errors:0 dropped:0 overruns:0 frame:0
          TX packets:50 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:48665 (47.5 KiB)  TX bytes:7289 (7.1 KiB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:80 errors:0 dropped:0 overruns:0 frame:0
          TX packets:80 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:6148 (6.0 KiB)  TX bytes:6148 (6.0 KiB)


本文出自 “RightNow” 博客,請務必保留此出處http://amelie.blog.51cto.com/12850951/1962642

CentOS6 虛擬機遷移後網卡名更改問題解決