Rate This Document
Findability
Accuracy
Completeness
Readability

Configuring the Network (Bridge Mode)

It is assumed that the KVM VMs have been installed. To access the TomEE service on a KVM VM from another PC in the LAN, you can connect the KVM VM (guest) to the host machine in bridge mode, and enable the VM to obtain an independent IP address on the LAN.

Configuring Bridges

  1. Check the network.
    ip a

    Find a network port whose NIC status is UP and IP address has been configured based on the site requirements. The test objective is to bridge the KVM to the network segment (192.168.100.XXX, subnet mask: 255.255.255.0) where enp5s0 is located.

  2. Check the bridge and ensure that the br0 bridge does not exist.
    1
    brctl show
    
  3. Stop the NetworkManager service to prevent the modified configuration from taking effect unexpectedly.
    1
    systemctl stop NetworkManager
    
  4. Create the br0 bridge.
    1. Open the ifcfg-br0 file.
      1
      vi /etc/sysconfig/network-scripts/ifcfg-br0
      
    2. Add the following content. Save the file and exit.
      DEVICE=br0
      ONBOOT=yes
      TYPE=Bridge
      NM_CONTROLLED=yes
      BOOTPROTO=static
      IPADDR=192.168.100.2
      NETMASK=255.255.255.0
      GATEWAY=192.168.100.1
      STP=on
      DELAY=0.0

      If you perform the following operations to create a bridge, the bridge becomes invalid after the host machine is restarted.

      brctl addbr br0
      brctl addif br0 enp5s0
      ifconfig br0 192.168.100.2/24
      service network restart
      brctl show
      ip a
  5. Modify the ifcfg-enp5s0 file to connect the enp5s0 NIC to the br0 bridge.
    1. Back up the ifcfg-enp5s0 file.
      mv /etc/sysconfig/network-scripts/ifcfg-enp5s0 /home/
    2. Open the ifcfg-enp5s0 file.
      1
      vi /etc/sysconfig/network-scripts/ifcfg-enp5s0
      
    3. Add the following content. Save the file and exit.
      HWADDR=24:a5:2c:17:bb:39
      DEVICE=enp5s0
      TYPE=Ethernet
      ONBOOT=yes
      NM_CONTROLLED=yes
      BRIDGE=br0

      Check the HWADDR value of enp5s0. In the command output, the MAC address following ether is the HWADDR value.

      ip a
  6. Make the ifcfg-br0 and ifcfg-enp5s0 files take effect.
    • CentOS:
      1
      systemctl restart network
      
    • openEuler:
      1
      systemctl restart NetworkManager
      

      If the configuration does not take effect after the network service is restarted, check whether the preceding operations are correctly performed. Alternatively, restart the host and then restart the network service.

  7. Check the network.
    1
    ip a
    

    Ensure that the configurations of br0 and enp5s0 have taken effect.

  8. Check the bridge.
    1
    brctl show
    

    If enp5s0 is displayed under interfaces of br0, the network bridge is configured successfully.

