Pcornel
Browse topics
Options
Recent
Favorites
Linux · Technical reference

SSH Tunneling

Direct answer

SSH tunnelling forwards TCP ports through an SSH connection: local (-L) exposes a remote service on a local port, remote (-R) exposes a local service on the server, and dynamic (-D) creates a SOCKS proxy. ProxyJump (-J) connects through a bastion.

When to use this

Use it to reach services behind a firewall securely or through a jump host.

First 30 seconds

1. Local forward: ssh -L 8080:internal:80 user@bastion -N.

2. ss -ltn | grep 8080 — listening locally?

3. Server allows it: sshd -T | grep -i allowtcpforwarding.

4. Test: curl -I http://localhost:8080.

5. Bastion: ssh -J user@bastion user@target.

Operational verification

SSH session → forwarding requested → server permits → local or remote port listens → traffic carried through the encrypted channel

Evidence · next step

For SSH → SSH Tunneling, continue with the first unproven Topic check: Classify the forward as local, remote or dynamic and draw listener → SSH server → destination path. If that boundary is healthy, advance to the adjacent check: Verify bind address/port and forwarding policy on the side that owns the listener. Preserve the same host/time/identity scope and rerun the original workload before accepting recovery.

Continue only after interpreting the current observation.
Context & applicabilityCommon mistakes · platform/version boundaries
Platform / version applicability
linux
applies
Structured applicability is explicit Topic metadata; it does not infer compatibility beyond the stored rows.
At a glance

Operational reference

Fast context before you go deeper.

Platformlinux
Scope / prerequisiteUse it to reach services behind a firewall securely or through a jump host.
What next?3 suggested next steps
Evidence1
On this pageJump to a specific section
Operational workflow

Verification & Troubleshooting

Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.

5 steps Observe → verify → isolate → change minimally → repeat the original test.
ObservedRecord what the original test actually shows

Capture the concrete output, symptom, packet, log or counter before changing anything.

Step 1 Operational evidence path Verify boundary

forward specification → bind/listener → SSH transport/auth → forwarding policy/channel open → destination resolution/connect → application protocol → original workload

Healthy evidence: the intended bind exists, sshd permits the forward, the correct side resolves/connects to the destination and the original application succeeds through the tunnel.

Step 2 Verification and output interpretation Verify boundary

Existing fast checks for this Topic. - Classify the forward as local, remote or dynamic and draw listener → SSH server → destination path.

  • Verify bind address/port and forwarding policy on the side that owns the listener.
  • Test destination reachability from the side that actually opens the forwarded connection.
  • Validate the original tunneled application end-to-end, including DNS/TLS/application identity where relevant.

Verification chain. forward specification → bind/listener → SSH transport/auth → forwarding policy/channel open → destination resolution/connect → application protocol → original workload

Step 3 Commands Verify boundary
ssh -L 8443:internal:443 user@jump
ssh -R 9000:localhost:9000 user@host
ssh -D 1080 user@host
Step 4 Failure modes and next checks Narrow the fault

Suspicious evidence: forward is bound only to loopback when remote access is expected, server policy rejects forwarding, destination is tested from the wrong host or tunnel establishment is mistaken for application success.

Step 5 Common mistakes Narrow the fault
  • Leaving tunnels open with GatewayPorts exposing services.
Evidence references

Evidence · 1 on this Topic

Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.

observation · 1
Key points

The server must allow forwarding (AllowTcpForwarding). Remote forwards bind to localhost unless GatewayPorts allows otherwise. Prefer ProxyJump over agent forwarding.

Key checks
  • ssh -v user@host — client-side connection and authentication steps
  • journalctl -u ssh -u sshd -e — server log
  • sshd -T — effective server settings
  • ss -ltnp | grep :22 — sshd listening
ReferenceWhat it is1 section · depth on demand

Core model

Describe the tunnel as listener side → SSH channel → connect side. For -L, -R and -D, record which host performs DNS resolution and destination connection, what address the listener binds, and whether GatewayPorts/AllowTcpForwarding/PermitOpen or network/firewall policy constrains the path.

ReferenceImportant terms & boundaries5 sections · depth on demand

What this shows and what it does not

A working SSH transport or listening forward shows only part of the tunnel, but it does not show destination reachability, correct resolution side, application identity or service-level success.

In depth

SSH tunnelling: local, remote and dynamic forwarding

