Score:0

ssh to a server behind NAT without VPS being the bridge during communication

lb flag

I currently can ssh through my localhost behind NAT using VPS as reverse SSH server.

ssh -f -N -R 1234:localhost:22 user@[vps_ip]

And I can do the following to connect to my localhost SSH server from other place:

ssh my_user@[vps_ip] -p 1234

My problem is that this connection will have high latency because the VPS is in the US (only free in the US) and I'm in East Asia. Is there a possible way that can start a script automatically after connection, and do some tricky stuff (to punch a TCP hole maybe) to set a SSH communication directly from anywhere to my localhost to reduce latency? I want it to make the client side only have to do ssh my_user@[vps_ip] -p 1234 to connect to my localhost.

A.B avatar
cl flag
A.B
I'm not sure the question fits here, but anyway, to punch a hole, you need at least one side of the two clients to have adequate network properties, if not both. For example if the two clients are behind CG-NAT, no punching (whatever help is available from the server to try and achieve it).
TWTom avatar
lb flag
Thanks for the answer, @A.B Do you mean if both the client and the localhost server is behind NAT, direct communication is not possible if I don't want the client side has any additional configurations?
A.B avatar
cl flag
A.B
I won't continue beyond this comment: I wrote "[CG-NAT](https://en.wikipedia.org/wiki/Carrier-grade_NAT)", not just NAT. There are different types of [NAT](https://en.wikipedia.org/wiki/Network_address_translation#Methods_of_translation). Those with interesting network properties can get to punch holes, with the help of a 3rd party. An example 3rd party help is a [STUN server](https://en.wikipedia.org/wiki/STUN). SSH won't help much in this regard.
Jaromanda X avatar
ru flag
if you're afflicted by CG-NAT you can use something like tailscale (or the self hosted version headscale) - there are many other variations that essentially use wireguard under the hood to provide secure and fast end-to-end connections - you can install them on your VPS, but don't worry, the "server" component is just there to establish direct connections
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.