Ubuntu as Switch

use netplan to config bridge

/etc/netplan
sudo nano 00-installer-config.yaml
network:
  version: 2
  ethernets:
    enp2s0:
      dhcp4: no
    enp3s0:
      dhcp4: no
    enp4s0:
      dhcp4: no
    enp5s0:
      dhcp4: no
  bridges:
    br0:
      dhcp4: yes
      interfaces:
        - enp2s0
        - enp3s0
        - enp4s0
        - enp5s0
      parameters:
        stp: true

config sysctl to disable ubuntu ethernet filtering

cd /etc
sudo nano sysctl.conf
net.bridge.bridge-nf-call-ip6tables = 0
net.bridge.bridge-nf-call-iptables = 0
net.bridge.bridge-nf-call-arptables = 0

add crontab to enable sysctl config

sudo crontab -e
@reboot /bin/sleep 5 && /sbin/sysctl -p

reboot to check

sudo reboot

Reference