How to Install and use Open vSwitch with KVM on CentOS 7 / RHEL 7

Open vSwitch is a free and open source multi-layer software switch, which is used to manage the traffic between virtual machines and physical or logical networks.  It provides the features like traffic isolation in OpenStack tenants using the overlay techniques likes GRE, VXLAN and 802.1Q VLANs.

Using open vSwitch packet forwarding engine in kernel space or user space can be implemented and Link aggregation can also be accomplished through LACP.

In this article we will discuss how to install latest version of Open vSwitch 2.9.2 on CentOS 7 and RHEL 7 Server. Apart from this we will see how open vSwitch can be used in KVM virtual machines for their networking.


Read More On : How to Install and Configure KVM on Ubuntu 18.04 LTS Server

I am assuming you have already have either CentOS 7 or RHEL 7 server configured with KVM. Open vswitch (OVS) 2.0 is available in the CentOS 7 & RHEL 7 default yum repositories, but if you install latest version of open vSwitch refer the below steps.

Step 1) Install the required packages using yum command

Login to your CentOS 7 or RHEL 7 server and run the beneath yum command,

[[email protected] ~]# yum install wget openssl-devel  python-sphinx gcc make python-devel openssl-devel kernel-devel graphviz kernel-debug-devel autoconf automake rpm-build redhat-rpm-config libtool python-twisted-core python-zope-interface PyQt4 desktop-file-utils libcap-ng-devel groff checkpolicy selinux-policy-devel -y

Step 2) Create ovs user and download Open vSwitch 2.9

Create a user with name ovs using below command

[[email protected] ~]# useradd ovs
[[email protected] ~]# su - ovs
[[email protected] ~]$

Download OVS 2.9 tar file and build the openvswitch rpm using beneath commands,

[email protected] ~]$ mkdir -p ~/rpmbuild/SOURCES
[[email protected] ~]$ wget
[[email protected] ~]$ cp openvswitch-2.9.2.tar.gz ~/rpmbuild/SOURCES/
[[email protected] ~]$ tar xfz openvswitch-2.9.2.tar.gz
[[email protected] ~]$ rpmbuild -bb --nocheck openvswitch-2.9.2/rhel/openvswitch-fedora.spec
[[email protected] ~]$ exit
[[email protected] ~]#

Now install Open vSwitch rpm using below yum command,

[[email protected] ~]# yum localinstall /home/ovs/rpmbuild/RPMS/x86_64/openvswitch-2.9.2-1.el7.x86_64.rpm -y

Step 3) Start and enable Open vSwitch Service

Use below systemctl commands to start and enable open vSwitch service

[[email protected] ~]# systemctl start openvswitch.service
[[email protected] ~]# systemctl enable openvswitch.service
Created symlink from /etc/systemd/system/ to /usr/lib/systemd/system/openvswitch.service.
[[email protected] ~]# systemctl status openvswitch.service
● openvswitch.service - Open vSwitch
Loaded: loaded (/usr/lib/systemd/system/openvswitch.service; enabled; vendor preset: disabled)
Active: active (exited) since Sun 2018-08-05 10:16:12 EDT; 17s ago
Main PID: 73958 (code=exited, status=0/SUCCESS)
Aug 05 10:16:12 compute02 systemd[1]: Starting Open vSwitch...
Aug 05 10:16:12 compute02 systemd[1]: Started Open vSwitch.
[[email protected] ~]#

Use below command to check the OVS version

[[email protected] ~]# ovs-vsctl -V
ovs-vsctl (Open vSwitch) 2.9.2
DB Schema 7.15.1
[[email protected] ~]#

Step:4 Create the OVS bridge and add interfaces to it.

Use the below command to create ovs bridge,

[[email protected] ~]# ovs-vsctl add-br ovs-br0

Now flush or remove IP from the interface, in my case IP as was assigned to eno16777736

[[email protected] ~]# ip addr flush dev eno16777736

Now assign this IP address to ovs bridge(ovs-br0)

[[email protected] ~]# ip addr add dev ovs-br0

Add interface as port in ovs-br0 using below command,

[[email protected] ~]# ovs-vsctl add-port ovs-br0 eno16777736

Now bring up the bridge using below ‘ip link’ command,