SSH can carry other TCP connections through its encrypted channel. The ssh(1) manual page describes three kinds of forwarding:

  • Local (-L): listens on the client and connects, through the server, to a destination on the server's side.
  • Remote (-R): listens on the server and connects back to a destination on the client's side.
  • Dynamic (-D): runs a SOCKS4/5 proxy on the client, and each request is forwarded to the destination the application asks for.

-N (no command) and -f (background) are useful when the connection only carries forwards. -W connects stdin and stdout straight to a host and port, which is how ProxyJump works internally.

Which forward for which job

NeedCommand
Reach a database behind a bastion from your laptopssh -N -L 15432:db1.internal:5432 bastion
Let a server reach a service on your machinessh -N -R 8080:localhost:3000 srv1
Browse an internal web UI through a jump hostssh -N -D 1080 bastion, then use SOCKS proxy localhost:1080
Hop through a bastion to another SSH serverssh -J bastion srv1

Server-side controls (sshd_config(5))

SettingEffect
AllowTcpForwardingyes (default), no, local, remote
GatewayPortsno (default): remote forwards bind to loopback only
PermitOpenLimit the destinations local forwards may reach
permitopen / permitlisten in authorized_keysThe same limits per key
admin$ ssh -f -N -L 15432:db1.internal:5432 bastion
admin$ ss -tlnp | grep 15432
LISTEN 0 128 127.0.0.1:15432 0.0.0.0:* users:(("ssh",pid=4122,fd=5))
admin$ psql -h 127.0.0.1 -p 15432 -U app appdb
admin$ ssh -N -D 127.0.0.1:1080 bastion &
admin$ curl --socks5-hostname 127.0.0.1:1080 https://grafana.internal/api/health
admin$ ssh -O check bastion
Master running (pid=4100)

Tunnel bound to loopback

The local forward listens on 127.0.0.1 only, so other machines on the network can't use the tunnel. Bind it to another address only deliberately, for example -L 0.0.0.0:15432:....

SOCKS and DNS

--socks5-hostname makes the far side resolve the name, which matters for internal names your laptop can't resolve itself. If a forward is refused, the server's AllowTcpForwarding or a key restriction is the usual reason. The client's -v output shows "administratively prohibited".

Documented example, not captured output.

Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.

How it works at runtime

SSH Tunneling is part of SSH → SSH Tunneling. SSH tunneling forwards TCP endpoints through SSH channels using local, remote or dynamic forwarding; success depends on bind/listen scope, name-resolution side, sshd forwarding policy, destination reachability from the relevant endpoint and the tunneled application protocol.

Topic-specific state model. SSH tunneling forwards TCP endpoints through SSH channels using local, remote or dynamic forwarding; success depends on bind/listen scope, name-resolution side, sshd forwarding policy, destination reachability from the relevant endpoint and the tunneled application protocol.

Interpretation rule. - SSH session established ≠ requested port forward was accepted.

  • Local listening socket exists ≠ remote destination connection succeeds.
  • Tunnel TCP connect succeeds ≠ application protocol/TLS/authentication succeeds.
  • localhost ≠ same machine from both sides of an SSH tunnel.

Quick reference

SSH tunnelling:

TypeCommandUse
Local forwardssh -L 5433:db01:5432 bastionReach a remote service via localhost:5433
Remote forwardssh -R 8080:localhost:80 public-hostExpose a local service on the remote side
Dynamic (SOCKS)ssh -D 1080 bastionBrowser/tools via SOCKS proxy
Jump hostssh -J bastion targetMulti-hop SSH
ssh -fNL 5433:db01.internal:5432 bastion      # background, no shell
ssh -o ExitOnForwardFailure=yes -NR 2222:localhost:22 relay

Servers can restrict tunnels with AllowTcpForwarding, PermitOpen, GatewayPorts. Persistent tunnels belong in systemd units or autossh.

Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.

Limits and how it fails

Primary failure point. A working SSH transport or listening forward shows only part of the tunnel, but it does not show destination reachability, correct resolution side, application identity or service-level success.

ReferenceConfiguration & state1 section · depth on demand

Configuration, persistence and lifecycle

Distribution/platform context. SSH Tunneling owns OpenSSH local/remote/dynamic forwarding semantics. Linux Networking/Firewall own underlying packet paths and filtering; application protocol/TLS behavior belongs to its relevant domain.

Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Technical verification history

Verification history & basis

When and against what this Topic was checked. Later text edits do not count as a new check.

