Skip to content
SSH11 min read14.08.2026

What Is an SSH Tunnel? Local, Remote and Dynamic Port Forwarding

SSH port forwarding carries selected TCP connections through an encrypted SSH channel. Local, remote and dynamic forwarding use that channel in different directions.

SSH tunnelLocal forwardingRemote forwardingSOCKS proxy
SSH terminal and tunnel session in Varkuna Connect

What is SSH port forwarding?

Port forwarding listens on one side and carries incoming TCP connections through the SSH session to another host and port. SSH protects the transport, but the authorization and security of the destination application still matter.

It can provide controlled access to a database or management panel that is not public, reach an internal service temporarily or create a SOCKS proxy for selected applications.

Local, remote and dynamic forwarding compared

TypeListening sideTraffic destinationOpenSSH option
LocalClientHost and port reachable from the server side-L
RemoteSSH serverHost and port reachable from the client side-R
DynamicClientChosen by each application SOCKS request-D

How does local port forwarding work?

Local forwarding opens a port on the client. Connections to it travel to the SSH server, which then connects to the specified destination host and port.

In this example, a browser or tool connects to localhost:8080. The SSH server reaches a web service available to it at 127.0.0.1:80.

Forward local port 8080 to a remote web service
ssh -N -L 127.0.0.1:8080:127.0.0.1:80 user@ssh-server

How does remote port forwarding work?

Remote forwarding creates a listening port on the SSH server and carries connections back to a destination reachable from the client. It can expose a temporary development service to a controlled remote system.

The remote listening address and outside accessibility depend on the server GatewayPorts policy. Binding broadly can unintentionally expose a local service to the internet.

Forward server port 9000 to local port 3000
ssh -N -R 127.0.0.1:9000:127.0.0.1:3000 user@ssh-server

Dynamic forwarding and a SOCKS proxy

Dynamic forwarding creates a SOCKS proxy on the client. A SOCKS-aware application chooses the destination host and port for each connection, and the SSH server makes those outgoing connections.

This is not a full VPN and only appropriately configured application traffic uses it. Where DNS is resolved depends on the application and proxy settings.

Create a local-only SOCKS proxy
ssh -N -D 127.0.0.1:1080 user@ssh-server

SSH tunnel security checklist

Bind to loopback

Keep the listener on 127.0.0.1 unless deliberate sharing is required.

Limit the destination

Open a tunnel only to the required service and port.

Apply server policy

Use controls such as AllowTcpForwarding, PermitOpen and GatewayPorts to restrict accounts.

Keep application authentication

A tunnel does not replace the password or access policy of the destination database or panel.

Close temporary tunnels

End the SSH session and listener when the work is complete.

Check the bind address

Using 0.0.0.0 or * can make a port reachable by other devices. Do so only deliberately and with matching firewall rules.

Continue

Put the guide into practice.

Review the related Varkuna product or open its detailed user guide.