Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Network configuration of KVM virtual machine

2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

There are two modes of network configuration for kvm virtual machines: bridging mode and NAT mode.

The differences between the two modes are as follows:

1) NAT mode: it is also the user mode. Packets are transmitted through the interface of the host by NAT, and the public network can be accessed, but the virtual machine network cannot be accessed from the outside, so it is generally not used.

2) Bridge: bridge mode, which allows a virtual machine to own a network like an independent host. External machines can directly access the inside of the virtual machine, but it needs network card support, which is generally supported by wired network cards.

I. NAT mode configuration

The configuration of nat mode is relatively simple. You only need to change the network card configuration file of the virtual machine after starting the virtual machine, and change the default "no" of the "ONBOOT" configuration item to "yes" to realize ping access to the public network. (it is realized with the help of the firewall rules and IPtables rules of the KVM server. Turning off the firewall of the KVM server will not affect the virtual machine ping external network, but the default configuration of its iptables must exist, otherwise. The virtual machine cannot ping the extranet).

II. Bridge mode configuration

There are two ways to configure Bridge. The first one is cumbersome and is not recommended. It is written in my previous blog post: Centos7 deployment KVM Virtualization platform details, which can be used for reference. Here is the second method, a relatively simple one.

[root@kvm ~] # systemctl stop NetworkManager # stop this service [root@kvm ~] # virsh iface-bridge ens33 br0 # when executing this command, do not mind if you prompt the following information Because it already exists, using additional device br0 to generate bridging ens33 failed to launch bridging interface br0 [root@kvm ~] # ls / etc/sysconfig/network-scripts/ | grep br0 ifcfg-br0 # confirm that this file is available. [root@kvm ~] # virsh destroy test01 # close the virtual machine domain test01 is deleted [root@kvm ~] # virsh edit test01 # edit the configuration file of the virtual machine Navigate to interface # change this to bridge # Delete the Mac address line # change it to this # Save and exit

Now that the configuration is complete, run the virtual machine and change its network card configuration file. Note: the gateway and kvm host configured in the virtual machine are the same. They are now in the same network segment. The network card configuration file of the virtual machine is as follows:

After saving and exiting, restart the network service, and then the virtual machine and the external network can communicate with each other! Test it yourself!

-this is the end of this article. Thank you for reading-

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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report