Monday, October 27, 2014

Port tunneling on Mac with SSH


Imagine you need to connect from your browser to another computer which has access to an specific service, por example a private control panel. How to do it using SSH on a mac?

Well, lets describe the problem:


I want to access to the Service 192.168.300.12:11801 which can be accesed only from the Server SSH 192.168.200.1. To increase the complexity of the problem, we should use HTTPS to access the Service, ie, the direct URL from Server SSH looks like: https://192.168.300.12:11801/index.html

Well, first we open a terminal and execute the command:

$ sudo ssh -L 443:192.168.300.12:11801 -p 22 -l username -N 192.168.200.1

The command opens a tunnel between our machine on port 443 to machine 192.168.300.12 using the port 11801 through 192.168.200.1. Just what we want. "-p  20" is only the SSH port, "-l username" is clear and "-N" indicates that we will not execute remove commands.

Now, we can simply set up a SOCKS-Proxy going to Mac > Installation > Network > More Options. Select the tab "Proxies" and enable the protocol SOCKS-Proxy. You need only to insert:
  • SOCKS-Proxy-Server: 127.0.0.1
  • Port: 443
Now, open your favorite browser and write the URL:
https://localhost/index.html
to access to the Service.

Hope help



No comments:

Post a Comment