How to fix ngrok forwarding port?

Viewed 1463

I am ssh-ing onto a remote desktop. Since I have to connect over the internet, I have exposed the ssh port (22) on the remote side using ngrok, and everything is working great. I connect to the desktop using the command

ssh username@2.tcp.ngrok.io -p portno

where I get the portno from the remote side, when I start the ngrok service from the line that says Forwarding tcp://2.tcp.ngrok.io:portno -> localhost:22

However, everytime I start a new ngrok session on the remote side, a new portno is generated. Now, unless I have a secondary connection open (typically using teamviewer), I would not be able to know what that port number is. How can I start the ngrok service with a fixed portno. This is because I want to have the ngrok service on startup as I would have to restart my remote desktop a couple of times and still want to connect to the desktop using ssh.

Thanks.

1 Answers

You'll need to reserve a TCP address on ngrok, which will give you a fixed address.

To associate a tunnel with a reserved TCP address, you should include the remote-addr option in your ngrok config when starting the tunnel.

An example from the docs: ngrok tcp --region=us --remote-addr 1.tcp.ngrok.io:20301 22

Related