Skip to content

Instantly share code, notes, and snippets.

@jonjonw
Created September 30, 2018 22:26
Show Gist options
  • Save jonjonw/f4f38e57681d11d9f611515c6701aa7c to your computer and use it in GitHub Desktop.
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.
# /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
#!/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
@dellgreen
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment