June 12, 2019

SSH Tunnel with Port Forwarding

How to establish a ssh tunnel from one subnet onto another.

SSH Tunnel with Port Forwarding

I want to tunnel a port from a subnet into a different subnet. My local box sits in one subnet (subnet A). I have ssh access to a node sitting in the other subnet (subnet B). I want to establish a tunnel using ssh to forward a port (Postgre std port 5432) in order to access a database in the other subnet.

The command to start forwarding a local port (2345) onto the target machine port (5432) is:

ssh -L 2345:db.b.net:5432 user@node.b.net

A website with nice pictures can be found here.