Thursday, October 4, 2012

Setup bi-directional port forwarding on SSH


[Home_Machine] <--> [Firewall] <--> [Internal] <--> [Web_Server]
                     Port:22         Port:22         Port:80
                                                     Port:443


Forward remote port to local host port:

ssh -R remote_port:local_host:local_port
e.g. [Internal]$ ssh -R 2222:localhost:22 [Home_Machine]

This opens a socket on [Home_Machine] and listens to 2222 port. Whenever connection made on [Home_Machine] 2222 port will be forwarded to [Internal] port 22.  It opens a ssh connection door from [Home_Machine] to [Internal].

Forward local port to remote host port:

ssh -L local_port:remote_host:remote_port
e.g. [Home_Machine]$ ssh -p 2222 \
                         -L 443:[Web_Server]:443 \
                         -L 80:[Web_Server]:80 localhost

This opens a socket on [Home_Machine] and listens to 80 and 443 port.  Any connection to [Home_Machine] on these two ports will be forwarded to [Web_Server].  
(ssh to port 2222 on localhost will be forwarded to 22 port on [Internal])

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.