In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces how to use Bridge and Nat to configure the network of the KVM virtual machine, which has a certain reference value. Interested friends can refer to it. I hope you can learn a lot after reading this article.
Use libvirt to configure the network of the KVM virtual machine, using bridge and nat, respectively.
Operating system configuration: centos7,libvirt-1.1.1,qemu-1.5.3
1.bridged (bridging mode)
In bridged mode, the virtual operating system is like an independent host in the local area network, which can access any machine in the network. At the same time, because the virtual system is an independent host system in the local area network, its TCP/IP configuration information can be manually configured to access the Internet through the local area network gateway or router. The relationship between a virtual system using bridged mode and the host machine is like two computers connected to the same Hub. If you want them to communicate with each other, you need to configure the IP address and subnet mask for the virtual system, otherwise you will not be able to communicate (refer to whether the dhcp server is enabled, if enabled, you can choose dhcp to obtain the network address automatically). This is the simplest way to bridge a virtual network card directly to a physical network card, which is similar to the binding of two different addresses to the next network card in linux. In fact, it sets the network card to promiscuous mode, thus achieving the ability to listen for multiple IP. In this mode, the network card inside the virtual machine (such as eth0 under linux) is directly connected to the network where the physical network card is located. It can be imagined that the virtual machine and the host machine are in a peer-to-peer position, equal in the network relationship, and there is no problem of who is behind. It is easy to use this method, as long as you can get more than one address.
Configure Bridge mode with KVM:
First of all, you need to make sure that the network connection mode used on your host host is bridging. My machine uses a bridge called br0. The way to create a bridge is also very simple. Take my system as an example, the network card has an eno16777736, create the file ifcfg-br0 under the directory / etc/sysconfig/network-scripts/, and then modify the file ifcfg-eno16777736 to:
BOOTPROTO=noneDEVICE=eno16777736HWADDR=00:0c:29:09:0d:3dNM_CONTROLLED=noONBOOT=yesBRIDGE=br0
Modify the file ifcfg-br0 as follows:
BOOTPROTO=staticDEVICE=br0TYPE=BridgeNM_CONTROLLED=noIPADDR=192.168.7.183NETMASK=255.255.255.0GATEWAY=192.168.7.254
Of course, the IP address should be set to its own network segment, which is set to static here. If there is a dhcp server (home router), it can also be set to dynamic, and then restart the network. If the restart is not successful, try to take effect. If it does not, restart the system and it will take effect naturally.
Then it is time to configure the bridge network for the guest virtual machine:
Just add the interface tag under device in the XML configuration file of the virtual machine, as follows:
Of course, you can define the network first, and then name it br0.xml in the XML file added to the virtual machine. Some detailed configuration parameters of the network can be written in this file, which is roughly as follows:
Br0 fb48b969-b9f4-e859-d957-50aedd850fb4
Then use libvirt to define and open the network. Of course, there must be no less interface tags in the configuration file. Just use the above, and the name is exactly the same:
Virsh net-define br0.xml
Virsh net-start br0
The client can then be started to check the network connection.
2.NAT (Network address Translation Mode)
Using NAT mode is to let the virtual system access the public network through the network where the host machine is located with the help of NAT (Network address Translation) function. In other words, NAT mode can be used to access the Internet in a virtual system. Obviously, this approach is appropriate if you have only one public network address.
KVM virtual machine surfing the Internet by Nat:
Virsh net-list
Looking at the currently active network, you can see a default network, which is a default Nat network.
Virsh net-dumpxml default
You can view the detailed configuration of the network as follows:
Default 75dbebde-fc15-4350-8a06-f1432f9e6d30
You can see that the network is built on a bridge virbr0 that is automatically generated when libvirt is installed and started. Then add the label interface to the client's XML configuration file as follows:
The client can surf the Internet in nat mode, and it is verified that the client can obtain an ip address between 2 and 254.
We can edit and modify the configuration of default network directly:
Virsh net-edit default
You can also kill the default network directly and redefine it:
Virsh net-undefine default
Recreate a default.xml file and customize its contents. You can specify a mac address corresponding to an ip and an ip segment. For example, name corresponds to the name of the client.
Default dc69ff61-6445-4376-b940-8714a3922bf7
Then use the command:
Virsh net-define default.xml
Virsh net-start default
Enable a client to check that the network is available.
Thank you for reading this article carefully. I hope the article "how to configure the network of KVM virtual machines using Bridge and Nat" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.