在对VMWare的虚拟机进行复制之后,新的虚拟机会出现网络无法启动的问题,在实体机当中还没遇到,不过解决办法应该是通用的。

1、首先重命名 /etc/udev/rules.d/70-persistent-net.rules文件,并重启虚拟机。

Shell

cd /etc/udev/rules.d/

mv 70-persistent-net.rules 70-persistent-net.rules.bak

reboot

1

2

3

cd/etc/udev/rules.d/

mv70-persistent-net.rules70-persistent-net.rules.bak

reboot

重启后, 机器自己重新生成/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 0x1022:0x2000 (pcnet32)

SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:50:bd:1

7", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"

1

2

3

4

5

6

7

8

9

# 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 0x1022:0x2000 (pcnet32)

SUBSYSTEM=="net",ACTION=="add",DRIVERS=="?*",ATTR{address}=="00:0c:29:50:bd:1

7",ATTR{type}=="1",KERNEL=="eth*",NAME="eth1"

记下文件中显示的Mac地址信息以及网卡名称eth1,一会要用到。

2、修改网卡的文件名称。

mv /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth1

1

mv/etc/sysconfig/network-scripts/ifcfg-eth0/etc/sysconfig/network-scripts/ifcfg-eth1

默认的网卡名称为eth0,对应的文件名是ifcfg-eth0,需要根据刚才文件的内容将文件名改为ifcfg-eth1。

3、编辑ifcfg-eth1文件内容

DEVICE="eth1" #修改网卡名称

BOOTPROTO=dhcp

HWADDR="00:0C:29:50:bd:17" #把地址改成刚才看到的MAC地址

NM_CONTROLLED="yes"

ONBOOT="yes"

1

2

3

4

5

DEVICE="eth1"#修改网卡名称

BOOTPROTO=dhcp

HWADDR="00:0C:29:50:bd:17"#把地址改成刚才看到的MAC地址

NM_CONTROLLED="yes"

ONBOOT="yes"

4、重新启动网络服务

service network restart

1

servicenetworkrestart

重启后系统会输出提示信息:

Shutting down interface eth1: [ OK ]

Shutting down loopback interface: [ OK ]

Bringing up loopback interface: [ OK ]

Bringing up interface eth1:

Determining IP information for eth1... done.

[ OK ]

1

2

3

4

5

6

Shuttingdowninterfaceeth1:[OK]

Shuttingdownloopbackinterface:[OK]

Bringinguploopbackinterface:[OK]

Bringingupinterfaceeth1:

DeterminingIPinformationforeth1...done.

[OK]

网络服务重启成功。

5、查看获取到的IP地址

ifconfig

1

ifconfig

可以看到系统输出了eth1网卡的相关信息,包括MAC地址、IP、子网掩码等内容。

eth1 Link encap:Ethernet HWaddr 00:0C:29:51:36:61

inet addr:172.16.109.145 Bcast:172.16.109.255 Mask:255.255.255.0

inet6 addr: fe80::20c:29ff:fe51:3661/64 Scope:Link

UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1

RX packets:167 errors:0 dropped:0 overruns:0 frame:0

TX packets:142 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:1000

RX bytes:17298 (16.8 KiB) TX bytes:21562 (21.0 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:16436 Metric:1

RX packets:0 errors:0 dropped:0 overruns:0 frame:0

TX packets:0 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:0

RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

eth1Linkencap:EthernetHWaddr00:0C:29:51:36:61

inetaddr:172.16.109.145Bcast:172.16.109.255Mask:255.255.255.0

inet6addr:fe80::20c:29ff:fe51:3661/64Scope:Link

UPBROADCASTRUNNINGMULTICASTMTU:1500Metric:1

RXpackets:167errors:0dropped:0overruns:0frame:0

TXpackets:142errors:0dropped:0overruns:0carrier:0

collisions:0txqueuelen:1000

RXbytes:17298(16.8KiB)TXbytes:21562(21.0KiB)

loLinkencap:LocalLoopback

inetaddr:127.0.0.1Mask:255.0.0.0

inet6addr:::1/128Scope:Host

UPLOOPBACKRUNNINGMTU:16436Metric:1

RXpackets:0errors:0dropped:0overruns:0frame:0

TXpackets:0errors:0dropped:0overruns:0carrier:0

collisions:0txqueuelen:0

RXbytes:0(0.0b)TXbytes:0(0.0b)

成功获取到了IP地址,这样虚拟机就可以和其他服务器进行通信了。

Logo

更多推荐