异想天开

What's the true meaning of light, Could you tell me why

虚拟机网卡消失

日期:2014-09-19 10:43:18
  
最后更新日期:2014-09-21 11:10:43
【技术文章,非码农勿入】
最后更新时间: 2014-9-19

在virtual虚拟机安装pptpd的vpn时,重新开机后,发现网卡‘不见’了,不能联网了。这下蛋疼了,虚拟机与主机没有共享目录。幸亏,记得当时是由于ppp库版本是最新的,卸载这个库,自己本地安装了低版本的库。卸载ppp库的时候,同时把network-manage也卸载掉了。当时首先想到就是看系统的启动日志,看开机自检检测出网卡没有。 [code lang="cpp"]
#现在我的电脑网卡正常时的信息
[root@localhost ~]# cat /var/log/boot.log | grep eth
Bringing up interface eth0:
Determining IP information for eth0... done.
[root@localhost ~]# lspci
00:00.0 Host bridge: Intel Corporation 440FX - 82441FX PMC [Natoma] (rev 02)
00:01.0 ISA bridge: Intel Corporation 82371SB PIIX3 ISA [Natoma/Triton II]
00:01.1 IDE interface: Intel Corporation 82371AB/EB/MB PIIX4 IDE (rev 01)
00:02.0 VGA compatible controller: InnoTek Systemberatung GmbH VirtualBox Graphics Adapter
00:03.0 Ethernet controller: Intel Corporation 82540EM Gigabit Ethernet Controller (rev 02)
00:04.0 System peripheral: InnoTek Systemberatung GmbH VirtualBox Guest Service
00:05.0 Multimedia audio controller: Intel Corporation 82801AA AC'97 Audio Controller (rev 01)
00:06.0 USB controller: Apple Inc. KeyLargo/Intrepid USB
00:07.0 Bridge: Intel Corporation 82371AB/EB/MB PIIX4 ACPI (rev 08)
00:0b.0 USB controller: Intel Corporation 82801FB/FBM/FR/FW/FRW (ICH6 Family) USB2 EHCI Controller
00:0d.0 SATA controller: Intel Corporation 82801HM/HEM (ICH8M/ICH8M-E) SATA Controller [AHCI mode] (rev 02)
[/code]
网卡驱动是内核模块,那么可以通过:
[code lang="cpp"]
[root@localhost ~]# dmesg | grep eth
e1000 0000:00:03.0: eth0: (PCI:33MHz:32-bit) 08:00:27:34:62:61
e1000 0000:00:03.0: eth0: Intel(R) PRO/1000 Network Connection
ADDRCONF(NETDEV_UP): eth0: link is not ready
e1000: eth0 NIC Link is Up 1000 Mbps Full Duplex, Flow Control: RX
ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
eth0: no IPv6 routers present
[/code]
来查看驱动的加载的情况,可能搜索时要换一个关键字。ping 127.0.0.1也能ping通,ping百度的ip地址不行。
[code lang="cpp"]
#在其他另外一台电脑上面执行
[root@localhost ~]# rpm -qa | grep network
kdenetwork-4.3.4-11.el6_0.1.x86_64
system-config-network-tui-1.6.0.el6.2-1.el6.noarch
kdenetwork-libs-4.3.4-11.el6_0.1.x86_64
而在这台虚拟机上面没有显示
[/code]
说明是网络配置服务被卸载了。那么现在问题就是安装这个模块即可。首先确认发行版本,我记得是centos,突然具体版本不记得了:
[code lang="cpp"]
#这个方法比较通用
[root@localhost ~]# cat /etc/issue
CentOS release 6.5 (Final)
Kernel \r on an \m
#还可以
[root@localhost ~]# cat /etc/system-release
CentOS release 6.5 (Final)
[/code]
ok,6.5。兴冲冲只奔163镜像站点把centos 6.5的这个rpm包下载回来。用软碟通放到iso里面,让虚拟机挂载,接着安装。发现还依赖了其它几个包,当时想简单把这几个包也手动下载回来,结果依赖一大坨东东,顿时恶心了。还是用yum自动安装即可。想起发行版装好时,基本网络能用。那么镜像的iso文件里面应该有所有的依赖的包。内网下载一个centos 6.5 的系统iso。本地搭建源:
[code lang="cpp"]
#查看yum源
[root@localhost ~]# ls /etc/yum.repos.d/
adobe-linux-x86_64.repo CentOS-Media.repo
CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Vault.repo
#备份CentOS-Base.repo即可
[root@localhost ~]#mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
#在/etc/yum.repos.d/编辑一个新的CentOS-Base.repo
[root@localhost ~]# cat /etc/yum.repos.d/CentOS-Base.repo
[c6-media]
name=CentOS-$releasever-Media
baseurl=file:////media/CentOS_6.5_Final
gpgcheck=0
enabled=1
#/media/CentOS_6.5_Final这个就是你系统iso挂载的地方
[/code]
然后安装yum install system-config-network-tui。若还有个别noarch依赖失败的,手动下载回来安装了即可,这样system-config-network-tui就能用yum安装成功了。安装后发现eth0没有,只有eth1,同时eth1的ip也木有分配。这个问题之前遇到过,只因为曾把虚拟机的网卡地址,手动更新后。更新后的地址就是eth1,系统的eth0的mac地址还留在系统。忘记是那个文件去了,记得好像有个70。
[code lang="cpp"]
[root@localhost sysconfig]# find /etc/ -name "*70*" -print
...
/etc/udev/rules.d/70-persistent-net.rules
...
[/code]
找到了,打开这个文件,删除eth0的项,把eth1更改为eth0。
[code lang="cpp"]
[root@localhost sysconfig]# 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:0x100e (e1000)
#SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="08:00:27:20:dc:00", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

# PCI device 0x8086:0x100e (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="08:00:27:34:62:61", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
[/code]
同时,还需要设置dhcp。
[code lang="cpp"]
[root@localhost sysconfig]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE="eth0"
#加上下面这句即可,这句开始没有
#BOOTPROTO=dhcp
HWADDR="08:00:27:34:62:61"
NM_CONTROLLED="yes"
ONBOOT="YES"
[/code]
经验:操作virtualbox一定要记得先使用快照功能备份。