I need some port on a publicly accessible host constantly forwarded to a server that is behind a firewall.
I'm currently using autossh to connect from the server to an openssh container running on GKE and forward the port as required:
/usr/bin/autossh \
-y \
-v \
-i <ssh key> \
-M 0 \
-q \
-o 'ServerAliveInterval 60' \
-o 'ServerAliveCountMax 3' \
-p <alternative ssh port> \
-l <user name> \
<name resolving (locally) to GKE public IP address> \
-R 30000:localhost:6000
'while true; do echo were up; sleep 10; done' # this is done to generate a minimal amount of traffic.
Problem is, sometimes when the connection drops, autossh reconnects but can't set up forwarding again. It won't fail though, and therefore it won't retry. When I stop autossh and try to connect in such a situation, just using ssh (-vvv), I get a warning message that says the port is already in use.
Questions:
Is there a better way to keep forwarding a port to a server behind a firewall (securely)
Why isn't the port freed immediately once the connection is dropped, can I force it to be freed somehow, or at least disconnect and try again until it is freed?