Notes
ViliusCh

Ethernet bridge setup (for stm32mp1)

Enabling network bridge with single run script

Refferences:
ArchWiki


Network bridge setup script tested on stm32mp1 board with additional ethernet ports.

Will work on any systemd linux systems.

Create a bash file in directory of choice

root@stm32mp1:~# touch AUTO_BRIDGE.sh

Paste in the following script:

#!/bin/bash

# Check if script is run as root
if [ "$EUID" -ne 0 ]; then
    echo "Please run as root"
    exit 1
fi

# Variables

INTERFACE_FILE = "/etc/systemd/network/25-br0.netdev"
BIND_FILE = "/etc/systemd/network/25-br0-en.network"
BRIDGE_FILE = "/etc/systemd/network/25-br0.network"

#touch "$INTERFACE_FILE"
#touch "$BIND_FILE"
#touch "$BRIDGE_FILE"

cat > "$INTERFACE_FILE" << EOL
[NetDev]
Name=br0
Kind=bridge
EOL


cat > "$BIND_FILE" << EOL
[Match]
Name=lan*

[Network]
Bridge=br0
EOL

cat > "$BRIDGE_FILE" << EOL
[Match]
Name=br0

[Link]
RequiredForOnline=routable

[Network]
DHCP=yes
EOL

echo "Bridge creation successful"

Lastly the permissions need to be changed for the script file so it would be executable, run the following command to do sudo

root@stm32mp1:~# chmod +x AUTO_BRIDGE.sh

Script is ready to be executed by running ./AUTO_BRIDGE.sh