Score:2

SSH tunnel reconnecting after WAN change or server drop

cn flag

I am fighting with autoSSH configuration.

My setup

  1. VPS as a public contact point, clients will access the VPS IP to get to the server
  2. My home server running the service. This machine has dualwan connectivity - so it can switch to another ISP if the first one drop. (IP address will change)

I want to make a SSH tunnel that will automatically reconnect when the connectivity is switched or one of those two machines is restarted (or the tunnel drops for whatever reason).

Both machines runs on Debian 10 64bit with no GUI

What I did:

I created a Systemd service that will connect the autossh tunnel at the start of the machine when network is online. You can see my service here: https://paste.brcb.eu/xefobiremy.ini

The autossh command is:
/usr/bin/autossh -o "ServerAliveInterval 60" -o "ServerAliveCountMax 3" mctunel@remoteIP -p 22 -N -R 25565:localhost:25565 -i /home/mc/fhkey

My issue:

Whenever the connectivity switch or somethign goes wrong, the tunnel will not recover. Service will just run without any tries to reconnect. If I restart the service manually, I will get an error that the forwarding cannot connect to port 25565 - the connection was not closed on the VPS side and the port is still "used".

Any idea how to make this work? I can even use other software than autossh, if its better for my situation.

Thanks!

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.