SkillPilotAI

Open vSwitch: ovs-vsctl, ovs-ofctl, ovs-appctl, ovs-dpctl (1/3)

Open vSwitch (OVS) is a programmable software switch that connects VMs and containers in KVM, OpenStack and Kubernetes. This part covers ovs-vsctl, the tool that edits the OVS configuration database: bridges, ports, bonds, VLANs, controllers and raw database records.

63.1 The four OVS tools

ToolWorks onCovered in
ovs-vsctlConfig DB (OVSDB): bridge, port, VLANThis video
ovs-ofctlOpenFlow flows, groups, metersPart 2
ovs-appctlThe running daemonPart 3
ovs-dpctlThe kernel datapathPart 3
  • Linux only: macOS is not supported and the Windows port is experimental.

63.2 How it works: ovs-vsctl edits a database

  • ovs-vsctl never touches the switch directly.
  • ovsdb-server stores the config in conf.db.
  • ovs-vswitchd watches the database and builds the real bridges and ports.
  • So think of ovs-vsctl as a database editor; the config persists across restarts.
ovs-vsctl add-port, step by step
  1. 1.Admin runs ovs-vsctl add-port br0 vm1-p tag=10

  2. 2.The request goes to ovsdb-server over db.sock

  3. 3.ovsdb-server writes a new Port row into conf.db

  4. 4.ovs-vswitchd sees the DB change

  5. 5.ovs-vswitchd creates the real port vm1-p in br0

ovs-vsctl = config editor; forwarding is done by vswitchd + kernel

63.3 Bridge commands

  • Running add-br twice fails; --may-exist makes it idempotent.
  • add-br br10 br0 10: a fake bridge that is VLAN 10 of br0.
  • br-exists returns exit 0 for yes and 2 for no.
  • br-set-external-id: your own key=value tag on a bridge.
  • del-br deletes the bridge with all its ports: run it carefully; emer-reset brings the switch to a clean state.
Terminal
ovs-vsctl add-br br0ovs-vsctl add-br br0ovs-vsctl --may-exist add-br br0ovs-vsctl add-br br10 br0 10ovs-vsctl --fake list-brovs-vsctl br-to-vlan br10ovs-vsctl br-to-parent br10ovs-vsctl br-exists br9; echo $?ovs-vsctl br-set-external-id br0 owner labovs-vsctl br-get-external-id br0
Output
$ ovs-vsctl add-br br0ovs-vsctl: cannot create a bridge named br0 because a bridge named br0 already exists$ ovs-vsctl --may-exist add-br br0[exit 0]$ ovs-vsctl add-br br10 br0 10$ ovs-vsctl list-brbr0br10$ ovs-vsctl --fake list-brbr10$ ovs-vsctl br-to-vlan br10; ovs-vsctl br-to-parent br1010br0$ ovs-vsctl br-exists br9; echo $?2$ ovs-vsctl br-get-external-id br0owner=lab
Output
init                 init an empty DBshow                 bridges, ports overviewemer-reset           reset to a clean stateadd-br br0           new bridge--may-exist add-br   skip if it existsadd-br br10 br0 10   VLAN 10 fake bridgedel-br br0           delete bridge + ports--if-exists del-br   no error if missinglist-br              real + fake bridges--real / --fake list-br  only real / fakebr-exists br0        exit 0 yes, 2 nobr-to-vlan br10      VLAN of a fake bridgebr-to-parent br10    parent of a fakebr-set-external-id br key [value]  set/delbr-get-external-id br [key]  all / one

63.4 Port, bond and VLAN

  • tag=10 / tag=20 makes a port an access port in that VLAN.
  • add-bond br0 bond0 b1 b2 lacp=active: one port bond0 with two interfaces.
  • list-ports shows bond0; list-ifaces splits it into b1 and b2.
  • Lab result: VM1 -> VM2 (both VLAN 10) 0% loss; VM1 -> VM3 (VLAN 20) 100% loss.
  • add-bond-iface / del-bond-iface add or remove a member of an existing bond.
Port tag: VLAN 10 vs VLAN 20
  1. 1.VM1 (VLAN 10, 192.168.83.11) pings VM2 192.168.83.12

  2. 2.br0 sees the same VLAN tag 10 and forwards it to VM2: 2 received

  3. 3.VM1 pings VM3 192.168.83.13 (VLAN 20)

  4. 4.br0 drops it because the VLAN is different: 100% packet loss

Access ports in different VLANs cannot talk without a router

