Created
April 20, 2020 05:42
-
-
Save Hritik14/098c728e31056ecec28622b81de04a02 to your computer and use it in GitHub Desktop.
Multipath routing to increase bandwith
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
#!/bin/bash | |
# (C) Hritik Vijay | |
# License: GPLv2 | |
Table=200 | |
route_cmd="ip route add default scope global " | |
# Iterate through each interface and process them | |
while read -r line; do | |
P=$(echo $line | grep -Eo 'via [0-9\.]+ ' | cut -d " " -f 2) | |
IF=$(echo $line | grep -Eo 'dev [A-Za-z0-9]+ ' | cut -d " " -f 2) | |
ip=$(ip -br address show dev "$IF" | tr -s ' ' | cut -d " " -f 3) | |
IP=${ip%%/*} P_NET=$P # Assumption | |
# Init table | |
ip route add "$P_NET" dev "$IF" src "$IP" table $Table | |
ip route add default via "$P" table $Table | |
# Match connections on proper interfaces | |
ip rule add from "$IP" table $Table | |
# add nexthop | |
route_cmd="$route_cmd nexthop via $P dev $IF weight 1 " | |
# a new table | |
Table=$((Table+1)) | |
done < <(ip route list default) | |
echo $route_cmd | |
eval "$route_cmd" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment