This will allow you to use Open vSwitch with Libvirt to put your VMs on the same network as the host and not use the default NAT based bridge.
dnf install -y virt-install libvirt openvswitch
systemctl stop NetworkManager.service
systemctl disable NetworkManager.service
systemctl enable network.service
systemctl start network.service
systemctl enable openvswitch.service
systemctl start openvswitch.service
Please note /etc/sysconfig/network-scripts/ifcfg-enp2s0
file and the NAME and DEVICE entries inside this file may be named differently. Please adjust the steps below accordingly. This guide assumes you are using DHCP on this address and follows the steps on this video to cloning the MAC address from physical NIC. The video is talking about Openstack, but the same principles apply.
cp /etc/sysconfig/network-scripts/ifcfg-enp2s0 /etc/sysconfig/network-scripts/ifcfg-enp2s0.orig
touch /etc/sysconfig/network-scripts/ifcfg-ovsbr0
Edit /etc/sysconfig/network-scripts/ifcfg-enp2s0
and add the following. Please note your NAME and DEVICE entries may be named differently. Save your MAC address You need to make sure your MAC address is set correctly in /etc/sysconfig/network-scripts/ifcfg-ovsbr0
as well.
DEVICE="enp2s0"
NAME="enp2s0"
BOOTPROTO="none"
ONBOOT="yes"
DEVICETYPE="ovs"
TYPE="OVSPort"
OVS_BRIDGE="ovsbr0"
Edit /etc/sysconfig/network-scripts/ifcfg-ovsbr0
to reflect the below. Please note that MACADDR needs to be set to your physical MAC on your NIC and OVSDHCPINTERFACES needs to match your NAME and DEVICE entries in the /etc/sysconfig/network-scripts/ifcfg-enp2s0
file.
DEVICE="ovsbr0"
DEVICETYPE="ovs"
TYPE="OVSBridge"
ONBOOT="yes"
MACADDR="D8:50:E6:BD:83:E6"
OVS_EXTRA="set bridge $DEVICE other-config:hwaddr=$MACADDR"
OVSBOOTPROTO="dhcp"
OVSDHCPINTERFACES="enp2s0"
Restart networking with service network restart
. If ovsbr0 doesn't pull an IP from DHCP, reboot. You can verify that it pulls an IP with ip addr show ovsbr0
.
Then verify with ovs-vsctl show
that Open vSwitch shows the bridge.
0b349007-da10-4c09-a95f-ffc4518d1193
Bridge "ovsbr0"
Port "enp2s0"
Interface "enp2s0"
Port "ovsbr0"
Interface "ovsbr0"
type: internal
ovs_version: "2.3.2"
Generate a UUID with uuidgen
and create an XML file called ovsbr0.xml and replace the UUID below with the generated UUID from uuidgen
.
<network>
<name>ovsbr0</name>
<uuid>2a0cd43b-ce1f-4451-a3c8-8f8786fe77c8</uuid>
<forward mode='bridge'/>
<bridge name='ovsbr0'/>
<virtualport type='openvswitch'/>
</network>
Use virsh net-define ovsbr0.xml
to define the new network called ovsbr0
from the ovsbr0.xml
file.
virsh net-define ovsbr0.xml
Once that is done you will want start the new ovsbr0 network and have it autostart on boot.
virsh net-start ovsbr0
virsh net-autostart ovsbr0