linux 网卡设置/虚拟机克隆后网卡启动失败

静态IP设置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
[root@linux1 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0 
DEVICE=eth0
NAME="System eth0"
TYPE=Ethernet
UUID=9dc04a99-b654-4673-9b19-5100a2b03c51
NM_CONTROLLED=yes
ONBOOT=yes #开机自动启用此网卡设置
BOOTPROTO=static #启用静态IP地址
IPADDR=192.168.245.201 #设置IP地址
GATEWAY=192.168.245.2 #设置网关
NETMASK=255.255.255.0 #设置子网掩码
DNS1=114.114.114.114 #设置主DNS
HWADDR=00:0C:29:D1:9C:4D #网卡mac地址
PREFIX=24
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
LAST_CONNECT=1451228780

[root@linux1 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
NAME="System eth0"
TYPE=Ethernet
UUID=9dc04a99-b654-4673-9b19-5100a2b03c51
NM_CONTROLLED=yes
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.245.201
GATEWAY=192.168.245.2
NETMASK=255.255.255.0
DNS1=114.114.114.114
HWADDR=00:0C:29:D1:9C:4D
PREFIX=24
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
LAST_CONNECT=1451228780

虚拟机中克隆linux后网卡启动失败

克隆的linux主机在启动之后,mac地址发生了变化或者冲突了,重启网卡会出现以下错误

1
2
3
4
5
[root@linux1 rules.d]# service network restart
Shutting down loopback interface: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface eth0: Error: No suitable device found: no device found for connection 'System eth0'.
[FAILED]

解决办法:我们需要修改mac地址
linux主机启动之后,会多出一个DHCP自动分配的网卡eth1(如果没有,通过图形界面配置一个自动获取IP的网卡),找到HWaddr 00:0C:29:D1:9C:4D这一串信息,我们要用到的是新的网卡mac地址:00:0C:29:D1:9C:4D

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
[root@linux1 Desktop]# startx #进入linux图形界面
[root@linux1 Desktop]# ifconfig #查看所有网卡信息
eth1 Link encap:Ethernet HWaddr 00:0C:29:D1:9C:4D
inet6 addr: fe80::20c:29ff:fed1:9c4d/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1574 errors:0 dropped:0 overruns:0 frame:0
TX packets:153 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:108954 (106.4 KiB) TX bytes:13586 (13.2 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:62 errors:0 dropped:0 overruns:0 frame:0
TX packets:62 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:4212 (4.1 KiB) TX bytes:4212 (4.1 KiB)

修改网卡eth0配置中的HWADDR值(网卡mac地址),使用上面的新mac地址:00:0C:29:D1:9C:4D

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
[root@linux1 Desktop]# vi /etc/sysconfig/network-scripts/ifcfg-eth0
[root@linux1 Desktop]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
TYPE=Ethernet
UUID=9dc04a99-b654-4673-9b19-5100a2b03c51
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=none
IPADDR=192.168.245.201
PREFIX=24
GATEWAY=192.168.245.2
DNS1=114.114.114.114
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
NAME="System eth0"
HWADDR=00:0C:29:D1:9C:4D
LAST_CONNECT=1451228780

修改/etc/udev/rules.d/70-persistent-net.rules配置中的mac地址,改成和上面的一致

1
2
3
4
5
6
7
8
9
10
[root@linux1 rules.d]# vi /etc/udev/rules.d/70-persistent-net.rules
[root@linux1 rules.d]# cat /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:D1:9C:4D", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

删除掉网卡eth1(如果不需要的话),重启网卡就能生效了

1
2
3
[root@linux1 rules.d]# ifup eth0
Active connection state: activated
Active connection path: /org/freedesktop/NetworkManager/ActiveConnection/3
请我喝杯农夫山泉吧,原创来之不易
0%