kvm-网络基础和网络相关命令的介绍
1、基础知识
1.1、网络模型
1.1.1、kvm网络模型介绍【nat和bridge】
kvm类型的虚拟机,默认情况下使用的是nat网络,同一网络模型下创建的多虚拟机之间可以彼此通信,这种网络模型与外界网络进行通信依赖于nat服务,nat服务正常的话,
该模型的网络是通过数据包的转换来达到通信的效果的,在网络流量比较大的场景下,该模式的网络模型会成为虚拟机的瓶颈。
生产中我们一般采用桥接的网络模型,这种模型是借助于宿主机的网卡设备,直接与外网进行通信,效果很好。
1.1.2、网络模型图
1.2、网络配置方式
对于kvm来说,它有两种网络:永久网络和临时网络
1.3、配置流程
前提:保证宿主机网络正常,网络服务使用network
首先:生成新的桥接设备
其次:关联桥设备和物理网卡设备
然后:清空物理网卡地址,启用桥设备地址,设置网络网关为桥设备地址
最后:虚拟机使用桥设备
2、实战
2.1、基本配置
2.1.1、kvm的网络配置目录位置
# tree /etc/libvirt/qemu/networks/ /etc/libvirt/qemu/networks/ ├── autostart │ └── default.xml -> /etc/libvirt/qemu/networks/default.xml └── default.xml
2.1.2、查看桥接网络
# ifconfig vnet0 vnet0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet6 fe80::fc54:ff:fef4:2dfc prefixlen 64 scopeid 0x20<link> ether fe:54:00:f4:2d:fc txqueuelen 1000 (Ethernet) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 2581 bytes 134596 (134.5 KB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
2.1.3、查看vrish所有网络相关命令
# virsh -h | grep net- net-autostart autostart a network net-create create a network from an XML file net-define define an inactive persistent virtual network or modify an existing persistent one from an XML file net-destroy destroy (stop) a network net-dhcp-leases print lease info for a given network net-dumpxml network information in XML net-edit edit XML configuration for a network net-event Network Events net-info network information net-list list networks net-name convert a network UUID to network name net-start start a (previously defined) inactive network net-undefine undefine a persistent network net-update update parts of an existing network's configuration net-uuid convert a network name to network UUID net-port-list list network ports net-port-create create a network port from an XML file net-port-dumpxml network port information in XML net-port-delete delete the specified network port
2.2、网络查看
2.2.1、查看网络列表
virsh net-list
virsh net-list --all
2.2.2、查看网络信息
# virsh net-info default Name: default UUID: 178c4147-c955-4252-827d-84b4b78a65d1 Active: yes Persistent: yes Autostart: yes Bridge: virbr0
2.2.3、查看网络配置
# virsh net-dumpxml default <network connections='1'> <name>default</name> <uuid>178c4147-c955-4252-827d-84b4b78a65d1</uuid> <forward mode='nat'> <nat> <port start='1024' end='65535'/> </nat> </forward> <bridge name='virbr0' stp='on' delay='0'/> <mac address='52:54:00:eb:07:52'/> <ip address='192.168.122.1' netmask='255.255.255.0'> <dhcp> <range start='192.168.122.2' end='192.168.122.254'/> </dhcp> </ip> </network>