Intermediate LevelLinux Commands & SysAdmin
How do Local (-L), Remote (-R), and Dynamic (-D) SSH Tunnels work?
❓ Interview Prompt: Explain SSH port forwarding modes: Local forwarding (-L), Remote forwarding (-R), and Dynamic SOCKS proxy (-D).
SSH Tunnels encapsulate network traffic inside encrypted SSH connections to bypass firewalls or access internal services safely:
1
Local Forwarding ('-L 8080:localhost:5432'): Forwards a local port to a remote destination service (e.g. connecting local GUI tool to remote database).
2
Remote Forwarding ('-R 9000:localhost:3000'): Exposes a local port to a remote server.
3
Dynamic Forwarding ('-D 1080'): Creates a SOCKS5 proxy server forwarding arbitrary browser traffic through the SSH host.
Code Implementation Example
bash
# Local Forwarding: Connect local port 5432 to remote PostgreSQL DB
ssh -L 5432:localhost:5432 deploy@db-server.internal
# Remote Forwarding: Expose local port 3000 to remote server port 9000
ssh -R 9000:localhost:3000 user@remote-public-server.com
# Dynamic SOCKS5 Proxy
ssh -D 1080 user@remote-jump-host💡Executing Local, Remote, and Dynamic SSH port forwarding tunnels.
🎯 Interview Key Takeaway
Use Local forwarding (-L) to securely access internal remote databases from your local workstation.
#SSH Tunneling#Port Forwarding#SOCKS Proxy#Intermediate
Back to all Linux Commands & SysAdmin Questions→