Skip to content

Instantly share code, notes, and snippets.

@zaneclaes
Created October 30, 2019 20:19
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zaneclaes/89ffcaa8ac4cbb07c002cdc313a727ef to your computer and use it in GitHub Desktop.
Save zaneclaes/89ffcaa8ac4cbb07c002cdc313a727ef to your computer and use it in GitHub Desktop.
#!/bin/bash
interfaces=(eth0 eth1 eth2) # which interfaces to auto-detect, in descending order of priority
interface="eth0" # the default/current interface
while true; do
newif="$interface"
for i in "${interfaces[@]}"; do
if $(ip link show dev "$i"); then
newif="$i"
fi
done
if [[ ! "$interface" == "$newif" ]]; then
echo "Switching from $interface to $newif"
brctl delif br0 "$interface" || true
brctl addif br0 "$newif"
interface="$newif"
fi
sleep 5
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment