netscrew.dev/commands/tunnel
Command

n tunnel

SSH port forwarding made easy (-L / -R / -D), explained as it runs

Short forms:forward · port-forward · proxy

Usage — n tunnel

═══════════════════════════════════════════════════════════════════════════════
  Netscrew ("n") — tunnel (forward, port-forward, proxy) — SSH port forwarding, explained as it runs
═══════════════════════════════════════════════════════════════════════════════

USAGE:
  n tunnel <host> <lport>[:rhost:rport] local forward (default): bring a remote port to localhost
  n tunnel <host> --remote <rport>[:lport] remote forward: expose your port on the host
  n tunnel <host> --socks [port]       SOCKS proxy through the host

OPTIONS:
  --bg                             run in the background
  --print                          show the ssh command, don't run

Target: . = this machine · <host> = remote
Deeper: n tunnel -h = the concept/theory behind this command

The concept behind it — n tunnel -h

═══════════════════════════════════════════════════════════════════════════════
  Netscrew ("n") — SSH Tunnels / Port Forwarding
═══════════════════════════════════════════════════════════════════════════════

LOCAL FORWARD (default) — bring a remote service to your machine:
  n tunnel <host> <LPORT>[:RHOST:RPORT]
  n tunnel hp2 5901                localhost:5901 → hp2's localhost:5901 (the VNC case)
  n tunnel hp2 8080:80             localhost:8080 → hp2's localhost:80
  n tunnel hp2 8080:nas:80         localhost:8080 → nas:80, reachable from hp2

REMOTE FORWARD — expose YOUR service on the remote:
  n tunnel <host> --remote <RPORT>[:LHOST:LPORT]
  n tunnel hp2 --remote 9000:3000  hp2:9000 → your localhost:3000

SOCKS PROXY — use the host as a proxy:
  n tunnel <host> --socks [PORT]
  n tunnel hp2 --socks 1080        SOCKS5 at localhost:1080, traffic exits via hp2

OPTIONS:
  --bg      Run in the background (else it stays open until Ctrl+C)
  --print   Show the ssh command it would run, without running it

Which side listens? LOCAL (-L) listens on YOUR machine; REMOTE (-R) listens on the far host;
SOCKS (-D) makes a proxy on your machine. The tunnel fails loudly if the port is already in use.

Back to main help: n -h