Votes: 0Posted On: Oct 31, 2017 04:26:21
Port forwarding is the process of sending data, connections or requests of a local port to remote ports via an alternate medium. We are able to achieve this through SSH, also known as SSH port forwarding.
Under the process of SSH port forwarding, the various programs running on the local machine can connect to the remote server via the SSH connection. This is done to bypass the firewall of the remote server. For instance, SSH port forwarding can be used to access websites that are blocked by the firewall.
There are primarily three types of port forwarding. These are mentioned in detail below.
Local Port Forwarding
It is the most common type of port forwarding. In this type, the connections from one machine are forwarded through the SSH connection to the remote server. If a program or application is trying to connect to a remote server but is blocked by the firewall, it can establish connections through SSH. For instance, you can connect to a website through SSH by entering the source and destination port with website's name and host ID.
This is the command that can be used for such an instance.
ssh -L 8080:www.abc.com:80 user@remote IP address
- The "-L" option is used for Local Port Forwarding.
- 8080 is the HTTP port at the localhost.
- www.abc.com is the website you are trying to connect.
- 80 is the remote HTTP port.
Remote Port Forwarding
Remote port forwarding is a less common type of port forwarding. This is because it implies that the remote server tries to access programs of the local machine through SSH. In this type, the connections from the remote SSH server are forwarded via the SSH client, then to a local machine.
You can use the Remote Port Forwarding with the help of the following command.
ssh -R 5900:localhost:5900 user@destination IP address.
- The "-R" option is used for remote port forwarding
- 5900 is the default VNC port.
Dynamic Port Forwarding
It is rather the least used type of SSH port forwarding. In dynamic port forwarding, we make use of SOCKS proxy server. SOCKS is a little-known but widely-implemented protocol for programs to request any Internet connection through a proxy server.
With dynamic port forwarding, you can access all the ports of the remote machine. Hence, this type of port forwarding is not recommended and rarely used.
Please use the following command for dynamic port forwarding.
ssh -C -D 1080 username