Open vSwitch (OVS) is a programmable virtual switch used by OpenStack, OVN and many large virtualization platforms. On a single KVM host it gives you per-port VLAN tagging, mirroring, QoS and flow-level control beyond a plain Linux bridge. This guide shows how to use Open vSwitch with KVM.
Before you start
- A KVM host with libvirt; see install KVM on Ubuntu.
- Console access: moving the host IP onto OVS can drop SSH.
- Background: bridges, NAT and VLANs.
Install Open vSwitch
sudo apt install -y openvswitch-switchRHEL family: install openvswitch from the appropriate repository (for example the NFV or OpenStack SIG repos) and enable openvswitch.
Create an OVS bridge
sudo ovs-vsctl add-br ovsbr0sudo ovs-vsctl add-port ovsbr0 eno1Then move the host IP from eno1 to ovsbr0. With Netplan you can declare it persistently:
network:
version: 2
ethernets:
eno1: {}
bridges:
ovsbr0:
interfaces: [eno1]
openvswitch: {}
addresses: [203.0.113.10/24]
routes:
- to: default
via: 203.0.113.1Apply from the console with sudo netplan try.
Connect libvirt VMs
In the VM XML (virsh edit vmname):
<interface type='bridge'>
<source bridge='ovsbr0'/>
<virtualport type='openvswitch'/>
<model type='virtio'/>
</interface>With virt-install: --network bridge=ovsbr0,virtualport_type=openvswitch,model=virtio.
Tag VLANs per VM
Add a VLAN tag in the interface definition:
<vlan><tag id='100'/></vlan>The uplink switch port must be a trunk carrying VLAN 100. You can also define a libvirt network with portgroups for each VLAN so VMs simply pick a portgroup.
Inspect and debug
| Task | Command |
|---|---|
| Show bridges and ports | ovs-vsctl show |
| Port statistics | ovs-ofctl dump-ports ovsbr0 |
| Flow table | ovs-ofctl dump-flows ovsbr0 |
| Learned MACs | ovs-appctl fdb/show ovsbr0 |
OVS vs Linux bridge
- Linux bridge: simpler, built in, enough for most single-host setups (VLAN-aware bridges cover basic tagging).
- OVS: use for SDN, OVN, overlays (VXLAN/Geneve), port mirroring, fine-grained QoS and OpenFlow rules.
Troubleshooting
- Host lost network: the IP is still on
eno1or the bridge has no IP; fix from console. - VM gets no traffic on VLAN: tag missing or the switch port is not a trunk.
- libvirt error about virtualport: OVS service not running;
systemctl status openvswitch-switch.
Frequently asked questions
Does OVS slow down traffic?
Its kernel datapath performs well; DPDK-accelerated OVS exists for very high packet rates.
Do VPS panels use OVS?
Some do, many use Linux bridges. It depends on the panel and configuration.
Can I mix OVS and Linux bridges?
Yes, on different interfaces, but keep the design simple.
