C.W.K.
Stream
Lesson 10 of 12 · published

LocalForward — Reach Remote Services

~15 min · port-forwarding, localforward, ssh-tunnel

Level 0Pinger
0 XP0/101 lessons0/12 achievements
0/150 XP to next level150 XP to go0% complete

Bringing a remote service to your localhost

Local port forwarding creates a tunnel from a port on your local machine to a port on the remote side. The remote service feels like it's running locally. Pattern: a database, web app, or admin UI runs on the remote server but isn't exposed to the network — local forwarding gives you private access.

The mental model

Syntax: -L local-port:remote-host:remote-port. The remote-host is resolved from the SSH server's perspective, not yours. So -L 8080:localhost:80 means "forward my localhost:8080 to whatever the server calls localhost — that is, the server itself." To reach a third host through the server, swap localhost for that third host's address.

Code

Local forwarding patterns·bash
# Reach a web app on the server's localhost:80 via your localhost:8080
ssh -L 8080:localhost:80 server
# Now: open http://localhost:8080 in your browser

# Reach a third-party host through the bastion
# Local 5432 → bastion → database.internal:5432
ssh -L 5432:database.internal:5432 bastion

# Background tunnel, no shell — daemon-like
ssh -NfL 8080:localhost:80 server
# -N: no remote command  -f: background after auth
Bake into ~/.ssh/config·ssh-config
Host server-web
    HostName 192.168.1.11
    User you_username
    LocalForward 8080 localhost:80
    LocalForward 5432 localhost:5432

# Now `ssh server-web` opens both tunnels automatically
# while your shell runs

External links

Exercise

On any machine where you have a web service running (Pippa's localhost:8000 if you're on the cwkPippa repo, or a quick python3 -m http.server 8000 on a remote host), set up a LocalForward to port 8080 on your laptop. Browse to http://localhost:8080 and confirm it's reaching the remote service. Then bake it into ~/.ssh/config so it auto-opens with ssh that-host.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.