This repository contains scripts and configuration files to set up an Open vSwitch (OVS) bridge for a host with VLAN trunking and access ports.
-
ens4
andens6
: Trunk ports carrying VLANs 2201–2205 -
ens5
: Access port on VLAN 2201, used for management (IP:10.10.3.2/24
) -
The diagram:
setup-ovs.sh
: Configures the OVS bridge and portssetup-ovs.service
: systemd unit to automatically apply the OVS setup on bootnetplan/01-netcfg.yaml
: Netplan config to assign an IP address on VLAN 2201
Note: The IP addresses, VLAN IDs, and interface names in the YAML and setup script are specific to one environment.
You must update these values to match your network infrastructure:
- IP address (
10.0.22.3/24
) → your desired management IP on the ens3 port (in netplan)- VLANs (
2201–2205
) → your VLAN range- Interfaces (
ens4
,ens5
,ens6
) → your actual NIC names
sudo apt update
sudo apt install -y openvswitch-switch openvswitch-common
sudo cp setup-ovs.sh /usr/local/bin/
sudo chmod +x /usr/local/bin/setup-ovs.sh
sudo cp setup-ovs.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable setup-ovs.service
Edit /etc/netplan/01-netcfg.yaml
to include a defined br0
bridge:
network:
version: 2
renderer: networkd
#this configuration is for the OOB (Out-Of-Band) management of the host only.
ethernets:
ens3: #change this to you out-of-band management port
dhcp4: false
dhcp6: false
addresses:
- 10.0.22.3/24 #change this to the IP you want to assign
routes:
- to: default
via: 10.0.22.254 #change this to the gateway of interface
nameservers:
addresses: [8.8.8.8] #change to whatever the DNS you want to use
Then apply the configuration:
sudo netplan generate
sudo netplan apply
sudo reboot
After rebooting:
-
Check if bridge
br0
is are up:ip addr show br0
-
Test IP connectivity:
ping 10.0.22.3
-
Test SSH access to
10.0.22.3
from another host. -
Check Open vSwitch config:
sudo ovs-vsctl show
If the system stalls at systemd-networkd-wait-online.service
, disable and mask it:
sudo systemctl disable systemd-networkd-wait-online.service
sudo systemctl mask systemd-networkd-wait-online.service
Ensure that br0
is declared in the Netplan YAML. Netplan must define the bridge, even if Open vSwitch also creates it.
If ovs-vsctl
shows: could not add network device br0 to ofproto (file exists)
, the bridge might have been defined both by Netplan and OVS. To avoid this:
- Use Netplan only to define the existence of
br0
(with no interfaces). - Let
setup-ovs.sh
handle the OVS configuration.
Create a systemd-networkd override for br0
:
sudo mkdir -p /etc/systemd/network/
cat <<EOF | sudo tee /etc/systemd/network/br0.network
[Match]
Name=br0
[Network]
DHCP=no
[Link]
RequiredForOnline=no
EOF
sudo systemctl restart systemd-networkd
- Ubuntu system with Open vSwitch installed
systemd-networkd
as the Netplan renderer
MIT License