Last active
April 13, 2020 10:07
-
-
Save grainrigi/b0f44abb0c3ff615181d86169ea3bdec to your computer and use it in GitHub Desktop.
flannel save/restore
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 | |
# Restore Flannel | |
DEVICE=flannel.1 | |
# Load Config | |
source /tmp/.flannel-save || exit | |
# Restore link | |
ip l a "$DEVICE" type vxlan id 1 local 192.168.210.252 dstport 8472 dev wg0 | |
ip l set dev "$DEVICE" address "$MACADDR" | |
ip a a dev "$DEVICE" "${IPADDR}" | |
ip l set dev "$DEVICE" up | |
# Restore arp/route | |
echo "$NETWORKS" | while read network; | |
do | |
LINK="$(echo "$network" | awk '{print $2}')" | |
INET="$(echo "$network" | awk '{print $1}')" | |
ip neigh add "$INET" dev "$DEVICE" lladdr "$LINK" | |
ip r a "${INET}/24" dev "$DEVICE" via "$INET" onlink | |
done | |
# Restore fdb | |
echo "$FDBS" | while read fdb; | |
do | |
LINK="$(echo "$fdb" | awk '{print $1}')" | |
INET="$(echo "$fdb" | awk '{print $2}')" | |
bridge fdb replace "$LINK" dev "$DEVICE" dst "$INET" self | |
done | |
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 | |
# Save Flannel | |
DEVICE=flannel.1 | |
# Prepare save file | |
rm -f /tmp/.flannel-save | |
save_conf() { | |
local KEY="$1" | |
local VAL="$2" | |
echo "$KEY='$VAL'" >> /tmp/.flannel-save | |
} | |
# Save Device Address | |
IPRAW="$(ip a show "$DEVICE")" | |
MACADDR="$(echo "$IPRAW" | grep "link/ether" | awk '{print $2}')" | |
IPADDR="$(echo "$IPRAW" | grep "inet " | awk '{print $2}')" | |
save_conf MACADDR "$MACADDR" | |
save_conf IPADDR "$IPADDR" | |
# Save networks | |
NETWORKS="$(ip neigh show dev "$DEVICE" | grep PERMANENT | awk '{print $1" "$3;}')" | |
save_conf NETWORKS "$NETWORKS" | |
# Save Forwards | |
FDBS="$(bridge fdb show dev "$DEVICE" | awk '{print $1" "$3;}')" | |
save_conf FDBS "$FDBS" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment