Skip to content

SSH Tunnel: Port Forwarding ​

Parameters:

  • -N: Do not execute a remote command.
  • -L [bind_address:]port:host:hostport

Example: Forward server's local postgresql ​

SSH 本地轉發:local 經由 tunnel 連到伺服器上的 pgsql

bash
ssh -N -L 127.0.0.1:15432:localhost:5432 user@server.com

Then localhost:15432 provide the postgresql service

Example: ssh to target server through tunnel server ​

經由 tunnel server 連到 target server 的 SSH 示意圖

bash
ssh -N -L 19999:target.com:22 user@tunnel.com

Then link to localhost:19999

Reverse SSH Tunnel ​

Reverse SSH Tunnel:target server 反向連回 local

  1. First execute this from target server
bash
ssh -R 19999:localhost:22 source@123.456.789.000
  1. Then execute this from source
bash
ssh -R 19999:localhost:22 source@123.456.789.000

Changelog

Just observe 👀