How to install and configure OVS virtual switch on CentOS 7 or RED HAT 7 host with KVM

We will be configuring open vSwitch OVS as bridge with local physical interface p4p1 connected to bridge xxx222. This bridge will be located on OVS we will also created 2 vlans 8 and 4 on the same OVS switch.

Open vSwitch installation

Steps below will install latest 2.4.0 openswitch on your CentOS or RED HAT 7 system

#yum -y install wget openssl-devel gcc make python-devel openssl-devel kernel-devel kernel-debug-devel autoconf automake rpm-build redhat-rpm-config libtool
#adduser ovs
#su - ovs
#mkdir -p ~/rpmbuild/SOURCES
#wget http://openvswitch.org/releases/openvswitch-2.4.0.tar.gz
#cp openvswitch-2.4.0.tar.gz ~/rpmbuild/SOURCES/
#tar xfz openvswitch-2.4.0.tar.gz
#sed 's/openvswitch-kmod, //g' openvswitch-2.3.1/rhel/openvswitch.spec > openvswitch-2.3.1/rhel/openvswitch_no_kmod.spec
#rpmbuild -bb --nocheck ~/openvswitch-2.4.0/rhel/openvswitch_no_kmod.spec
#exit
#yum localinstall /home/ovs/rpmbuild/RPMS/x86_64/openvswitch-2.4.0-1.x86_64.rpm
#ovs-vsctl -V
#/etc/init.d/openvswitch start
#chkconfig openvswitch on
 

Configure physical interface to be Port on OVS Bridge xxx222

# vi /etc/sysconfig/ ifcfg-xxx222
DEVICE="xxx222"
BOOTPROTO="none"
IPADDR=192.168.0.101
PREFIX=24
GATEWAY=192.168.0.1
DNS1=8.8.8.8
ONBOOT="yes"
TYPE="OVSBridge"
DEVICETYPE="ovs"
 
# cat /etc/sysconfig/network-scripts/ifcfg-p4p1
TYPE=Ethernet
DEVICE="p4p1"
NAME=p4p1
ONBOOT=yes
OVS_BRIDGE=xxx222
TYPE="OVSPort"
DEVICETYPE="ovs"
 

Edit virtual machine xml file

Replace below on in your vm xml file.

from

<interface type='network'>

<mac address='52:54:00:71:b1:b6'/>

<source network='default'/>

<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>

</interface>

to

<interface type='bridge'>

<mac address='52:54:00:71:b1:b6'/>

<source bridge='xxx222'/>

<virtualport type='openvswitch'/>

<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>

</interface>

 

Assign vlans to your vnet interfaces

After starting vms you will be able to see vnet interfaces by running

#ip a
#ovs-vsctl set port vnet0 tag=8
#ovs-vsctl set port vnet1 tag=4

In the above example we have 2 virtual systems with virtual interfaces vnet0 and vnet1. They now be tagged with vlans 8 and 4 respectively

 

Setup network with virsh

1) Put the following xml into a file (e.g. /tmp/ovsnet.xml):

<network>
<name>xxx222</name>
<forward mode='bridge'/>
<bridge name='xxx222'/>
<virtualport type='openvswitch'/>
</network>

2) define and start the network:

# virsh net-define /tmp/ovsnet.xml
# virsh net-start xxx222
# virsh net-autostart xxx222

3) virsh net-list --all

 

Using fake bridges to create vlans

In some cases you may want to use fake bridges to vlan your virtual network. You will need to create parent bridges with vlan number of your vlan. All traffic from that bridge will be tagged with correct vlan

#ovs-vsctl add-br vlan7 xxx222 7
<interface type='bridge'>
<mac address='xx:xx:xx:xx:xx:xx'/>
<virtualport type='openvswitch' />
<source bridge='vlan7'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> </interface>