linux 虚拟机拷贝后无法上网

linux 虚拟机拷贝后启动后使用ifconfig命令显示:



[root@localhost ~]# ifconfig

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)

[root@localhost ~]# 

使用service network restart 命令显示:

[root@localhost ~]# service network restart

Shutting down interface eth0:                              [  OK  ]
Shutting down loopback interface:                          [  OK  ]
Bringing up loopback interface:                            [  OK  ]
Bringing up interface eth0:device "eth0" does not seem to be present, delaying initialization.

[root@localhost ~]#


这说明没有虚拟机拷贝后开机时虚拟出来的新的网卡没有正常工作。

这里做一下说明:

每一个虚拟机会有一网卡,当我们先创建虚拟机再安装linux系统,那么安装过程中系统会检测当前机器(系统并不知道这是个虚拟机还是实体机)的各个硬件并自动初始化完成配置。这时的配置一般是正确的。当我们把这个安装完系统的虚拟机,拷贝到另一个位置后再打开。这相当于把原来一台电脑拿到了另一个地方,但有一点不一样。拷贝来的虚拟机在新的宿主机上运行时会自动由虚拟机软件虚拟出来一个新的网卡。这一次相当于把原来那台电脑换了一个网卡,而系统还是原来的,所以系统的网络配置文件里保存的还是之前的网卡信息。所以就出现在了上面的情况。

那么我们可以做什么呢?

我们可以在/etc/udev/rules.d/目录下找到70-persistent-net.rules

我们可以cat 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:78:86:e9", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

这个文件是自动生成的。其中这个设备的mac为00:0c:29:78:86:e9,而我们cat /etc/sysconfig/network-scripts/ifcfg-eth0 可以看到这里面的mac和70-persistent-net.rules中的不一样。

所以我们开机后来配置网络时用的是这个/etc/sysconfig/network-scripts/ifcfg-eth0脚本,这个脚本中用到的是一个不存在的网卡所不能上网。所以我们只把mac改成自动检测到的那个网络设备就的mac就行了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值