Terminal
ovs-vsctl add-port br0 vm1-p tag=10ovs-vsctl add-port br0 vm2-p tag=10ovs-vsctl add-port br0 vm3-p tag=20ovs-vsctl add-bond br0 bond0 b1 b2 lacp=activeovs-vsctl list-ports br0ovs-vsctl list-ifaces br0ovs-vsctl port-to-br vm1-povs-vsctl iface-to-br b1# inside namespace vm1:ping -c 2 -W 1 192.168.83.12ping -c 2 -W 1 192.168.83.13
Output
$ ovs-vsctl list-ports br0bond0vm1-pvm2-pvm3-p$ ovs-vsctl list-ifaces br0b1b2vm1-pvm2-pvm3-p$ ovs-vsctl port-to-br vm1-p; ovs-vsctl iface-to-br b1br0br0vm1$ ping -c 2 -W 1 192.168.83.122 packets transmitted, 2 received, 0% packet loss, time 1002msvm1$ ping -c 2 -W 1 192.168.83.132 packets transmitted, 0 received, 100% packet loss, time 1019ms

63.5 Global options

  • cmd1 -- cmd2: several commands in one atomic transaction.
  • --oneline: each command's output on one line.
  • --dry-run: does not change the DB (br0 is still listed); combine with --no-wait, else it times out (-t 2 -> signal 14).
  • --db=tcp:IP:6640 manages a remote DB; --retry keeps trying; --no-wait when vswitchd is not running.
Terminal
ovs-vsctl --oneline get bridge br0 datapath_type -- list-ports br0ovs-vsctl --dry-run --no-wait del-br br0ovs-vsctl list-brovs-vsctl -t 2 --dry-run del-br br0
Output
$ ovs-vsctl --oneline get bridge br0 datapath_type -- list-ports br0""bond0\nvm1-p\nvm2-p\nvm3-p$ ovs-vsctl --dry-run --no-wait del-br br0$ ovs-vsctl list-brbr0br10$ ovs-vsctl -t 2 --dry-run del-br br02026-11-08T19:24:17Z|00002|fatal_signal|WARN|terminating with signal 14 (signal 14)[exit 142]

63.6 Table formatting options

  • -f table: aligned columns; --columns picks columns.
  • csv for spreadsheets; json gives headings and data as separate arrays (best for scripts).
  • --bare: only values, no headings or quotes; default format is list.
  • --pretty indents JSON; --max-column-width truncates columns.
Terminal
ovs-vsctl -f table --columns=name,tag list portovs-vsctl --format=csv --columns=name,tag list portovs-vsctl -f json --columns=name,tag list port vm1-povs-vsctl --bare --columns=name list port
Output
$ ovs-vsctl -f table --columns=name,tag list portname  tag----- ---vm3-p 20vm2-p 10vm1-p 10br0   []bond0 []$ ovs-vsctl --format=csv --columns=name,tag list portname,tagvm3-p,20vm2-p,10vm1-p,10$ ovs-vsctl -f json --columns=name,tag list port vm1-p{"data":[["vm1-p",10]],"headings":["name","tag"]}$ ovs-vsctl --bare --columns=name list portvm3-pvm2-pvm1-pbr0bond0

63.7 SSL / PKI and logging

  • --db=ssl:... needs -p (private key), -c (certificate) and -C (CA cert); without them OVS refuses.
  • -C none turns verification off and --bootstrap-ca-cert fetches the CA on first connect: lab only (MITM risk).
  • Verbose format: -vMODULE:DEST:LEVEL, e.g. vsctl:console:dbg; -v sets every module to dbg.
  • Levels off, emer, err, warn, info, dbg; destinations console, syslog, file.
  • The logging options are common to all OVS utilities (ofctl, dpctl too).
Terminal
ovs-vsctl --db=ssl:192.168.83.99:6640 showovs-vsctl --verbose=vsctl:console:dbg list-brovs-vsctl -v list-br 2>&1 | head -4
Output
$ ovs-vsctl --db=ssl:192.168.83.99:6640 show2026-11-08T19:24:27Z|00001|stream_ssl|ERR|Private key must be configured to use SSL2026-11-08T19:24:27Z|00002|stream_ssl|ERR|Certificate must be configured to use SSL2026-11-08T19:24:27Z|00003|stream_ssl|ERR|CA certificate must be configured to use SSLovs-vsctl: ssl:192.168.83.99:6640: database connection failed (Protocol not available)$ ovs-vsctl --verbose=vsctl:console:dbg list-br2026-11-08T19:24:29Z|00001|vsctl|DBG|Called as ovs-vsctl --verbose=vsctl:console:dbg list-brbr0$ ovs-vsctl -v list-br 2>&1 | head -42026-11-08T19:24:29Z|00001|vsctl|DBG|Called as ovs-vsctl -v list-br2026-11-08T19:24:29Z|00002|reconnect|DBG|unix:/var/run/openvswitch/db.sock: entering BACKOFF2026-11-08T19:24:29Z|00003|reconnect|INFO|unix:/var/run/openvswitch/db.sock: connecting...2026-11-08T19:24:29Z|00004|reconnect|DBG|unix:/var/run/openvswitch/db.sock: entering CONNECTING

