VM中Centos克隆後致MAC重複故障解決centos
軟件環境:centos 6.4_x86_64bit服務器
故障描述:網絡
用Vmware虛擬機軟件克隆一個centos後,克隆後的系統mac地址與被克隆系統重複致使克隆的虛擬機網絡故障,解決辦法以下。ide
緣由分析:spa
不少Linux distribution使用udev動態管理設備文件,並根據設備的信息對其進行持久化命名。udev會在系統引導的過程當中識別網卡,將mac地址和網卡名稱對應起來記錄在udev的規則腳本中。而VMware會自動生成虛擬機的mac地址。這樣,因爲基本系統的虛擬機已經記錄了該虛擬機的網卡mac地址對應於網卡eth0,在克隆出的虛擬機中因爲mac地址發生改變,udev會自動將該mac對應於網卡eth1。以此類推,udev會記錄全部已經識別的mac與網卡名的關係,因此每次克隆網卡名稱會自動加1,而其實kernel僅僅只識別到一張網卡,跟網卡名相關的網絡配置也未發生任何變化。blog
緣由分析來自一網友 ip
故障解決:get
操做前備份:generator
cp /etc/udev/rules.d/70_persistent-net.rules /etc/udev/rules.d/70-persistent-net.rules.bak博客
故障解決前文件內容爲:
步1:[root@yuanC6~]# vi /etc/udev/rules.d/70-persistent-net.rules
# This file wasautomatically generated by the /lib/udev/write_net_rules
# program, runby the persistent-net-generator.rules rules file.
#
# You can modifyit, as long as you keep each rule on a single
# line, andchange only the value of the NAME= key.
# PCI device0x8086:0x100f (e1000)
SUBSYSTEM=="net",ACTION=="add", DRIVERS=="?*",ATTR{address}=="00:0c:29:87:5d:83", ATTR{type}=="1",KERNEL=="eth*", NAME="eth0" ###註釋這是錯誤內容,刪除該行。
# PCI device0x8086:0x100f (e1000)
SUBSYSTEM=="net",ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:7d:ee:c4",ATTR{type}=="1", KERNEL=="eth*", NAME="eth1" ###註釋把前面的eth1改成0,由於我使用的是eth0因此這裏改成0,強調要改成你要使用的網卡號
步2:
[root@yuanC6 ~]#vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
TYPE=Ethernet
UUID=0c65414f-4fac-4719-863f-8b1ee1a4ccf3
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=none
HWADDR=00:0c:29:7d:ee:c4###註釋修改此處的mac地址要和步一中的紅色mac同樣。
IPADDR=192.138.1.61
PREFIX=24
GATEWAY=192.138.1.1
DNS1=202.101.224.68
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
NAME="Systemeth0"
NETMASK=255.255.255.0
USERCTL=no
步3:
完成前幾步後,重啓服務器便可。
故障解決後文件內容爲:注意粉紅色底紋部分
[root@yuanC6 ~]#cat /etc/udev/rules.d/70-persistent-net.rules
# This file wasautomatically generated by the /lib/udev/write_net_rules
# program, runby the persistent-net-generator.rules rules file.
#
# You can modifyit, as long as you keep each rule on a single
# line, andchange only the value of the NAME= key.
# PCI device0x8086:0x100f (e1000)
SUBSYSTEM=="net",ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:7d:ee:c4",ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
[root@yuanC6 ~]#cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
TYPE=Ethernet
UUID=0c65414f-4fac-4719-863f-8b1ee1a4ccf3
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=none
HWADDR=00:0c:29:7d:ee:c4
IPADDR=192.138.1.61
PREFIX=24
GATEWAY=192.138.1.1
DNS1=202.101.224.68
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
NAME="Systemeth0"
NETMASK=255.255.255.0
USERCTL=no
或參考我老師博客老師的總結:http://oldboy.blog.51cto.com/2561410/1363853