Created
August 24, 2021 14:09
-
-
Save loupzeur/6b29d0aa5598c933a4070cd3509c3559 to your computer and use it in GitHub Desktop.
Generate rule table for all non l interface having an ip address (for mptcp support)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/bash | |
IP=$(ip addr | awk ' | |
/^[0-9]+:/ { | |
sub(/:/,"",$2); iface=$2 } | |
/^[[:space:]]*inet / { | |
split($2, a, "/") | |
print iface" "a[1] | |
}'|egrep -v ^lo) | |
IFS=$'\n' | |
count=0 | |
for i in $IP | |
do | |
IFS=' ' | |
INT=($i) | |
count=$((count+1)) | |
LAST_IP=${INT[1]} | |
LAST_IN=${INT[0]} | |
LAST_GW=$(ip route|grep ${INT[0]} |grep default|cut -f3 -d' ') | |
echo "ip rule add from ${INT[1]} table $count" | |
echo "ip route add $(ip route|grep ${INT[0]}|grep src|cut -d' ' -f1) dev ${INT[0]} scope link table $count" | |
echo "ip route add default via $LAST_GW dev ${INT[0]} table $count" | |
done | |
echo "ip route add default scope global nexthop via $LAST_GW dev $LAST_IN" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Another script to do the same (adding rule and route for table)