SSH
Local port forwarding
ssh -L $lport:$dhost:$dport $user@$sshserver
Remote port forwarding
ssh -R $rport:$dhost:$lport $user@$sshserver
B:1 -> A:2 <- C:3 <---> internet
NOTE: this option can be useless if you have no root access to change the
sshd_configfile in the machineA, and restart the ssh service, since you need to setGatewayPorts yesin order to let others than the ssh server machine could access todhost. However, there's a workaround: Remote Port Forwarding fromB:port1to one remote serverA:port2and then a Local Port Forwarding to the sameA:port2machine using a local machineC:port3to which you have more access. You can know access to the service inB:port1usingC:port3.
Dynamic port forwarding
ssh -D $lport $user@$server