Skip to content
Related Articles
Open in App
Not now

Related Articles

SSH Port Forwarding

Improve Article
Save Article
  • Difficulty Level : Easy
  • Last Updated : 31 Oct, 2019
Improve Article
Save Article

SSH Port forwarding is a method used for securing TCP/IP connections. The TCP/IP packets can be tunneled through a SSH link making the data obscure thus protecting the link from attacks. SSH Port forwarding can be also seen as a form of Virtual Private Network(VPN).

Types of Port Forwarding:
There are 2 main types of port forwarding: Local Port Forwarding, and Remote Port Forwarding. These are explained as following below.

  1. Local Port Forwarding:
    Suppose you are on a local network that restricts access to a site, let us suppose To work around this we could create a tunnel through a server that is not on our network and thus has access to The command we would use is:

    ssh -L 

    The -L flag here tells that local port forwarding is being used. So, what the above command does is it forwards the data on local port 9090 to the server which has access to through a secure SSH connection. Note here that admin is a user on the server. Now visit on your browser.

    A second scenario would be a situation in which you want to access a service on the server which is open only on localhost for security reasons. You would use the following command:

    ssh -L 9090:localhost:3306 

    Make a note here that localhost in the command is from the perspective of the server. The server is running a MySQl service on port 3306 and it allows only local connections.

  2. Remote Port Forwarding:
    The command for remote forwarding is

    ssh -R

    -R flag specifies that requests on remote server port(9090) should be forwarded to which is on the local network at port 80. Now if we make a request to the server on port 9090 you would get a reply from

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!