Home
Help
Search
Login
Register
OPNsense Forum
»
English Forums
»
Development and Code Review
(Moderator:
fabian
) »
bridge script to auto add into/out of the bridge active and non active interface
« previous
next »
Print
Pages: [
1
]
Author
Topic: bridge script to auto add into/out of the bridge active and non active interface (Read 7814 times)
Fantonald
Newbie
Posts: 1
Karma: 0
bridge script to auto add into/out of the bridge active and non active interface
«
on:
October 06, 2024, 10:45:05 am »
I have little to zero knowledge about router software or coding.
However, I have added a small script that checks the status of network interface cards (NICs) every 30 seconds. If a change is detected, such as a NIC becoming active, it will automatically be added to the bridge. Conversely, if a NIC currently in the bridge becomes inactive or disconnected, it will be removed from the bridge within 30 seconds.
The reason I created this script is to address issues where inactive NICs in the bridge generate a lot of errors. By automatically removing inactive NICs and adding them back when they become active, I hope to reduce these errors and improve stability.
The errors is comming up in the bridge interface "out" section of the "Interface Statistics"
I don't know if they matter at all or make any problems on the way, but it can get up into millions of errors there. And it stopps up asap when i take the not active card out of the bridge.
It is a home router for a house where it is a lot of gaming, and it is using 9900k cpu and 16gb of ram and have a total of about 25 devices connected to it over wifi and cable.
My question: Will this script cause any problems since it only runs in the background, and the changes to the NICs in the bridge are not reflected in the web GUI?
Here is the script:
#!/bin/sh
BRIDGE_NAME="bridge0" # This is the correct bridge name
INTERFACES="igb0 igb1 igb2 igb3 igb4 igb5 igb6 igb7 em0" # Replace with the actual interface names
while true; do
for IFACE in $INTERFACES; do
STATUS=$(ifconfig $IFACE | grep "status: active")
# Check if interface is active and not already part of the bridge
if [ -n "$STATUS" ] && ! ifconfig $BRIDGE_NAME | grep -q "$IFACE"; then
ifconfig $BRIDGE_NAME addm $IFACE
echo "Added $IFACE to $BRIDGE_NAME"
fi
# Check if interface is inactive and is part of the bridge
if [ -z "$STATUS" ] && ifconfig $BRIDGE_NAME | grep -q "$IFACE"; then
ifconfig $BRIDGE_NAME deletem $IFACE
echo "Removed $IFACE from $BRIDGE_NAME"
fi
done
sleep 30
done
«
Last Edit: October 06, 2024, 10:59:29 am by Fantonald
»
Logged
Print
Pages: [
1
]
« previous
next »
OPNsense Forum
»
English Forums
»
Development and Code Review
(Moderator:
fabian
) »
bridge script to auto add into/out of the bridge active and non active interface