[Basic]
# One server, two clients (IP unknown)
# Forwarding port from server to client
(IPs of clients change regularly and aren't known, between client A and B are Firewalls, which don't allow connections from outside)
Client A is allowed to connect to the server, but not to client B.
Client B is allowed to connect to the server, but not to client A.
[Solution]
Client B makes a connection to the server to forward a remote port to the local host and hold this connection all the time (cron-script).
Client A makes a connection to the remote port on the server and will be forwarded to the client B.
[Why?]
I use this to forward a SSH connection from work home, or the other way around.
[Example with SSH]
The SSH daemon runs also on both clients and on the server.
So I forward a port from the server to my clients ssh port.
[Client B]
ssh -R 2048:localhost:22 user@example.com
[Client A]
ssh -P -L1234:localhost:2048 user@example.com
ssh -p 1234 localhost
[crontab -l]
# check connection to the server
*/2 * * * * /root/fwd_ssh > /dev/null 2>&1
[Cron-Script - fwd_ssh]
#!/bin/sh
# $REMOTE_HOST is the name of the remote system
REMOTE_HOST=user@example.com
# $REMOTE_PORT is the remote port number that will be used to tunnel
# back to this system
REMOTE_PORT=2048
# $CMDDHCPCD dhcpcd command
CMDDHCPCD="/sbin/dhcpcd -d -t 30 eth0"
# $CMDSSHD sshd command
CMDSSHD="/etc/rc.d/rc.sshd start"
# $COMMAND is the command used to create the reverse ssh tunnel
COMMAND="ssh -f -q -N -R ${REMOTE_PORT}:localhost:22 ${REMOTE_HOST}"
# Is the dhcpcdaemon running?
pgrep -f -x "${CMDDHCPCD}" > /dev/null 2>&1 || ${CMDDHCPCD}
# Check for relevant process ($COMMAND)
pgrep -f -x "${COMMAND}" > /dev/null 2>&1 || ${COMMAND}
# Check for sshd
pgrep -f -x "/usr/sbin/sshd" > /dev/null 2>&1 || ${CMDSSHD}
#
Based on: http://www.brandonhutchinson.com/ssh_tunnelling.html
[some links]
X11 forwarding over SSH
ssh tunneling, reverse ssh tunneling
Port forwarding, tunneling, X forwarding, German
SSH general German