ianharrier / synology-scripts

Scripts for Synology DSM
MIT License
112 stars 34 forks source link

Default Gateway sticks #27

Closed nickel82 closed 1 year ago

nickel82 commented 1 year ago

This script is great and solves the issue 90% of the time but i occasionally see an odd one where the default gateway sticks to the VPN gateway when the vpn disconnects and so when it tries to reconnect (in our case to OpenVPN cloud) it cannot because it isn't using the lan1 gateway to attempt reconnection. Wondered if anyone else has seen this too!? Ive cobbled together with my limited knowledge a script (below) which checks the default and changes it if needed but it doesn't always seem to work (it works fine when im logged in and run it, but not when its running on its own oddly, despite root being set as the run user). I put this just before '/usr/syno/bin/synovpnc kill_client'

gateway=$(ip route | awk '/default/ { print $3 }')

Check if current gateway is already LAN1

if [ "$gateway" = "$(ip addr show dev eth0 | awk '/inet/ { print $4 }' | cut -d/ -f1)" ]; then echo "Default gateway is already set to LAN1." exit 0 fi

Disable current default gateway

ip route del default

Set default gateway to LAN1

ip route add default via $(ip addr show dev eth0 | awk '/inet/ { print $4 }' | cut -d/ -f1)

echo "Default gateway has been set to LAN1."

ianharrier commented 1 year ago

If I'm understanding correctly, it sounds like you're saying the gateway from the VPN connection is persisting after the VPN connection is disconnected, so reconnects aren't succeeding because DSM is trying to route the Internet-bound traffic through a non-existent gateway. If that's the case, it sounds like either (a) the VPN connection isn't actually disconnecting, (b) there's a misconfiguration, or (c) there's a bug in DSM. In order to troubleshoot further, I would suggest creating a script that would dump the routing table to a file on some scheduled basis for analysis.

Given that I have not seen any other reported issues similar to yours, I am going to close this issue.

Also, in case you're not aware, version 1.5.0 introduced the ability to run external scripts at various points of the script's execution. The script you wrote could be executed via PRE_RECONNECT_SCRIPT, if desired.

beornlake commented 1 year ago

I know this is closed, but I've definitely seen the issue where the VPN could not reconnect. I hadn't been able to track down the cause, so I can't say if it's the same as what @nickel82 has found, but it certainly sounds similar. Typically it happens when one of our clients machines is on an inconsistent/unstable internet connection and the tunnel has to be repeatedly rebuilt in a short time window. I was chalking it up to a bug in DSM or the version of OpenVPN that is installed by DSM, but this might be the real cause. If I'm able to track it down, then I'll report back here.

nickel82 commented 1 year ago

Yep thats it! So it mainly happens to us when OpenVPN Cloud do an update and it knocks people off intentionally (computers seem to reconnect but some synologies dont)...that said it also randomly happens to others, i think due to unstable connections like you say. My script to test for the gateway and reset it only seems to work when im logged in though rather than all the time, even though in task manager its set to root and every 10 mins...maybe my scripting isnt right though! I would love to solve this, its driving me mad! (Ian - your script though has been fantastic for all other situations, thank you!)