KVM --- Virtual Network Manager

  In the blog post, we completed the installation of KVM virtual machine, but I found the virtual machine within the network is unreasonable (of course, at the time of writing this blog has already made the desired changes on the blog post configuration files, network also pass, hehe), so this blog summed up the virtual machine's network connection and configuration. In the virtual machine, there is a common Internet a virtual machine are two types of NAT mode, the other is the Bridge (bridge mode), other patterns such as host-only mode is not discussed here.

Pre-knowledge

  When we installed the KVM, if you use ifconfig look, in fact, we found our host has more than one virtual network interface, it is because it will generate a virbr0 (virtual bridge) on the host after libvirt start, host top All virtual machines are connected by this virbr0. By default virbr0 using NAT mode, so in this case, guest can only access to the outside through the host.

 

For the role of virbr0 generated and default connection, I refer to intercept the bottom of the blog a picture to illustrate:

Some small partners might wonder, why virbr0 the inet (IP address) for the image above the red box in it? Let us look at the host virtual network (virtual machine network connection) situation, as shown below:

We found a name for the default virtual network, let's open about its configuration file to look at, enter the following command to view:

View Results (usually in the following figure profile name to the same name and the bridge, so with brctl show command and with virsh net-list view as the command):

NAT mode connection

  This time get the point, this configuration file is installed by default when death has been written, and there's ip address what we see in the ipconfig command; Part blog in centos_config.xml virtual machine configuration file about the network part specify the source option get the idea for the reason of default, it is to bind generated after the virtual machine is turned on to the bridge above the virtual NIC (virtual machine mac address specified in the configuration file, open the file when this bridge, this will start a service dhcp service, the service is implemented libvirt simulation, the customer can dhcp service configuration specified in the ip address range assigned a random ip). As can be seen from the figure above is the configuration mode mode = 'nat', so that it can communicate with the host via the external network. Of course, we can also define your own configuration files to generate the above-mentioned another card, then you can be bound by a source to fill in your new network name in the host network to modify the configuration file, provided that you define must bridge He walked up ( virsh NET-dEFINE command to define a bridge, virsh bridge names NET-Start command bridge service enabling, by virsh net-list view bridge status command, as shown in the figure above, if state represents successfully turned to active, the specific operation may be analogous to the operation of the following bridged network).

  Then we log into the client can use the command ip a view (similar to Ubuntu ifconfig), it found that the network ens3 has not been assigned ip address:

At this point we can use the command dhclient apply to the dhcp server IP address, and then check again:

At this time, check the network and the external network is capable of communication:

Bridge Mode

  If you want to connect via ssh to your client, you may need to connect via bridge mode, the following figure is probably way bridge mode, first create a bridge, then the virtual network adapter virtual machines are mounted (inserted) to the the bridge, on the other end to the physical NIC, so depending on the mode of Layer 2 forwarding bridge, can be a bridge to forward the frame to the socket where the individual virtual machines. What if we want to connect the virtual machine through the bridge, you will need three steps:

step 1: establish a bridge:

  Editing a bridge configuration file, named: demo0.xml, contents as shown below

  Define the bridge:

  Open this bridge:

Check whether they have open (you can see already open):

With ifconfig look:

With brctl show look at the command:

step 2: the virtual machine is turned on first (before the above-described operation do I have undefine virtual machine, and then modify the configuration file, the name of the configuration of the network portion of the source to the demo0, only the interception FIG virtual machine configuration file section, see the full version of the blog post ):

  Redefine and open the virtual machine:

  This time with a look at brctl show command (you can see the virtual NIC created the virtual machine is turned on has been inserted demo0 bridge):

step 3: the physical NIC also insert bridge (you can see my name via the physical NIC ifconfig command ens33):

  At this time, virtual machines and physical machines will be able to access external networks, we try to enter the virtual machine (VM If you do not have a network ip address, same as above execute dhclient command to):

Note: At this point you can see from the image above IP address of the virtual machine is a physical machine and the IP address is the same network segment, please search the specific reasons for the bridge and NAT connection for viewing.

  Look at whether it can pass outside the network:

So far, we have completed the virtual machine network connection of the machine and the client!

 

References:

https://blog.csdn.net/hzhsan/article/details/44653403

https://www.linuxidc.com/Linux/2013-08/88720.htm

https://www.linuxidc.com/Linux/2013-08/88517.htm

There is also grateful to my colleagues-ho enthusiasm to explain!

  

 

Guess you like

Origin www.cnblogs.com/zpcoding/p/11403365.html