#!/bin/bash # Please adapt the below variables to your needs # WARNING: any existing configuration in /etc/systemd/network # will be trashed by this script. # Backup before or run in a container/VM, whatever # Afterwards, set TRASH_MY_NETWORK_CONFIG=yesplease and go ahead ETH_MODULE=igb ETH_IFACE=enp11s0f0 [ "$TRASH_MY_NETWORK_CONFIG" = "yesplease" ] || exit 1 VLANS=$1 if [ -z "$VLANS" ]; then echo "Usage: $0 <# of VLANs>" exit 1 fi rm -rf /etc/systemd/network mkdir -p /etc/systemd/network echo "[Match] Name=test*" > /etc/systemd/network/00-test.network echo "[Match] Name=$ETH_IFACE [Network]" > /etc/systemd/network/00-trunk.network for ((i=1; i <= VLANS; ++i)); do echo "[NetDev] Name=test-$i Kind=vlan [VLAN] Id=$i" > /etc/systemd/network/test-$i.netdev; echo "VLAN=test-$i" >> /etc/systemd/network/00-trunk.network done rmmod "$ETH_MODULE" systemctl stop systemd-networkd CURSOR=$(journalctl -n0 --show-cursor | awk '/^-- cursor:/ {print $3}') modprobe "$ETH_MODULE" systemctl start systemd-networkd sleep 5 ip link echo journalctl --no-pager -u systemd-networkd --cursor "$CURSOR"