19 C
Texas

Configuring Open vSwitch on CentOS | RHEL | Fedora

Today we are going to learn that how to configure Open vSwitch on CentOS/RHEL. In our previous lecture you’ve learned that how to install Open vSwitch on CentOS/RHEL. If you missed the previous article simply click the below link to read it first for the installation of Open vSwitch on CentOS/RHEL.

How To Install Open vSwitch on CentOS 8 | RHEL 8

Here we’ll use the os-net-confi script for the configuration of Open vSwtich on CentOS/RHEL. So, follow the below steps to configure the Open vSwitch on your system.

Step 1: Install os-net-config Tool

To configure the Open vSwitch we need os-net-config tool as it will help us to perform configuration steps more easily. It provides the configuration of host networking using YAML or JSON files format.

- Advertisement -

By default, os-net-config use the YAML file that can be located under /etc/os-net-config/config.yaml. You can also customize this by –config-file(-c) CLI option.

Installing os-net-config by using OpenStack Repository

Hit the following command to install the os-net-config tool using OpenStack repository if you’ve already configured it.

sudo yum install os-net-config

Find out more details about the package by typing

[sabi@localhost ~]$ rpm -qi os-net-config
Name : os-net-config
Version : 11.3.1
Release : 1.el8
Architecture: noarch
Install Date: Sat 08 Aug 2020 02:20:02 AM EDT
Group : Unspecified
Size : 3760703
License : ASL 2.0
Signature : RSA/SHA1, Sun 19 Apr 2020 12:34:05 PM EDT, Key ID f9b9fee7764429e6
Source RPM : os-net-config-11.3.1-1.el8.src.rpm
Build Date : Fri 28 Feb 2020 08:55:33 AM EST
Build Host : c1be.rdu2.centos.org
Relocations : (not relocatable)
Packager : CBS [email protected]
Vendor : CentOS
URL : http://pypi.python.org/pypi/os-net-config
Summary : Host network configuration tool
Description :
Host network configuration tool for OpenStack.

Installing os-net-config with the help of Pip

You can also install the os-net-config tool using pip or pip3 as it is distributed as python package.

CentOS 8:
sudo dnf install python3-pip
CentOS 7:
sudo yum install -y epel-release
sudo yum -y install python-pip
sudo pip install os-net-config

Make sure to verify the PATH once the installation finished.

[sabi@localhost ~]$ which os-net-config
/usr/bin/os-net-config

Step 2: Configuring Open vSwitch by using os-net-config

Let’s dive into the configuration of Open vSwitch by using os-net-config tool as we’ve already installed the Open vSwitch and the configuration tool.

Here we’ll see some example to understand that how we can configure.

Single Interface Configuration with Static IP Address

First create a YAML file to save configuration.

sudo nano ovs-interface.yml

And then configure as shown below:

network_config:
- type: interface
 name: eth1
 use_dhcp: false
 use_dhcpv6: false
 addresses:
- ip_netmask: 172.11.101.10/24
routes:
- ip_netmask: 0.0.0.0/0
next_hop: 172.11.101.254
default: true
Result:

It’ll configure the eth1 interface along with the static IP address as 172.11.101/24 and the gateway is 172.11.101.254.

Run the given command to apply the configuration changes.

sudo os-net-config -c ovs-interface.yml

Configure OVS bridge With Single Attached Interface (Port)

First create the file for configuration and then do the changes as given below:

sudo nano ovs-bridge-single-interface.yml

It’ll look like this:

network_config:
- type: ovs_bridge
 name: br-ex 
use_dhcp: false 
use_dhcpv6: false 
addresses:
 - ip_netmask: 172.11.101.10/24
routes:
- ip_netmask: 0.0.0.0/0
next_hop: 172.11.101.254
default: true
members:
-
type: interface
name: eth1

Finally apply the configuration.

os-net-config -c ovs-bridge-single-interface.yml

Configure OVS Bridge on OVS Bond

Follow the below configuration for OVS bridge.

network_config:
- type: 
ovs_bridge 
name: br-ex 
use_dhcp: true 
members: 
- type: ovs_bond 
name: bond1 
members: 
- type: interface
name: em1
- type: interface
name: em2

Apply the changes in a file as done in above step.

Configure Tagged VLAN Interface On Top of OVS Bridge

Here’s the configuration sample.

network_config:
- type: ovs_bridge 
name: br-ctlplane
 use_dhcp: true 
members: 
- type: interface
name: em1
- type: vlan 
vlan_id: 20 
addresses:
- ip_netmask: 192.0.2.1/24

Creating an OVS Bond

You can create OVS bond by doing the changes as given below:

network_config:
- type: ovs_bridge
 name: bond1 
use_dhcp: true
 members: 
- type: interface
name: eno1
- type: interface
name: eno2

Checking OVS Configuration

Once the settings are applied, network config script will be added automatically to /etc/sysconfig/network-scripts/ directory.

ls /etc/sysconfig/network-scripts/

Verify the settings by hitting

ovs-vsctl show

Step 3: Creating KVM Network with OVS

For users who are using Open vSwitch with KVM virutalization, need to define the network that Virtual Machine will use.

Create xml config file.

sudo nano kvm-ovs.xml

Then add the bridge details in the file and save it.

<network>
<name>ovs-bridge </name>
<forward mode='bridge'/>
<bridge name='br-ex'/>
<virtualport type='openvswitch'/>
<network/>

Note:

ovs-bridge: Name of the libvirt network
br-ex: Name of OVS bridge

To define a network from the XML file, without starting it hit

sudo virsh net-define kvm-ovs.xml

If you want to start the inactive network(previously defined) type

sudo virsh net-start ovs-bridge

To start a network when service started, type the following command:

sudo virsh net-autostart ovs-bridge

Verify that autostart flag is turned to yes.

sudo virsh net-list --all

So, this is how you can configure the Open vSwitch on CentOS/RHEL.

Please share this post and join our Telegram Channel.

- Advertisement -
Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

LEAVE A REPLY

Please enter your comment!
Please enter your name here



Latest article