Introduction to kvm network virtualization

Introduction to QEMU network types

In QEMU, the client mainly provides four different network configuration schemes:
1. Bridge-based virtual network card mode
2. NAT-based virtual network mode
3. QEMU built-in user network mode
4 , direct assignment network setting mode

Bridge and NAT are software virtual network modes implemented based on linux-bridge. QEMU is a virtual network mode of QEMU software. The fourth network mode is directly allocated to clients based on physical network cards. For example, a physical machine has eth0 and There are two physical network cards in eth1, and the network card of eth0 is directly assigned to a client for use.

Remarks:
The full path of qemu-kvm is /usr/libexec/qemu-kvm , in order to avoid entering the full path every time, you can use the soft link to set it, the command is as follows:

ln -sv /usr/libexec/qemu-kvm /usr/bin/

Virtualization network card setting command

The details of the basic "-net" parameter in the qemu-kvm command line are as follows:
-net nic[, vlan=n ] [,m acaddr=mac] [,model=type ][,name=name] [,addr=addr ] [,vectors=v]

Executing this command line will cause QEMU to create a new network card and connect it to VLAN n. Among them
:
"-net nic" is a required parameter, indicating that this is a network card configuration.
1) vlan=n, means put the network card into the VLAN numbered n, the default is 0.
2) macaddr=mac, set the MAC address of the network card, which will be allocated according to the address of the network card in the host by default. If there are too many clients in the LAN, it is recommended to set the MAC address by yourself to prevent MAC address conflicts.
3) model= type, set the type of the simulated network card, the default is rtl8139 in qemu-kvm. Use qemu-kvm -net nic, model=? to query the type of network card supported by kvm
4) name=name, set an easy-to-read name for the network card, which may only be used in QEMU monitor.
5) addr=addr, set the PCI device address of the network card in the client to addr.
6) vectors=v, set the number of MSI-X vectors of the network card device to n, which is only valid for network cards driven by virtio. Set to "vectors=0" to disable the MSI-X interrupt mode of the virtio network card.

Example:
-net vlan=0,macaddr=fe:54:00:86:0d:04,model=rtl8139 ,name=eth0,addr=0x0
If you need to provide multiple network cards to a client, you can use "- net" parameter

Check the virtual network card

qemu-kvm provides simulations of a series of mainstream and well-compatible network cards. Through the "-net nic,model=?" parameter, you can query which network card simulations are implemented by the current qemu-kvm tool.
insert image description here

  • "rtl8139" network card mode is the default analog network card type of qemu-kvm. RTL8139 is a 10/100M network card series of Realtek Semiconductor Company. It was once very popular (of course it seems a bit old now) and has good compatibility. Almost all Modern operating systems provide support for RTL8139 network card drivers
  • "e1000" provides Intel e1000 series NIC emulation, and pure QEMU (not qemu-kvm) provides Intel e1000 series virtual NIC by default.
  • The virtio type is qemu-kvm's support for paravirtualized IO (virtio) drivers

The biggest difference between these three network cards (here refers to the place that needs the most attention) is the speed:
rtl8139 10/100Mb/s
e1000 1Gb/s
virtio 10Gb/s

The following are introductions to two commonly used network virtualization solutions.

bridge mode

In the network use of QEMU/KVM, the bridge mode allows the client and the host to share a physical network device to connect to the network. The client has its own independent IP address and can directly connect to the same network as the host. The computer can access the external network, and the external network can also directly access the client (just like accessing an ordinary physical host).

Even if the host has only one network card device, the bridge mode can be used to allow multiple clients to share the network device with the host. The network diagram is as follows: As shown in the above figure, the basic principle of the bridge is to
insert image description here
create a bridging interface br0 between the physical network card and the host. Pass data between virtual network interfaces
! [Insert picture description here](https://img-blog.csdnimg.cn/75e05a9db1904fa2b1b8c3d53ed35984.png

The following is the output of the ifconfig command. The other br0 is the bridge interface, and eth0 is the real network card.
insert image description here
After creating a virtual machine on this host, there will be an additional vnet0 network card. The virtual network card vnet# is automatically created when the virtual machine is created. . All we have to do is associate br0 with the virtual network card vnet#
insert image description here

NAT mode

NAT mode is the default mode after kvm installation. It supports mutual visits between hosts and virtual machines, and also supports virtual machines to access the Internet, but does not support external access to virtual machines.

Among them, virbr0 is a virtual network interface generated when the host virtual machine support module is installed, and is also a switch and bridge, responsible for distributing content to each virtual machine.
insert image description here
As can be seen from the figure, there is no connection between the virtual interface and the physical interface, so the virtual machine can only access the outside world through the virtual network

Guess you like

Origin blog.csdn.net/xiao3404/article/details/129917232