1. 程式人生 > >虛擬機復制出現的網卡問題

虛擬機復制出現的網卡問題

電腦 tar edi -1 con www modified onf end

問題

從另外一臺電腦,直接 把VMware 中的一個linux虛擬機系統 目錄(其中包括.vmx文件和許多.vmkd文件)直接復制到我的電腦,然後用 “打開虛擬機” 方式打開那個目錄,啟動虛擬機,發現居然沒有eth0網卡,只有一個lo。

解決流程

然後在網上找資料,

找到如下資料:

-------------------

VMware虛擬機克隆Linux系統後找不到eth0網卡的問題

有時候,會使用VMware虛擬機的的克隆功能,快速的復制已安裝好的Linux系統。

可是克隆完之後,會發現沒有eth0網卡。

技術分享

解決方法:

1、編輯/etc/udev/rules.d/70-persistent-net.rules文件

技術分享

把NAME="eth0"的那行配置註釋掉或者刪掉,把NAME="eth1"的修改成NAME="eth0",修改後如下:

技術分享

2、更改網卡配置文件,/etc/sysconfig/network-scripts/ifcfg-eth0

技術分享

將HWADDR的值修改為/etc/udev/rules.d/70-persistent-net.rules文件中的新值,修改後如下:

技術分享

3、修改/etc/sysconfig/network,更改主機名

技術分享

修改HOSTNAME

4、重啟系統,reboot。

技術分享

-------------------

按照上面的方法,執行完,用 ifconfig 查看,果然 eth0 出來了,但是,裏面只有要給 inet6,沒有inet,

想到剛才修改 網卡配置文件,/etc/sysconfig/network-scripts/ifcfg-eth0 的時候,

輸入 vim etc/sysconfig/network-scripts/ifcfg-eth0 後,不是正常的直接進入編輯界面,而是

提示了一些東西:

 1 [[email protected] ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
 2 
 3 E325: ATTENTION
 4 Found a swap file by the name "/usr/local/msmtp/etc/.msmtprc.swp"
 5           owned by: root  dated: Thu May 22
15:47:09 2014 6 file name: /etc/sysconfig/network-scripts/ifcfg-eth0 7 modified: YES 8 user name: root host name: zabbix.clvn.com.cn 9 process ID: 3122 10 While opening file "/etc/sysconfig/network-scripts/ifcfg-eth0" 11 dated: Thu May 22 15:44:52 2014 12 13 (1) Another program may be editing the same file. 14 If this is the case, be careful not to end up with two 15 different instances of the same file when making changes. 16 Quit, or continue with caution. 17 18 (2) An edit session for this file crashed. 19 If this is the case, use ":recover" or "vim -r /etc/sysconfig/network-scripts/ifcfg-eth0" 20 to recover the changes (see ":help recovery"). 21 If you did this already, delete the swap file "/etc/sysconfig/network-scripts/ifcfg-eth0.ifcfg-eth0.swp" 22 to avoid this message. 23 24 Swap file /etc/sysconfig/network-scripts/ifcfg-eth0.ifcfg-eth0.swp" already exists! 25 [O]pen Read-Only, (E)dit anyway, (R)ecover, (D)elete it, (Q)uit, (A)bort:

當時,沒管它,直接按的 enter,就進入編輯界面編輯了,是不是這個的問題,就又搜了一下,找到如下文章:

---------------------------------------------------

用Vim編輯文件時出現E325: ATTENTION錯誤的解決方法

當用Vim編輯一個文件時出現下列錯誤

[[email protected] ~]# vim /usr/local/msmtp/etc/msmtprc

E325: ATTENTION
Found a swap file by the name "/usr/local/msmtp/etc/.msmtprc.swp"
owned by: root dated: Thu May 22 15:47:09 2014
file name: /usr/local/msmtp/etc/msmtprc
modified: YES
user name: root host name: zabbix.clvn.com.cn
process ID: 3122
While opening file "/usr/local/msmtp/etc/msmtprc"
dated: Thu May 22 15:44:52 2014

(1) Another program may be editing the same file.
If this is the case, be careful not to end up with two
different instances of the same file when making changes.
Quit, or continue with caution.

(2) An edit session for this file crashed.
If this is the case, use ":recover" or "vim -r /usr/local/msmtp/etc/msmtprc"
to recover the changes (see ":help recovery").
If you did this already, delete the swap file "/usr/local/msmtp/etc/.msmtprc.swp"
to avoid this message.

Swap file "/usr/local/msmtp/etc/.msmtprc.swp" already exists!
[O]pen Read-Only, (E)dit anyway, (R)ecover, (D)elete it, (Q)uit, (A)bort:

解決方法:

方法一、可以在上面出現的提示中按D,將臨時文件刪除掉

方法二、

[[email protected] ~]# cd /usr/local/msmtp/etc
[[email protected] etc]# ls -a
. .. msmtprc .msmtprc.swp

[[email protected] etc]# rm -rf .msmtprc.swp

Vim學習指南 http://www.linuxidc.com/Linux/2013-08/89096.htm

快速學會 Vi編輯器 http://www.linuxidc.com/Linux/2013-08/88586.htm

強大的Vim 編輯器 http://www.linuxidc.com/Linux/2013-07/87544.htm

在CentOS 6.2上搭建Vim開發環境 http://www.linuxidc.com/Linux/2013-07/87363.htm

Vim 7.4a 發布,全新更快的正則表達式引擎 http://www.linuxidc.com/Linux/2013-07/87035.htm

CentOS 5.4 安裝高亮Vim編輯工具 http://www.linuxidc.com/Linux/2013-06/86508.htm

Vim技巧分享:C語言設置 http://www.linuxidc.com/Linux/2012-12/77124.htm

Ubuntu中設置Vim的行號 http://www.linuxidc.com/Linux/2012-12/75485.htm

Vim編輯器使用基礎教程 http://www.linuxidc.com/Linux/2013-05/84031.htm

本文永久更新鏈接地址:http://www.linuxidc.com/Linux/2014-05/102255.htm

技術分享

----------------------------------------------

按照上面說的,直接 按 D 【應該是刪除了臨時文件 同名的 .swp文件】,然後再退出,保存。重啟網卡服務:

重啟服務:service network restart

技術分享

出現determining ip information for eth0 fail... 查了一下,發現是因為,自己選的此虛擬機網絡 是 橋接模式,網卡配置裏,BOOTPROTO 設置的是dhcp ,但是 局域網內可能又沒有dhcp服務器,所以導致,eth0網卡獲取不到ip,於是把 網卡配置中的 BOOTPROTO 改成static:

更改網卡配置文件,/etc/sysconfig/network-scripts/ifcfg-eth0

技術分享

重啟網絡服務,問題解決。 。。。。。 總結啟示: 其實,這個問題最開始,可能根本就不需要這些配置, 1、只需要發現沒有網卡eth0時, 就修改 網卡配置文件, 2、發現 提示存在臨時文件,直接按D刪除臨時文件,再配置好 ip地址及靜態等然後直接保存,重啟網卡服務後可能就好了。

虛擬機復制出現的網卡問題