SSH Port Forwarding or SSH Tunnel

Local and Remote forwarding connects ports on two machines over SSH connection (tunnel).

Local Forwarding

Local forwarding -L creates a listener on the local machine (current shell) and forwards traffic to the remote host.

ssh -L 8001:localhost:80 remote.example.com
Listen on LOCAL port 8001 forward to port 80 on remote.example.com.

Remote Forwarding

Remote forwarding -R creates a listener on the remote machine (requested shell) and forwards traffic to the local host.

ssh -R 8004:localhost:8003 remote.example.com
Listen on REMOTE (remote.example.com) port 8004 forward to port 8003 on localhost.