Port forwarding using SSH tunneling

April 22, 2019

Posted in:

When you need to expose a service to the internet or an outside network but you don't have control over your local NAT or port-forwarding, you can use SSH to create a reverse tunnel.

For this you will need a VPS instance to which you have root access and VPS is securely connected to the internet. You will need to enable the following in `/etc/ssh/sshd_config`.

AllowTcpForwarding yes
GatewayPorts yes

From your local machine, you can now use the following command to create port forwarding using SSH tunnel.

ssh -R 8080:localhost:8000 -N user@remote_server

Service running on localhost:8000 would now be accessible through remote_server:8080


Return to blog