SSH port forwarding

From Luniwiki
Jump to: navigation, search

Command

ssh -t -t  <LOCALPORT>:<REMOTE_HOST>:<REMOTE_PORT> <USER>@<SSH_SERVER>
  • <LOCALPORT> TCP port on your local machine listening
  • <REMOTE_HOST>:<REMOTE_PORT> Remote machine you want to reach, traffic from your local port will be forwarded to the remote host and remote port
  • <USER>@<SSH_SERVER> Remote SSH server used to create the tunnel

Example

root@empltdsimao1:~# ssh -t -t -L 5000:192.168.1.3:80 dany@192.168.2.7
dany@192.168.2.7's password:
dany@192.168.2.7:~$

On my local machine if I open a browser http://127.0.0.1:5000, I will see the web page of the not directly reachable server 192.168.1.3 on port 80

References

Daniel Simao (talk) 10:52, 20 September 2018 (EDT)