I set up reverse tunnel this way:
function startconn () {
ssh -N -b ${SRCIP} -X -R ${REMOTEIP}:${REMOTEPORT}:${LOCALIP}:${LOCALPORT} root@${REMOTEIP} &
SSHPID=$!
echo "$SSHPID" > $PIDFILE
echo "Forwarding port ${REMOTEPORT} at ${REMOTEIP} to ${LOCALIP}:${LOCALPORT}"
}
This forwards REMOTEPORT@REMOTEIP via backup link available via SRCIP network (I have auxilliary NIC with SRCIP==192.168.5.2 that connects to backup link gateway at 192.168.5.1).
It works nicely, but there's a problem: if ssh connection gets broken, e.g. by restart of gateway, etc, in general anything that breaks TCP/IP connection of reverse tunnel ssh session, sshd process at REMOTEIP is hanging, preventing re-establishing reverse tunnel to this port (30200 below is REMOTEPORT):
netstat -anp | grep 30200
tcp 0 0 0.0.0.0:30200 0.0.0.0:* LISTEN 8772/sshd: root
The only viable solution I see for now is the reconnect script logging on lost connection to REMOTEIP and killing sshd process "manually" before trying to re-establish reverse tunnel.
Is there any smarter/less cumbersome way to prevent remote sshd process blocking REMOTEIP port?