2021-11-12 ④ enterprise virtualization, KVM management, KVM network configuration, bridging, nait mode, setting input method language, Part 4

KVM network configuration

Bridged Networking

nat network

Isolated network (host mode only)

You can determine whether there are two interfaces on the same line by checking whether the mac addresses are consistent

[root@youngfit ~]# brctl show
bridge name	bridge id		                STP enabled	 interfaces
virbr0		        8000.5254003c2ba7	yes		         virbr0-nic
							                             vnet2
							                             vnet3
 Note: here vnet Network card refers to the network card device being used by each started virtual machine. Each virtual machine uses different network cards

Delete the vnet network card from the switch (equivalent to unplugging the network cable):

[root@youngfit ~]# brctl delif  virbr0 vnet0

When you come to the virtual machine of vm9, ping Baidu is not available, nor is ping the host

[root@vm9 ~]# ping www.baidu.com
[root@vm9 ~]# ping 192.168.153.132

Add vnet network card to switch:

[root@youngfit ~]# brctl addif  virbr0 vnet0

Go to the virtual machine of vm9 and return to normal

[root@vm9 ~]# ping www.baidu.com
[root@vm9 ~]# ping 192.168.153.132

Creating an isolated network in profile mode

Create an isolated network (host only) in the configuration file mode: I've never used the host only mode. We don't operate anymore. If you are interested, you can operate it

[root@localhost networks]# pwd
/etc/libvirt/qemu/networks
[root@youngfit networks]# cp default.xml isolated200.xml
[root@youngfit networks]# vim isolated200.xml
<network>
  <name>isolated200</name>
  <uuid>6341d3a6-7330-4e45-a8fe-164a6a68929a</uuid>
  <bridge name='virbr2' stp='on' delay='0'/>
  <mac address='52:54:00:6b:39:0c'/>
  <domain name='isolate1'/>
  <ip address='192.168.123.1' netmask='255.255.255.0'>
    <dhcp>
      <range start='192.168.123.128' end='192.168.123.254'/>
    </dhcp>
  </ip>
</network>  

Restart it

[root@youngfit networks]# systemctl restart libvirtd

Add a network card and check whether it takes effect


View all networks:

# virsh net-list

Start the network:

# virsh net-start isolated200

Startup and self startup:

# virsh net-autostart  isolated200 

Bridged Networking

Profile mode configuration bridging: on the host

[root@youngfit test]# ip a   #First find out which network card device the host uses. Mine is ens33
[root@youngfit test]# cd /etc/sysconfig/network-scripts/


1. Modify the configuration file

[root@youngfit network-scripts]# vim ifcfg-br0  #New without this file
[root@youngfit network-scripts]# cat ifcfg-br0
TYPE=Bridge
NAME=br0
DEVICE=br0
ONBOOT="yes"
BOOTPROTO=static
IPADDR=196.196.196.129     #Host ip address
GATEWAY=196.196.196.2    #Host gateway
NETMASK=255.255.255.0
DNS1=114.144.144.144
DNS2=8.8.8.8

Then see the network card being used by the host and modify the configuration file

[root@youngfit network-scripts]# cp ifcfg-ens33 ifcfg-ens33.bak
[root@youngfit network-scripts]# vim ifcfg-ens33
[root@youngfit network-scripts]# cat ifcfg-ens33
TYPE="Ethernet"
NAME="ens33"		#Define network card device name
DEVICE="ens33"	#Network card device in use by host
ONBOOT="yes"
BRIDGE=br0			#It corresponds to the device in the ifcfg-br0 file
  

2. Restart libvirtd service

[root@youngfit network-scripts]# systemctl restart libvirtd

3. Restart the network service

[root@youngfit network-scripts]# systemctl restart network

Then check to see if any new devices are generated





After adding, start

As you can see, we added the network card device first

Test network availability

Host test
[root@youngfit network-scripts]# ping www.baidu.com / / wait a moment

If ping fails to connect to the Internet

#If Ping fails, modify DNS to the gateway address, delete the old network card of kvm virtual machine, add the latest network card and try again
method; The bridging mode host is different from the virtual machine ping
First modify the dns of the host to its own ip network

vim /etc/resolv.conf


kvm virtual machine delete old network card

Host test

Guest OS test of kvm virtual machine

Remove operation

Shut down the kvm virtual machine first



To delete a bridge network card:
1. Delete br0's profile
2. Modify the configuration file of the normal network card
3. Restart the system

[root@youngfit network-scripts]# mv ifcfg-br0 ifcfg-br0.bak2
[root@youngfit network-scripts]# mv ifcfg-en
 ifcfg-enp0s25.bak2
[root@youngfit network-scripts]# mv ifcfg-ens33.bak ifcfg-ifcfg-ens33
[root@youngfit network-scripts]# systemctl restart libvirtd
[root@youngfit network-scripts]# systemctl restart network
[root@youngfit network-scripts]# ping www.baidu.com
PING www.a.shifen.com (39.156.66.14) 56(84) bytes of data.
64 bytes from 39.156.66.14 (39.156.66.14): icmp_seq=1 ttl=52 time=13.3 ms

nat network

Create nat network by configuration file:

[root@youngfit networks]# cd /etc/libvirt/qemu/networks
[root@youngfit networks]# cp default.xml nat1.xml
[root@youngfit networks]# vim nat1.xml


Restart service:

# systemctl  restart libvirtd

Add this device test in a virtual machine (such as vm9)


Test network availability

[root@localhost ~]# ping www.baidu.com


Stop the virtual network before deleting it

Centos setup IME






Tags: Linux CentOS network

Posted on Fri, 12 Nov 2021 08:35:27 -0500 by davidz