Course contentsShow
← Security
Lesson 500 of 3,05211. Network Security - VPNs and TunnelingFree lesson

Local Port Forwarding (-L)

Creating local port forwards to access remote services through SSH, syntax, and practical applications.

Local Port Forwarding (-L)

What you'll learn: How to use SSH's local port forwarding to securely access remote services through an encrypted tunnel.

What Is Local Port Forwarding?

Local port forwarding creates a secure tunnel from your machine to a remote service through an SSH server. Think of it as building a private, encrypted bridge: you knock on a door on your own computer (a local port), and SSH secretly carries your traffic through its secure tunnel to reach a service on the remote side.

This is incredibly useful when a service isn't directly accessible from your location—perhaps it's behind a firewall, on an internal network, or you want to encrypt traffic that would otherwise be unencrypted.

The Syntax

The SSH flag -L establishes local forwarding:

ssh -L [local_port]:[destination_host]:[destination_port] [ssh_user]@[ssh_server]

Example:

ssh -L 8080:database.internal:3306 user@jumpserver.example.com

This means: "Open port 8080 on my local machine. When I connect to localhost:8080, secretly forward that traffic through the SSH connection to database.internal:3306."

Practical Applications

  • Access internal databases: Connect to a database server that only accepts connections from inside the corporate network
  • Bypass restrictive firewalls: Reach services blocked by network policies
  • Encrypt unencrypted protocols: Wrap insecure protocols like HTTP or VNC in SSH encryption
  • Testing and development: Access staging servers or development environments remotely

Once the tunnel is active, you simply point your application to localhost:8080 (or whatever local port you chose), and SSH handles the rest transparently.

Key Takeaway: Local port forwarding (-L) lets you securely access remote services by creating an encrypted SSH tunnel from a port on your local machine to a destination through an SSH server.