[[email protected] ~]# ip link set dev ovs-br0 up

Note : Above changes are not persistent, so make these changes persistent across the reboot, we have to create ovs bridge file, steps are shown below

[[email protected] ~]# cd /etc/sysconfig/network-scripts/
[[email protected] network-scripts]# cp ifcfg-eno16777736 ifcfg-ovs-br0
[[email protected] network-scripts]#
[[email protected] network-scripts]# vi ifcfg-eno16777736

Save and exit the file

[[email protected] network-scripts]# vi ifcfg-ovs-br0

Save & exit the file

Restart the network service using below command,

[[email protected] network-scripts]# systemctl restart network

Now Verify ovs bridge and its ports using “ovs-vsctl” command

[[email protected] ~]# ovs-vsctl show
    Bridge "ovs-br0"
        Port "ovs-br0"
            Interface "ovs-br0"
                type: internal
        Port "eno16777736"
            Interface "eno16777736"
    ovs_version: "2.9.2"
[[email protected] ~]#

Step:5 ) Create and define virsh ovs network

Create ovs network file with the following contents ,

[[email protected] ~]# vi /tmp/ovs-network.xml
<forward mode='bridge'/>
<bridge name='ovs-br0'/>
<virtualport type='openvswitch'/>

Now define the ovs-network using below virsh command,

[[email protected] ~]# virsh net-define /tmp/ovs-network.xml
Network ovs-network defined from /tmp/ovs-network.xml
[[email protected] ~]# virsh net-start ovs-network
Network ovs-network started
[[email protected] ~]# virsh net-autostart ovs-network
Network ovs-network marked as autostarted
[[email protected] ~]#

Now verify the virsh network using beneath command,

[[email protected] ~]# virsh net-list
 Name                 State      Autostart     Persistent
 default              active     yes           yes
 ovs-network          active     yes           yes
[[email protected] ~]#

Step:6) Create Virtual machines and attach ovs-network

Let’s create two test VMs using below virt-install command, specify the network for these VMs as ovs-network,

[[email protected] ~]# virt-install  -n testvm1  --description "Test VM1 for OVS "  --os-type=Linux  --os-variant=rhel7  --ram=1096  --vcpus=1  --disk path=/var/lib/libvirt/images/testvm1.img,bus=virtio,size=10  --network network:ovs-network --graphics none  --location /root/CentOS-7-x86_64-DVD-1511.iso --extra-args console=ttyS0

Similarly Create a second test vm with name “testvm2”

[[email protected] ~]# virt-install  -n testvm2  --description "Test VM2 for OVS "  --os-type=Linux  --os-variant=rhel7  --ram=1096  --vcpus=1  --disk path=/var/lib/libvirt/images/testvm2.img,bus=virtio,size=10  --network network:ovs-network --graphics none  --location /root/CentOS-7-x86_64-DVD-1511.iso --extra-args console=ttyS0

Once the VMs are created then their interfaces should be added in ovs bridge (ov-br0) automatically and we can verify this from ovs-vsctl command,

[[email protected] ~]# ovs-vsctl show
    Bridge "ovs-br0"
        Port "ovs-br0"
            Interface "ovs-br0"
                type: internal
        Port "eno16777736"
            Interface "eno16777736"
        Port "vnet0"
            Interface "vnet0"
        Port "vnet1"
            Interface "vnet1"
    ovs_version: "2.9.2"
[[email protected] ~]# ovs-vsctl list-ports ovs-br0
[[email protected] ~]#

In the above command vnet0 & vnet1 are VMs tap interface. When we shutdown these VMS then these ports will be removed from OVS Bridge (ovs-br0) automatically. Log files for ovs (openvswitch) are kept under the folder “/var/log/openvswitch“.

This conclude this article, I hope you got an idea how to install and use Open vSwitch 2.9 with KVM on CentOS 7 and RHEL 7 Servers. If you like article, please do share your feedback and comments. .large-mobile-banner-2-multi-135{border:none !important;display:block !important;float:none;line-height:0px;margin-bottom:15px !important;margin-left:0px !important;margin-right:0px !important;margin-top:15px !important;max-width:100% !important;min-height:250px;min-width:250px;padding:0;text-align:center !important;}

Posted by WordPress Guru