Created
September 30, 2018 22:26
-
-
Save jonjonw/f4f38e57681d11d9f611515c6701aa7c to your computer and use it in GitHub Desktop.
This is a hack to work around https://github.com/systemd/systemd/issues/928 and add metrics to all routes on an interface/network.
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
# /etc/systemd/system/systemd-networkd.service.d/fix-route-metric.conf | |
[Service] | |
ExecStartPost=/usr/local/lib/ip-route-change-metric.sh 192.168.0.0/24 net0 1024 |
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 | |
# /usr/local/lib/ip-route-change-metric.sh | |
# Usage: $0 <destination> <dev> <metric> | |
# ex: $0 192.168.0.0/24 net0 2048 | |
OLD_ROUTES=`ip route show to exact $1 | grep "dev $2"` | |
while read -r OLD_ROUTE; do | |
ip route del $OLD_ROUTE | |
LAST_OLD_ROUTE="$OLD_ROUTE" | |
done <<< "$OLD_ROUTES" | |
ip route add $LAST_OLD_ROUTE metric $3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This doesn't seem work for me as systemd 237 on my system, as system seems to be protected with the file system as read-only for this unit so the here-string cannot be saved to tmp directory.