Openvswitch is the software used on both physical and virtual environments to implement L2 switching.
Installation of openvswitch:
dnf install -y virt-install libvirt openvswitch
Enabling the openvswitch service and daemon:
systemctl enable openvswitch
systemctl start openvswitch
systemctl status openvswitch
Adding a network interface to ovs bridge ovsbr0:
ovs-vsctl add-br ovsbr0
ovs-vsctl add-port ovsbr0 enp9s0
ifconfig ovsbr0 192.168.15.15/20
dhclient ovsbr0
ovs-vsctl show
Modify the enp9s0 network configuration file:
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=none
DEFROUTE=yes
NAME=enp9s0
DEVICE=enp9s0
DEVICETYPE="ovs"
TYPE="OVSPort"
OVS_BRIDGE="ovsbr0"
Creating a bridge configuration file to keep changes persistent across reboots:
DEVICE="ovsbr0"
DEVICETYPE="ovs"
TYPE="OVSBridge"
ONBOOT="yes"
MACADDR="00:1c:23:01:fb:dc"
OVS_EXTRA="set bridge $DEVICE other-config:hwaddr=$MACADDR"
OVSBOOTPROTO="dhcp"
OVSDHCPINTERFACES="enp9s0"
After kvm guest is booted up we can see that ip is the same range as the bridge br0.
Related Articles
How We Set Up Our KVM Hypervisor: From Bare Metal to Production-Ready VM Host
Detailed walkthrough of building a dedicated KVM/libvirt hypervisor with XFS tuning, hugepages, 10GbE tuning, and automation.
Installing eve-ng on ubuntu 24.04 LTS
Step-by-step guide to installing EVE-NG on Ubuntu 24.04 LTS bare metal server for running network labs.
Setting default gateway from virsh-net command line
Generally when a network is configured from virsh-define for a particular range say 192.168.4.0 it gateway will be automatically assigned to 192.168.4.1.