2026-09-14 · vendor doclinux current

Authoritative/upstream documentation reviewed for bounded claims in SSH → SSH Tunneling. Documentation verification only; this is not observed lab or production Evidence.

Basis: https://www.openssh.com/manual.html · confidence 94%
Technical changelog & impact

What changed and what may be affected

Recent technical edits are separated from ordinary page timestamps. Relationship impact is advisory: it identifies nearby canonical references to review, not automatic breakage.

Related reference impactReview these references after material technical changes when their shared boundary is affected.
Terminology layer

Terms & aliases

Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.

Aliases that resolve here
ssh tunnelingssh port forwardingssh -L -R -Ddynamic socks ssh
Embedded reference data

Quick lookup tables

SSH Tunneling operational reference

Topic-specific lookup boundaries, proof limits and next-step Evidence for SSH Tunneling.

Lookup boundaryTopic-specific referenceOperational use
Scope / effective stateSSH tunneling forwards TCP endpoints through SSH channels using local, remote or dynamic forwarding; success depends on bind/listen scope, name-resolution side, sshd forwarding policy, destination reachability from the relevant endpoint and the tunneled application protocol.Establish exactly what this Topic owns before crossing into another subsystem.
Fast verificationPin exact client/server + attempt time → resolve destination/TCP path → inspect effective client config → identify OpenSSH versions → verify KEX + host-key trust → trace offered/accepted authentication → inspect effective sshd policy for user/source → verify session/subsystem/forward → verify remote process/filesystem/service → repeat original workload.Use the shortest evidence path first; a fast check is a boundary test, not blanket proof.
Verification chainforward specification → bind/listener → SSH transport/auth → forwarding policy/channel open → destination resolution/connect → application protocol → original workloadTrace requested/configured state through effective state to the observed workload result.
Failure boundaryA working SSH transport or listening forward proves only part of the tunnel; it does not prove destination reachability, correct resolution side, application identity or service-level success.Stop broad troubleshooting at the first boundary that is not supported by evidence.
Positive evidenceCorrelated Linux SSH evidence can establish this proof path: forward specification → bind/listener → SSH transport/auth → forwarding policy/channel open → destination resolution/connect → application protocol → original workloadUse this observation only for the specific claim it actually supports.
Evidence limitIt does not independently prove behavior outside the captured transport, trust, authentication, policy, session, filesystem or workload scope. A working SSH transport or listening forward proves only part of the tunnel; it does not prove destination reachability, correct resolution side, application identity or service-level success.Do not promote a local success signal into end-to-end or adjacent-dependency proof.
Next troubleshooting checkContinue from the first unproven boundary: correlate client and server evidence for the same attempt, inspect effective client/server configuration and identity/trust/authentication state, then test the exact requested session, transfer or forward before changing additional layers.Continue to the next unresolved boundary while preserving the original test condition.

SSH Tunneling · operational reference

Compact Linux state, persistence, verification and boundary reference for fast lookup.

Reference boundarySSH Tunneling
Topic pathSSH → SSH Tunneling
Runtime stateSSH tunneling forwards TCP endpoints through SSH channels using local, remote or dynamic forwarding; success depends on bind/listen scope, name-resolution side, sshd forwarding policy, destination reachability from the relevant endpoint and the tunneled application protocol.
Fast checks- Classify the forward as local, remote or dynamic and draw listener → SSH server → destination path. - Verify bind address/port and forwarding policy on the side that owns the listener. - Test destination reachability from the side that actually opens the forwarded connection. - Validate the original tunneled application end-to-end, including DNS/TLS/application identity where relevant.
Verification chainforward specification → bind/listener → SSH transport/auth → forwarding policy/channel open → destination resolution/connect → application protocol → original workload Boundary chain: local authoritative state → adjacent dependency → effective/programmed state → original workload/request → return/regression → explicit Evidence boundary. Boundary chain: local authoritative state → adjacent dependency → effective/programmed state → original workload/request → return path or regression → explicit Evidence boundary.
Failure boundaryA working SSH transport or listening forward proves only part of the tunnel; it does not prove destination reachability, correct resolution side, application identity or service-level success. Boundary chain: process/context → userspace configuration → kernel subsystem/resource → device/network/filesystem dependency → effective state → original workload.
Persistence ruleProve which configuration source owns the state, then prove that the running consumer loaded or generated the intended state.
Confirmation

Confirm action

Continue?