Skip to content

Instantly share code, notes, and snippets.

@vincentchalamon
Last active June 28, 2022 08:39
Show Gist options
  • Save vincentchalamon/93710b8930b8b5f15361fa8e84e3a699 to your computer and use it in GitHub Desktop.
Save vincentchalamon/93710b8930b8b5f15361fa8e84e3a699 to your computer and use it in GitHub Desktop.
Fix SNX interface scope
fixInterfaceScope() {
interface=tunsnx
data=($(ip -o address show "$interface" | awk -F ' +' '{print $4 " " $6 " " $8}'))
LOCAL_ADDRESS_INDEX=1
PEER_ADDRESS_INDEX=2
SCOPE_INDEX=3
if [ "${data[$SCOPE_INDEX]}" = "global" ]
then
echo "Interface ${interface} is already set to global scope. Skip!"
return
else
echo "Interface ${interface} is set to scope ${data[$SCOPE_INDEX]}."
tmpfile=$(mktemp --suffix=snxwrapper-routes)
echo "Saving current IP routing table..."
sudo ip route save dev ${interface} > ${tmpfile}
echo "Deleting current interface ${interface}..."
sudo ip address del ${data[$LOCAL_ADDRESS_INDEX]} peer ${data[$PEER_ADDRESS_INDEX]} dev ${interface}
echo "Recreating interface ${interface} with global scope..."
sudo ip address add ${data[$LOCAL_ADDRESS_INDEX]} dev ${interface} peer ${data[$PEER_ADDRESS_INDEX]} scope global
echo "Restoring routing table..."
sudo ip route restore < $tmpfile 2>/dev/null
echo "Cleaning temporary files..."
rm $tmpfile
echo "Interface ${interface} is set to global scope. Done!"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment