Skip to content

Instantly share code, notes, and snippets.

@jdoss
Created October 31, 2015 23:30
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jdoss/64ecd24b74792efaa794 to your computer and use it in GitHub Desktop.
Save jdoss/64ecd24b74792efaa794 to your computer and use it in GitHub Desktop.
Configure Fedora Server with Open vSwitch and Libvirt

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.

Install Packages

dnf install -y virt-install libvirt openvswitch

Services Prep Work

Disable NetworkManager :(

systemctl stop NetworkManager.service
systemctl disable NetworkManager.service

Enable Classic Networking

systemctl enable network.service
systemctl start network.service

Enable Open vSwitch

 systemctl enable openvswitch.service
 systemctl start openvswitch.service

Configure Bridge

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.

Backup your old config just in case. ;)

cp /etc/sysconfig/network-scripts/ifcfg-enp2s0 /etc/sysconfig/network-scripts/ifcfg-enp2s0.orig
touch /etc/sysconfig/network-scripts/ifcfg-ovsbr0

Edit the /etc/sysconfig/network-scripts/ifcfg-enp2s0 file.

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 file.

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"

Enable Libvirt to use Open vSwtich

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment