Skip to content

Instantly share code, notes, and snippets.

@andiwand
Last active September 26, 2018 04:07
Show Gist options
  • Save andiwand/19dc57d632b63af0ee1ec1739a2106bf to your computer and use it in GitHub Desktop.
Save andiwand/19dc57d632b63af0ee1ec1739a2106bf to your computer and use it in GitHub Desktop.
OpenWrt / LEDE script to fix default routes.
#!/bin/ash
# OpenWrt / LEDE script to fix default routes.
if [ "$#" -ne 1 ]; then
>&2 echo "usage: $0 interface [interface ...]"
exit 1
fi
for arg in "$@"; do
INTERFACE="$arg"
uci get "network.${INTERFACE}.gateway" > /dev/null 2>&1 || exit
GATEWAY=`uci get "network.${INTERFACE}.gateway"`
METRIC=`uci get "network.${INTERFACE}.metric"`
[ `ifstatus ${INTERFACE} | jsonfilter -e "@.up"` = true ] && OPERATION=add ||
ip route $OPERATION default via $GATEWAY metric $METRIC
#echo "ip route $OPERATION default via $GATEWAY metric $METRIC"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment