iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🌉

Connecting a Virtual Bridge to a KVM Virtual Machine

に公開

This should have been a simple task, but I somehow got really stuck, so here are my notes.

Overview

  • Create a virtual bridge on a host machine where you want to set up KVM virtual machines.
  • Connect the created bridge to the virtual machine so that the host and the virtual machine are on the same network.
  • The verification environment is RockyLinux 9 on the host side and AlmaLinux 10 on the virtual machine side.

Creating a Virtual Bridge

Below, assume enp7s0 is the host's physical NIC, br0 is the virtual bridge to be created, and eth7 is the host interface (to be connected to the bridge).

## Create br0
# nmcli con add type ethernet con-name br0 ifname enp7s0 master br0 stp no
## Set the IP address for br0
# nmcli con modify br0 ipv4.method manual ipv4.addresses 192.168.2.101/24 ipv4.gateway 192.168.2.254 ipv4.dns 192.168.2.254
## Create eth7 and connect it to br0
# nmcli connection add type bridge ifname eth7 master br0
# systemctl restart network

Creating a Virtual Machine

Please adjust settings such as --disk and --cdrom as necessary.

# HOSTNAME=hostname
# CDROM=/path/to/iso
# virt-install \
--name ${HOSTNAME} \
--memory 4096 \
--vcpus 2 \
--disk pool=vm-data,size=32,format=qcow2 \
--os-variant almalinux10 \
--cdrom ${CDROM} \
--graphics vnc,port=5901,listen=0.0.0.0 \
--network bridge=br0 \
--noautoconsole
# virsh list --all
## The created virtual machine should be displayed

Discussion