Configuring the VM

  1. Modify the VM configuration.
    1. Open the VM configuration file.
      1
      2
      3
      vi /etc/libvirt/qemu/vm1.xml
      Or
      virsh edit vm1
      
    2. Find the <interface> tag under <devices> and change br1 to br0. Save the file and exit.

      If the <interface> tag does not exist, add the following content under the <devices> tag:

      <interface type='bridge'>
            <mac address='52:54:00:7a:95:48'/>
            <source bridge='br1'/>
            <model type='virtio'/>
            <address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x0'/>
      </interface>
      • <interface type='bridge'> indicates that the VM uses the bridge mode.
      • The MAC address in <mac address='52:54:00:7a:95:48'/> is automatically generated after the VM is installed and is used as the MAC address of the VM NIC eth0. Generally, you do not need to change the MAC address. If you need to change the MAC address, ensure that it is different from the MAC address of the br0 bridge.
      • <source bridge='br0'/> indicates that the br0 bridge on the host will be connected.
  2. Make the VM configuration take effect.
    1
    systemctl restart libvirtd
    
  3. Stop the VM.
    1
    virsh list --all
    
    1
    virsh shutdown vm1
    
    1
    virsh list --all
    

    Verify that the state of the VM is shut off.

  4. Start the VM.
    1
    virsh start vm1
    
    1
    virsh list --all
    

  5. Check the bridge.
    1
    brctl show
    

    If vnet0 is displayed under interfaces of br0, vm1 is successfully connected to the bridge. (vnet0 exists only when the vm1.xml configuration takes effect and vm1 is successfully started.)

  6. Log in to the VM.
    virsh list --all
    virsh console vm1 --force
  7. Configure the NIC.
    1. Check the network.
      ip a
    2. Modify the NIC configuration.
      • CentOS:
        1. Open the ifcfg-eth0 file.
          1
          vi /etc/sysconfig/network-scripts/ifcfg-eth0
          
        2. Modify the following information. Generally, you only need to modify the information in bold. Set IPADDR to an unused IP address that is in the same network segment as the host machine. Save the file and exit.
          TYPE=Ethernet
          PROXY_METHOD=none
          BROWSER_ONLY=no
          BOOTPROTO=static
          DEFROUTE=yes
          IPV4_FAILURE_FATAL=no
          IPV6INIT=yes
          IPV6_AUTOCONF=yes
          IPV6_DEFROUTE=yes
          IPV6_FAILURE_FATAL=no
          IPV6_ADDR_GEN_MODE=stable-privacy
          NAME=eth0
          UUID=aca69508-f4c7-4ff2-9cc5-668ac45e429e
          DEVICE=eth0
          ONBOOT=yes
          IPADDR=192.168.100.3
          NETMASK=255.255.255.0
          GATEWAY=192.168.100.1
      • openEuler:
        1. Open the ifcfg-enp1s0 file.
          1
          vi /etc/sysconfig/network-scripts/ifcfg-enp1s0
          
        2. Modify the following information. Generally, you only need to modify the information in bold. Set IPADDR to an unused IP address that is in the same network segment as the host machine. Save the file and exit.
          TYPE=Ethernet
          PROXY_METHOD=none
          BROWSER_ONLY=no
          BOOTPROTO=static
          DEFROUTE=yes
          IPV4_FAILURE_FATAL=no
          IPV6INIT=yes
          IPV6_AUTOCONF=yes
          IPV6_DEFROUTE=yes
          IPV6_FAILURE_FATAL=no
          IPV6_ADDR_GEN_MODE=stable-privacy
          NAME=enp1s0
          UUID=dedf1652-5eff-3fb4-be23-c658b834774f
          DEVICE=enp1s0
          ONBOOT=yes
          AUTOCONNECT_PRIORITY=-999
          IPADDR=192.168.100.13
          NETMASK=255.255.255.0
          GATEWAY=192.168.100.1
  8. Make the NIC take effect.
    • CentOS:
      systemctl restart network
      ip a

    • openEuler:
      systemctl restart NetworkManager
      ifdown enp1s0
      ifup enp1s0
      ip a

Verifying the Network

  1. Ping the VM and host machine from each other.
  2. Ping the VM and other hosts in the LAN from each other.
  3. Ping the host machine and other hosts in the LAN from each other.
    • If the ping fails, capture packets of bridge br0 on the host and analyze the problem.
      yum -y install tcpdump
      tcpdump -i br0
    • If all of the host machines, VMs, and other hosts are successfully pinged, the bridge configuration is complete.
    • If the VM can communicate with only the host machine but not other hosts in the LAN, you may need to disable the network filter on the host machine.
    1. Disable the network filter.
      1. Open the sysctl.conf file.
        1
        vim /etc/sysctl.conf
        
      2. Add the following content to the file. Save the file and exit.
        net.bridge.bridge-nf-call-ip6tables = 0
        net.bridge.bridge-nf-call-iptables = 0
        net.bridge.bridge-nf-call-arptables = 0
    2. Reload the kernel parameters for the configuration to take effect.
      1
      sysctl -p