Difference between revisions of "Connect to laptop (behind NAT) using intermediary server"

From Aram's Wiki
Jump to: navigation, search
(On the laptop)
(On the other client)
 
(8 intermediate revisions by the same user not shown)
Line 3: Line 3:
 
== Introduction ==
 
== Introduction ==
  
We'll use a combination of ssh remote and local port forwarding in order to expose the laptop's ssh port outside the NAT.
+
We'll use a combination of ssh remote and local port forwarding in order to expose the laptop's ssh port outside the NAT. The laptop must initiate the forwarding.
  
 
== On the server ==
 
== On the server ==
  
Make sure you have an account that the laptop can connect to.
+
Make sure you have an account that the laptop can connect to through ssh.
  
 
== On the laptop ==
 
== On the laptop ==
  
This will connect to the server, and set-up a remote port forward such that dialing localhost:12345 on the server will connect to localhost:22 on the laptop.
+
This will initiate a connection to the server (from the laptop), and it will set-up a remote port forward such that dialing localhost:12345 '''on the server''' will forward to localhost:22 on the laptop.
  
 
  ssh -N -R 12345:localhost:22 harieta@freedom.mgk.ro
 
  ssh -N -R 12345:localhost:22 harieta@freedom.mgk.ro
Line 17: Line 17:
 
== On the other client ==
 
== On the other client ==
  
This will connect to the server, and set-up a local port forward such that dialing localhost:1235 on the client will connect to localhost:12345 on the server. Of course, localhost:12345 on the server just forwards to localhost:22 on the laptop.
+
This will connect to the server, and then set-up a local port forward (from the ''other client'' to the server) such that dialing localhost:12345 '''on the client''' will connect to localhost:12345 '''on the server'''. Of course, localhost:12345 on the server just forwards to localhost:22 on the laptop.
  
 
  ssh -N -L 12345:localhost:12345 freedom.mgk.ro
 
  ssh -N -L 12345:localhost:12345 freedom.mgk.ro
Line 23: Line 23:
 
Then from another terminal (still on the other client) you can
 
Then from another terminal (still on the other client) you can
  
  ssh -p 12345 localhost
+
  ssh -p 12345 ubuntu@localhost
  
And should reach localhost:22 on the laptop.
+
And should reach localhost:22 '''on the laptop'''.
 +
 
 +
== References ==
 +
 
 +
* [https://man.openbsd.org/ssh.1 ssh(1)]

Latest revision as of 19:00, 29 July 2019


Introduction

We'll use a combination of ssh remote and local port forwarding in order to expose the laptop's ssh port outside the NAT. The laptop must initiate the forwarding.

On the server

Make sure you have an account that the laptop can connect to through ssh.

On the laptop

This will initiate a connection to the server (from the laptop), and it will set-up a remote port forward such that dialing localhost:12345 on the server will forward to localhost:22 on the laptop.

ssh -N -R 12345:localhost:22 harieta@freedom.mgk.ro

On the other client

This will connect to the server, and then set-up a local port forward (from the other client to the server) such that dialing localhost:12345 on the client will connect to localhost:12345 on the server. Of course, localhost:12345 on the server just forwards to localhost:22 on the laptop.

ssh -N -L 12345:localhost:12345 freedom.mgk.ro

Then from another terminal (still on the other client) you can

ssh -p 12345 ubuntu@localhost

And should reach localhost:22 on the laptop.

References