4

local -> gateway ( only ssh port enabled ) -> remote

I can ssh to gateway then to remote, no problem.

Can I establish a ssh tunnel between local and remote via gataway? I 'd like to access local:9980, which will forward to remote:9980 via gateway. I'm worried about tunnel using port 22 on gateway will be a trouble for others' ssh use.

Thanks

valpa
  • 319
  • 9
  • 15

2 Answers2

2

It depends.

Is your gateway an actual gateway/router? or is it a gateway/server?

If it's a gateway/router, then you can use port forwarding or NAT. I'd give you instructions, but that depends on the OS/manufacturer. Essentially, you have the gateway/router listen on port 22, and you forward to destination:9980, so long as destination is listening on 9980, this should work automatically.

If it's a gateway/server (assuming linux-based), then you can use an IPTABLES NAT rule, or a reverse ssh tunnel (which should be initialized from the destination end).

EXAMPLE IPTABLES NAT:

iptables -t nat -I PREROUTING --src 0/0 -p tcp --dport 22 -j REDIRECT --to-destination $destination_ip --to-ports 9980

This would take any incoming traffic from the any address for port 22 and forward it to your $destination_ip on port 9980 automatically.

EXAMPLE REVERSE SSH TUNNEL:

destination# ssh -R 9980:localhost:22 user@gateway

This sets up a listener on the gateway that maps anything going to gateway:9980 to point to destination:22

For you, if you connect to your gateway like normal:

local# ssh user@gateway

You would then be able manually connect to the destination from your gateway as needed, instead of automatically

gateway# ssh user@localhost:9980
CIA
  • 1,604
  • 2
  • 13
  • 32
0

If I understood correctly, you can do a SSH tunnel to remote through your gateway. To do that:

ssh -L 9980:remote:9980 gateway

will bind your local 9980 to the remote 9980 port using ssh tunnel through gateway.

aif
  • 381
  • 1
  • 8