KVM虚拟机无法连网分析
1. 主机设置 virtio 网络
两种方法:
a. virt-manager 图形设置,如下
b. 命令行设置
在 <devices> 和 </devices> 之间找一个合适的地方添加如下:# virsh edit <domin name>
<interface type='network'> <mac address='52:54:00:af:77:01'/> <source network='default'/> <model type='virtio'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> </interface>
通过以上步骤后,发现虚拟机仍然无法连接网络。
2. 虚拟机内查看 网络接口
得到如下:# ip link show
观察到主机虽然添加了硬件,但是虚拟机网络接口并不可见。下面就需要查看虚拟机硬件。1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 2: sit0@NONE: <NOARP> mtu 1480 qdisc noop state DOWN mode DEFAULT group default link/sit 0.0.0.0 brd 0.0.0.0
3. 虚拟机内查看 硬件
得到如下:# lspci
“00:03.0 Ethernet controller: Red Hat, Inc Virtio network device” 可以看出虚拟机上已经存在步骤1 中添加的硬件了。下面需要查看虚拟机驱动。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 82371SB PIIX3 IDE [Natoma/Triton II] 00:01.3 Bridge: Intel Corporation 82371AB/EB/MB PIIX4 ACPI (rev 03) 00:02.0 VGA compatible controller: VMware SVGA II Adapter 00:03.0 Ethernet controller: Red Hat, Inc Virtio network device 00:04.0 Audio device: Intel Corporation 82801FB/FBM/FR/FW/FRW (ICH6 Family) High Definition Audio Controller (rev 01) 00:05.0 SATA controller: Intel Corporation 82801IR/IO/IH (ICH9R/DO/DH) 6 port SATA Controller [AHCI mode] (rev 02) 00:06.0 USB controller: Intel Corporation 82801I (ICH9 Family) USB UHCI Controller #1 (rev 03) 00:06.1 USB controller: Intel Corporation 82801I (ICH9 Family) USB UHCI Controller #2 (rev 03) 00:06.2 USB controller: Intel Corporation 82801I (ICH9 Family) USB UHCI Controller #3 (rev 03) 00:06.7 USB controller: Intel Corporation 82801I (ICH9 Family) USB2 EHCI Controller #1 (rev 03) 00:07.0 Communication controller: Red Hat, Inc Virtio console 00:08.0 Unclassified device [00ff]: Red Hat, Inc Virtio memory balloon
4. 虚拟机内查看驱动
得到如下:# lsmod
看出virtio 这个网络设备对应的驱动并没有加载。Module Size Used by nfsd 231723 13
最后,选择 virtio_net 这个驱动,重新编译内核,重启机器,加载驱动后,网络正常。
最后主机上的加载模块:
# lsmod Module Size Used by nfsd 231723 13 virtio_net 17177 0 virtio_pci 11567 0 virtio_ring 5621 2 virtio_net,virtio_pci virtio 4479 2 virtio_net,virtio_pci