linux 虚拟机拷贝后无法上网 -电脑资料

电脑资料 时间:2019-01-01 我要投稿
【www.unjs.com - 电脑资料】

   

    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 虚拟机拷贝后无法上网

    这里做一下说明:

    每一个虚拟机会有一网卡,当我们先创建虚拟机再安装linux系统,那么安装过程中系统会检测当前机器(系统并不知道这是个虚拟机还是实体机)的各个硬件并自动初始化完成配置,

电脑资料

linux 虚拟机拷贝后无法上网》(https://www.unjs.com)。这时的配置一般是正确的。当我们把这个安装完系统的虚拟机,拷贝到另一个位置后再打开。这相当于把原来一台电脑拿到了另一个地方,但有一点不一样。拷贝来的虚拟机在新的宿主机上运行时会自动由虚拟机软件虚拟出来一个新的网卡。这一次相当于把原来那台电脑换了一个网卡,而系统还是原来的,所以系统的网络配置文件里保存的还是之前的网卡信息。所以就出现在了上面的情况。

    那么我们可以做什么呢?

    我们可以在/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就行了。

最新文章