Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
networkd-dispatcher bash script to set all IPv6 addresses to preferred_lft 0
# bash v4 required because of associative array below.
# networkd-dispatcher hook script that sets every IPv6 address on the system to
# have preferred_lft 0. Put it in for example in
# /etc/networkd-dispatcher/routable.d/50-set-preferred-lft and make sure it's
# executable and owned by root:root.
# There's an associative array below where you can list addresses NOT to
# interfere with.
declare -A exceptions
# Associative array with keys for each address that you DON'T want to have
# a preferred_lft of 0. Every other v6 address on the system will have
# preferred_lft 0 set.
logger -t $logname \
"$IFACE/$STATE: Looking for IPv6 addresses to set preferred_lft 0…"
for ip6 in $IP6_ADDRS
if [[ -n "${exceptions[$ip6]}" ]]
logger -t $logname \
"Not setting preferred_lft for $ip6 as it's in exception list"
logger -t $logname \
"Setting preferred_lft 0 for $ip6"
ip address change ${ip6} dev ${IFACE} preferred_lft 0
logger -t $logname \
"$IFACE/$STATE: Done."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.