63.8 Conntrack zones and datapath capabilities

  • Zone policies need a Datapath record; without it list-dp-cap says record not found.
  • add-zone-tp sets per-zone timeouts (ICMP here); set-zone-limit caps connections (0 = unlimited).
  • Datapath name: system (kernel) or netdev (userspace / DPDK).
  • list-dp-cap shows what the kernel datapath supports.
Terminal
ovs-vsctl list-dp-cap systemovs-vsctl -- --id=@d create Datapath datapath_version=0 \  -- set Open_vSwitch . datapaths:system=@dovs-vsctl add-zone-tp system zone=5 icmp_first=30 icmp_reply=60ovs-vsctl list-zone-tp systemovs-vsctl set-zone-limit system 5 1000ovs-vsctl set-zone-limit system default 50000ovs-vsctl list-zone-limits systemovs-vsctl list-dp-cap system | tr ' ' '\n' | head -8
Output
$ ovs-vsctl list-dp-cap systemovs-vsctl: datapath "system" record not found$ ovs-vsctl -- --id=@d create Datapath ...a84f717a-4eef-48d2-ad6f-2755bc050845$ ovs-vsctl list-zone-tp systemZone:5, Timeout Policies: icmp_first=30 icmp_reply=60$ ovs-vsctl list-zone-limits systemDefault, Limit: 50000Zone: 5, Limit: 1000$ ovs-vsctl list-dp-cap system | tr ' ' '\n' | head -8ufid=truesample_nesting=trueclone=truelb_output_action=falsetnl_push_pop=falsend_ext=falsect_orig_tuple=truepsample=false

63.9 Controller, fail-mode, manager

  • set-controller connects br0 to an OpenFlow controller (tcp, ssl, unix; ptcp/pssl/punix listen instead).
  • fail-mode secure: without a controller the switch installs no flows of its own, so traffic is dropped.
  • fail-mode standalone: falls back to a normal MAC-learning L2 switch.
  • set-manager ptcp:6640 makes OVSDB listen for remote managers.
  • add-aa-mapping maps an Auto-Attach I-SID to a VLAN; set-ssl sets the switch's key/cert/CA.
fail-mode secure without a controller
  1. 1.set-controller br0 tcp:192.168.83.1:6653 (controller does not exist)

  2. 2.br0 sends OpenFlow hello; no answer

  3. 3.set-fail-mode br0 secure: switch creates no flows by itself

  4. 4.VM1 pings VM2: dropped at br0, 100% packet loss

  5. 5.del-fail-mode + del-controller: ping back to 0% loss

Standalone mode = normal L2 learning switch

Terminal
ovs-vsctl set-controller br0 tcp:192.168.83.1:6653ovs-vsctl get-controller br0ovs-vsctl set-fail-mode br0 secureovs-vsctl get-fail-mode br0ping -c 2 -W 1 192.168.83.12   # vm1ovs-vsctl del-fail-mode br0ovs-vsctl del-controller br0ping -c 2 -W 1 192.168.83.12   # vm1ovs-vsctl set-manager ptcp:6640ovs-vsctl get-managerovs-vsctl add-aa-mapping br0 10000 100ovs-vsctl get-aa-mapping br0
Output
$ ovs-vsctl get-controller br0tcp:192.168.83.1:6653$ ovs-vsctl get-fail-mode br0secure$ ovs-vsctl show | head -98963fe9b-e16c-48e3-8f06-2967ae16e993    Bridge br0        Controller "tcp:192.168.83.1:6653"        fail_mode: securevm1$ ping -c 2 -W 1 192.168.83.122 packets transmitted, 0 received, 100% packet loss, time 1002ms$ ovs-vsctl del-fail-mode br0; ovs-vsctl del-controller br0vm1$ ping -c 2 -W 1 192.168.83.122 packets transmitted, 2 received, 0% packet loss, time 1001ms$ ovs-vsctl get-managerptcp:6640$ ovs-vsctl add-aa-mapping br0 10000 100; ovs-vsctl get-aa-mapping br010000 100

63.10 Database commands

  • list / find / get / set work on any table (Bridge, Port, Interface, QoS, Mirror...).
  • find port tag=10 gives matching rows; col:key reads one key of a map (statistics:rx_packets).
  • add / remove put one value into or out of a set column (trunks).
  • create + --id=@q hands the new row's UUID to another command in the same transaction.
  • clear empties a column, destroy deletes a row; --if-exists avoids errors; wait-until blocks until a condition is true.
Terminal
ovs-vsctl list bridge br0 | head -12ovs-vsctl --bare --columns=name find port tag=10ovs-vsctl get port vm3-p tagovs-vsctl set port vm3-p tag=10ovs-vsctl get interface vm1-p statistics:rx_packetsovs-vsctl add port vm3-p trunks 30ovs-vsctl remove port vm3-p trunks 30ovs-vsctl -- set port vm2-p qos=@q -- \  --id=@q create qos type=linux-htb other-config:max-rate=1000000ovs-vsctl clear port vm2-p qosovs-vsctl -- --all destroy qosovs-vsctl get port eth9 tagovs-vsctl --if-exists get port eth9 tagovs-vsctl --timeout=3 wait-until interface vm1-p link_state=up
Output
$ ovs-vsctl list bridge br0 | head -12_uuid               : 89ecef1b-970f-48d0-8995-689a54c48364auto_attach         : 80e4f98d-d1a2-462e-b4cd-f37a12dead7dcontroller          : []datapath_id         : "00001aefec89d048"datapath_type       : ""datapath_version    : "<unknown>"external_ids        : {owner=lab}fail_mode           : []flood_vlans         : []$ ovs-vsctl --bare --columns=name find port tag=10vm2-pvm1-p$ ovs-vsctl get port vm3-p tag20$ ovs-vsctl get interface vm1-p statistics:rx_packets24$ ovs-vsctl get port vm3-p trunks[30]$ ovs-vsctl remove port vm3-p trunks 30; ovs-vsctl get port vm3-p trunks[]$ ovs-vsctl -- set port vm2-p qos=@q -- --id=@q create qos ...683aef0d-fb42-49a9-a3db-4f5de2f4fdeb$ ovs-vsctl get port eth9 tag; echo $?ovs-vsctl: no row "eth9" in table Port1$ ovs-vsctl --if-exists get port eth9 tag; echo $?0$ ovs-vsctl --timeout=3 wait-until interface vm1-p link_state=up; echo $?0
CommandPurpose
list TABLE [rec]Show full rows
find TABLE col=valRows matching a condition (= != < > <= >=)
get / set TABLE rec col[:key]Read / write a column or map key
add / remove TABLE rec col valAdd or remove a set/map element
clear TABLE rec colEmpty a set or map
create / destroyMake or delete a row (--id=@n, --all)
wait-until TABLE rec col=valBlock until the condition holds

63.11 Value syntax

  • Integers as is; a range 100-103 becomes a set of four values; [] is an empty set.
  • Booleans: true / false.
  • Maps: {key=value,...}; keep them in quotes in the shell.
  • The string "true" needs double quotes, else OVS reads a boolean.
  • Table names are case-insensitive; a UUID can be shortened to 4 hex digits.
Terminal
ovs-vsctl set port vm3-p trunks=100-103ovs-vsctl set port vm3-p trunks=[]ovs-vsctl set bridge br0 stp_enable=trueovs-vsctl set interface vm1-p 'external_ids={team=net,env=lab}'ovs-vsctl set interface vm1-p external_ids:note='"true"'ovs-vsctl get interface vm1-p external_ids
Output
$ ovs-vsctl set port vm3-p trunks=100-103; ovs-vsctl get port vm3-p trunks[100, 101, 102, 103]$ ovs-vsctl set port vm3-p trunks=[]; ovs-vsctl get port vm3-p trunks[]$ ovs-vsctl set bridge br0 stp_enable=true; ovs-vsctl get bridge br0 stp_enabletrue$ ovs-vsctl set interface vm1-p 'external_ids={team=net,env=lab}'; ovs-vsctl get interface vm1-p external_ids{env=lab, team=net}$ ovs-vsctl set interface vm1-p external_ids:note='"true"'; ovs-vsctl get interface vm1-p external_ids{env=lab, note="true", team=net}

63.12 Common mistakes

  • Thinking ovs-vsctl forwards packets or creates flows: it only edits OVSDB; flows are ovs-ofctl.
  • Setting fail-mode secure with no reachable controller: all traffic drops.
  • Running del-br on a production bridge: it removes every port too.
  • Forgetting quotes around maps or string values like "true".

63.13 Interview tips

  • Linux bridge vs OVS: a simple kernel L2 bridge vs a programmable switch with flows, VLANs, bonds and tunnels in one DB.
  • OVS config persists in OVSDB and an SDN controller can drive it remotely.
  • fail-mode secure + controller down = traffic dropped; standalone = normal switching.
  • Use --may-exist / --if-exists for idempotent automation and -- for atomic multi-command changes.