0

There is an Ubuntu 16.04 server running a service/daemon that listens only to 127.0.0.1. A second Ubuntu 16.04 server needs to query this service/daemon found only on the first server.

Is there a way to do this? Will an SSH tunnel work?

Nyxynyx
  • 1,449
  • 10
  • 37
  • 47
  • It would be prudent to specify what service you have in mind and what you're trying to accomplish, as quite a few services have methods of communicating with resources that you may not be taking into account. That said, the `ssh -L port:host:remoteport remoteuser@remotehost` answer from @ivanivan will work in nearly every scenario. Keep in mind that SSH can be a bit slow if you're intending to push a lot of data through this tunnel. – Spooler Jul 04 '17 at 02:28

1 Answers1

0

Yes, a ssh tunnel will do this for you.

Assume remote service is listening on localhost:2345 and you want to be able to access it at your localhost:4321, and your username on the remote machine is remoteuser and the remote machine's hostname is remotehost

ssh -L4321:localhost:2345 remoteuser@remotehost

This says "connect as remoteuser to remotehost via ssh, and tunnel traffic from my port 4321 on localhost (no ip specified on local side) to port 2345 on whatever remotehost resolves as localhost (localhost is specified) "

Another example, forwarding through remotehost to some website on port 80 -

ssh -L3456:www.example.com:80 remoteuser@remotehost

This is "tunnel traffic from port 3456 on my localhost to port 80 on whatever remotehost resolves as www.example.com". You could then point a browser to http://localhost:3456 and see the content of www.example.com

HTH

ivanivan
  • 1,448
  • 6
  • 6