Frequently Asked Question

How to forward ports to enable access to applications?
Last Updated 7 months ago

1. Introduction

Port Forwarding allows remote computers (for example, computers on the Internet) to connect to a specific computer or service within a private local-area network (LAN). One reason might be to get access to an application that is running on the Virtual Machine. This guide will outline how to forward specific ports locally or remotely on Linux and Windows.

2. Port forwarding on Linux

Port forwarding relies on SSH. How to access a Virtual Machine with SSH?

2.1 Local port forwarding

This type of port forwarding lets you connect from your local computer to a remote server. Assuming you are behind a restrictive firewall, or blocked by an outgoing firewall from accessing an application running on port 3000 on your remote server.

To access an application running on port 3000 on the remote server on port 8080 on your local machine use

ssh -L 8080:localhost:3000 username@remote.server.com

or if the server is behind a proxy server

ssh -L 8080:remote.server.com:3000 username@proxy.server.com

Now, on your local machine, open a browser, instead of accessing the remote application using the address remote.server.com:3000, you can simply use localhost:8080

Alternatively you can setup a config file in ~/.ssh/config in the following manner:

Host remote_server
    HostName remote.server.com
    User username
    LocalForward 8080 localhost:3000

or if the server is behind a proxy server

Host proxy_server
    HostName proxy.server.com
    User username
Host remote_server
    Hostname remote.server.com
    ProxyJump proxy_server
    User username
    LocalForward 8080 localhost:3000

and run:

ssh remote_server

2.2 Remote port forwarding

This type of port forwarding lets you connect from a remote server to a local computer.
To access an application running on port 3000 on your local machine on port 8080 on the remote server use

ssh -R 8080:localhost:3000 username@remote.server.com

or if the server is behind a proxy server

ssh -R 8080:remote.server.com:3000 username@proxy.server.com

Now, on your local machine, open a browser, instead of accessing the remote application using the address remote.server.com:3000, you can simply use localhost:8080

Alternatively you can setup a config file in ~/.ssh/config in the following manner:

Host remote_server
    HostName remote.server.com
    User username
    RemoteForward 8080 localhost:3000

or if the server is behind a proxy server

Host proxy_server
    HostName proxy.server.com
    User username
Host remote_server
    Hostname remote.server.com
    ProxyJump proxy_server
    User username
    RemoteForward 8080 localhost:3000

and run:

ssh remote_server

3. Port forwarding on Windows

3.1 Local port forwarding

This type of port forwarding lets you connect from your local computer to a remote server. Assuming you are behind a restrictive firewall, or blocked by an outgoing firewall from accessing an application running on port 3000 on your remote server.
To access an application running on port 8080 on the remote server on port 80 on your local machine use MobaXterm.

Go to Tools, MobaSSHTunnel (port forwarding), New SSH tunnel

image


this will open the forwarding mask.

image


when you want to forward a port on the local machine use either localhost or 127.0.0.1
Past in all connection details you need and hit Save

image


press the key icon to add a Private Key.

image

3.2 Remote port forwarding

This type of port forwarding lets you connect from a remote server to a local computer.
To access an application running on port 3000 on your local machine on port 8080 on the remote server set MobaXterm up this way. The rest of the settings are the same as Local port forwarding.

image



Now, on your local machine, open a browser, instead of accessing the remote application using the address remote.server.com:3000, you can simply use localhost:8080

Loading ...