ssh/port forwarding - listening by multiple clients

Kevin Martin ktmdms at gmail.com
Mon Sep 16 13:19:43 UTC 2013


On 09/16/13 07:55, bruce wrote:
> hi..
> 
> Trying to see if ssh/port forwarding can be used to solve a prob.
> 
> I want to have multiple clients connected to a single master server
> 
> The masterServer/app is providing data on port X
> 
> The clientNodes/apps should then listen on port X
> 
> ssh allows for port forwarding, but I can't figure out how to
> accomplish this using ssh/port forwarding.
> 
> I've tried using :
> ssh   -L 8000:localhost:8000  bob at foo.com -p abc
>  as foo.com:abc is the vm ip/port that's the server app
> 
> I then did a test using nc
> 
> where on the serverside, i did a
> 
> nc -l 8000, and got an err msg indicating the port was already in use
> 
> port 8000 is the port the server app sends data on, and is the port
> I'd like to listen on on the clientnodes/apps..
> 
> pointers/comments are more than welcome!
> 
> thanks
> 
Bruce,

So what I'm getting from this is:

The server has an application listening on port 8000 (so that put's that port in use on the server side)

The clients, via the ssh command, bind port 8000 on their side and any traffic to that port on their side from that machine is
forwarded to port 8000 on the server foo.com over port "abc" (the port that ssh is using to connect to the remote server).

All of which has me a tad confused.

In a typical client/server setup, your clients will access the server on a given port.  The server won't, necessarily, care what
port the clients are talking to it from as once the client makes the connection you'll have your 3-way handshake done and a socket
setup.  IF the server sometimes initiates the contact to the client THEN the client will need to be listening on a particular port.
 That being said, if you need to forward packets back and forth over ssh, I don't think that the server app and the client app can
be listening on the same port UNLESS you specifically bind the server port 8000 to a particular interface/address AND the server has
multiple nics/addresses which can be used (the same holding true for the client).  I THINK this scenario would work if you have it
available:

Ex: server has addresses 1.2.3.3 and 1.2.3.4
    Server app runs on port 8000 but ONLY on address 1.2.3.3
    From the server you "ssh -L 1.2.3.4:8000:localhost:8000 bob at 10.1.2.3 -p 2222"

    client has addresses 10.1.2.3 and 10.1.2.4
    Client app runs on port 8000 but ONLY on address 10.1.2.3
    From the server you "ssh -L 10.1.2.4:8000:localhost:8000 bob at 1.2.3.3 -p 2222"

    When the server needs to talk to the client on port 8000 it would need to talk to it's own address of 1.2.3.4 which would
forward the traffic over the ssh connection to the remote machine 10.1.2.3:8000.  When the client needs to talk to the server on
port 8000 it would have to talk to it's own address of 10.1.2.4:8000 which would then forward the traffic over an ssh tunnel to
1.2.3.3:8000.  This is all much easier if the client and server don't share a port assignment (assuming that both the server and
client apps need to INITIATE conversations...if only one side is always the INITIATOR of the conversation, you would still want to
have the server and client bound to separate ports, if only because there may come a day when you are running the client app on the
same machine as the server app.

Kevin


More information about the users mailing list