My goal was to configure the following network settings on Ubuntu 18.04 (bionic) using Open vSwitch bridge and ports.
Uplink is a trunk port connected to eth0.
VLAN Tagged Interface IP trunk eth0 100 no vlan100 192.168.100.3 200 yes vlan200 192.168.200.4
Netplan is the default utility on Ubuntu 18.04 (bionic) for configuring network.
Unfortunately Netplan can not brings up Open vSwitch bridges and ports like ifupdown does.
Basically you have the following options:
The classic way is installing ifupdown for IP configuration and optionally resolvconf for DNS resolver configuration.
Install packages.
apt-get install ifupdown openvswitch-switch resolvconf
Edit /etc/network/interfaces.
auto br0 allow-ovs br0 iface br0 inet manual ovs_type OVSBridge ovs_ports eth0 vlan100 vlan200 dns-nameservers 192.168.100.10 dns-search example.com allow-br0 eth0 iface eth0 inet manual ovs_bridge br0 ovs_type OVSPort ovs_options vlan_mode=native-untagged tag=100 allow-br0 vlan100 iface vlan100 inet static address 192.168.100.3 netmask 255.255.255.0 gateway 192.168.100.1 ovs_type OVSIntPort ovs_bridge br0 ovs_options tag=100 allow-br0 vlan200 iface vlan200 inet static address 192.168.200.4 netmask 255.255.255.0 ovs_type OVSIntPort ovs_bridge br0 ovs_options tag=200
Note: As README.Debian for openvswitch-switch mentions, and Ubuntu bug #1448254 describes (suggested workaround) auto br0 should not be set in /etc/network/interfaces, however it worked for me under bionic.
Netplan does not manage Open vSwitch.
You have to set up Open vSwitch before the IP configuration.
It is very easy to manage Netplan with Ansible, as network configuration can be stored in inventory group or host variables in YAML format.
Install Open vSwitch.
apt-get install openvswitch-switch
Configure Open vSwitch.
ovs-vsctl add-br br0 ovs-vsctl add-port br0 eth0 ovs-vsctl set port eth0 tag=100 vlan_mode=native-untagged ovs-vsctl add-port br0 vlan100 tag=100 -- set interface vlan100 type=internal ovs-vsctl add-port br0 vlan200 tag=200 -- set interface vlan200 type=internal
Create Netplan configuration.
network: version: 2 renderer: networkd ethernets: vlan100: dhcp4: no addresses: - 192.168.100.3/24 gateway4: 192.168.100.1 nameservers: search: [example.com] addresses: [192.168.100.10] vlan200: dhcp4: no addresses: - 192.168.200.4/24
Apply configuration.
sudo netplan generate sudo netplan apply
Systemd-networkd does not manage Open vSwitch.
You have to set up Open vSwitch before the IP configuration.
Install and configure Open vSwitch similarly as in Netplan.
/etc/systemd/network/10-eth0.network:
[Match] Name=eth0
/etc/systemd/network/10-vlan100.network:
[Match] Name=vlan1 [Network] Address=192.168.100.3/24 Gateway=192.168.100.1 DNS=192.168.100.10
/etc/systemd/network/10-vlan200.network:
[Match] Name=vlan11 [Network] Address=192.168.200.4/24
Restart systemd-networkd.
sudo systemctl restart systemd-networkd