Created
November 17, 2018 23:37
-
-
Save grifferz/0421e2876b270bb6816e94e5db37bb2e to your computer and use it in GitHub Desktop.
networkd-dispatcher bash script to set all IPv6 addresses to preferred_lft 0
This file contains hidden or 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 | |
# 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. | |
logname="set-preferred-lft" | |
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. | |
exceptions["2001:ba8:1f1:f1d7::2"]="1" | |
logger -t $logname \ | |
"$IFACE/$STATE: Looking for IPv6 addresses to set preferred_lft 0…" | |
for ip6 in $IP6_ADDRS | |
do | |
if [[ -n "${exceptions[$ip6]}" ]] | |
then | |
logger -t $logname \ | |
"Not setting preferred_lft for $ip6 as it's in exception list" | |
else | |
logger -t $logname \ | |
"Setting preferred_lft 0 for $ip6" | |
ip address change ${ip6} dev ${IFACE} preferred_lft 0 | |
fi | |
done | |
logger -t $logname \ | |
"$IFACE/$STATE: Done." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment