read -t 1 -N 100000 || true # clear stdin
for int in $( sed -n '/# local/,$ { /^[^#]/ s/.* // p }' /etc/iproute2/rt_tables )
do
- tab=$(ip -6 route list table "$int" |
- sed 's/\(dev [^ ]*\) .*/\1/')
- def=$(ip -6 route list match default |
- sed -n '/dev '"$int"'/ {
+ for proto in 4 6
+ do
+ tab=$(ip -"$proto" route list table "$int" match default |
+ sed 's/\(dev [^ ]*\) .*/\1/')
+ def=$(ip -"$proto" route list match default |
+ sed -n '/dev '"$int"'/ {
s/\(dev [^ ]*\) .*/\1/
p
}')
- if [ "x$def" != "x$tab" ]
- then
- ip -6 route del $tab table "$int" || true
- ip -6 route add $def table "$int" || true
- ip -6 rule del table "$int" || true
- ip -6 rule add from $(
- ip -6 addr show "$int" scope global | sed -n '
- /inet6/ {
- s/.*inet6 //
+ if [ "x$def" != "x$tab" ]
+ then
+ ip -"$proto" route flush table "$int" || true
+ ip -"$proto" route add $def table "$int" || true
+ ip -"$proto" route add $(
+ ip -"$proto" route list proto kernel |
+ sed -n '/dev '"$int"'/ {
+ s/\(dev [^ ]*\) .*/\1/
+ p
+ q
+ }'
+ ) table "$int" || true
+ ip -"$proto" rule del table "$int" || true
+ ip -"$proto" rule add from $(
+ ip -"$proto" addr show "$int" scope global | sed -n '
+ /inet/ {
+ s/.*inet[^ ]* //
s/ .*//
p
}') table "$int"
- fi
+ fi
+ done
done
done
)