How to forward a TCP port over SSH

Encrypted cloud connection

For years SSH has prooven to be extremly useful and flexible protocol.

The forwarding option in SSH is another example for its versatility. Using it you can easily forward a local TCP port to another on the remote machine.

ssh -L [bind_address:]port:host:hostport

For example if your remote machine is running an MySQL server listening on the remote machines local:3306, you can use the SSH forwarding to access it remotely.

To connect your local port 33060 to the remote machines 3306

ssh -L 33060:localhost:3306

Another use case for example could be to forward a local port to an external target, going through the SSH connection.

This way the connection to the endpoint will bill opened from the remote server, and you’ll be accesing it through a port on your local machine.

In this example we’ll open a connection to through a remote server:

ssh -L

This way opening localhost:4443 will forward the connection, through the and to the endpoint

Of course you might find more useful applications of the nice feature and we’ll be happy to hear from you in the comments below.

Leave a Reply

Your email address will not be published. Required fields are marked *