
If the proxy is configured on the browser, this request is encapsulated with the SOCKS header where the destination port and IP of your request become the port and IP of the proxy server you configured on your browser. Many applications like browsers support a SOCKS proxy where you configure the IP and port of the proxy server. Unlike an HTTP proxy, it’s protocol-independent. You must have used HTTP proxy, where your browser connects to a proxy server and that proxy server makes the HTTP request on your behalf and forwards you the response it gets.Īside from traffic forwarding, proxy servers provide security by hiding the actual IP address of a client.Ī SOCKS proxy routes any type of traffic generated by any protocol or program to the actual server on the behalf of the client. Simply, a proxy is a service/server that makes a request on your behalf. You can create a reverse SSH tunnel to a publicly accessible server for “port 80” (or any custom port) and let the end-users (clients or your team members in this example) browse the website using the IP address of this public server on “port 80” (or any custom port that you define in the command) to access the website.īefore you consider implementing a reverse SSH tunnel, the parameter “GatewayPorts” should be set to “yes” in your remotehost’s SSH server configuration file “/etc/ssh/sshd_config.”ĭynamic SSH Tunnel (Dynamic Port Forwarding)īefore we learn about what a dynamic SSH tunnel is, let’s discuss what a proxy and a Socket Secure (SOCKS) proxy are. Often, you do not have a public IP for your local machine (although you can create access to your local machine by configuring NAT rules, it doesn’t always work). Now let’s imagine a scenario where a developer is developing an application/website on its local machine and wants to let his/her client/team access that locally hosted website/app for a demo. Ssh -R 1234:nearhost_IP:5678 this example, all the data from “port 1234” of the remote machine will be forwarded by your local machine to “port 5678” of the nearhost machine. Ssh -R 1234:localhost:5678 this command, “-R” refers to the remote side listening and listens to the “port 1234” on the remote machine and forwards all the data from “port 1234” of the remote machine to the “port 5678” on your local machine.Īnother implementation of remote port forwarding is the following: Reverse SSH tunnel listens to the port on the remote machine and forwards all the data coming on that port to the specified port on your local machine via SSH. Reverse SSH Tunnel (Remote Port Forwarding) One other use case would be to access the database on the server securely without exposing the database ports. This is one of many use cases of local port forwarding. Ssh -L 8080::80 can access the restricted website with the URL “ in your local machine browser. In such a case, you can create an SSH tunnel to the machine inside your office network and access the restricted website: Let’s take a scenario where your office network only allows SSH connections to the inside resources/machines, blocks all other traffic from outside networks, and you want to access the website restricted to your office network securely. Local port forwarding is very useful while accessing the services hosted on a private network.


Ssh -L 1234:farawayhost_IP:5678 this kind of implementation, all the data coming on “port 1234” of your machine will be forwarded to the “port 5678” on the farawayhost machine by remotehost machine (given that farawayhost allows the remote host to send data for port 5678). In the above example, “localhost” refers to the localhost IP of a remote machine.Īnother implementation of local port forwarding is the following: With the above command, all the data coming on “port 1234” of your machine will be encapsulated as SSH data and forwarded to “port 5678” of the remotehost. Ssh -L 1234:localhost:5678 this command, “-L” refers to the local side listening. Use the following command to set up the SSH tunnel between your machine and remote machine (given that you have SSH access to the remote machine): When you create an SSH tunnel with local port forwarding, the SSH tunnel forwards the data from the port on the client machine to the port on the server machine. Dynamic SSH Tunnel (dynamic port forwarding).Reverse SSH Tunnel (remote port forwarding).

SSH tunneling can be implemented in three ways: SSH comes with authentication and encryption built-in, meaning we can use SSH tunnels to transfer the data from unsecured services between two hosts.

SSH tunneling is the feature offered by the OpenSSH tool, which lets us create a tunnel between two hosts so that data from some other protocol is encapsulated in the SSH header and transferred as SSH data between those two hosts.
