1

I'm trying to connect a websocket server (linux machine) and client (web browser) through an intermediary server (hosted on an AWS EC2 instance). The EC2 instance provides a public IP that the websocket server and client can reference.

My client connects to ws://<SERVER>:<PORT>, where SERVER is the address of my EC2 instance and PORT is an arbitrary port I've opened for port forwarding (e.g. 9111).

On the websocket server, I'm running the following command:

  /usr/bin/ssh -f -N -i $KEY -l ubuntu \
                 -R $PORT:127.0.0.1:9090 \
                 -L 9090:$SERVER:$PORT \
                  $SERVER

Where $KEY is a private key for EC2 and 9090 is the port my websocket server uses. I've configured my EC2 instance's ssh daemon to enable gateway ports, and port forwarding is working just fine.

The issue comes when I try to start my websocket server -- I get an Address already in use error, because apparently I can't start a websocket server on a port that I'm forwarding. Isn't this a fairly standard thing to do? What am I doing wrong?

Thanks!

Nick Sweet
  • 113
  • 1
  • 4

1 Answers1

1

Your '-L 9090' option to SSH is opening a listener on port 9090, which conflicts with your websocket server. The -R option should suffice, and the forwardd connection will be bi-directional, you don't need to set up a 'reverse route' with -L.

You may need to enable the GatewayPorts option on your EC2 SSH daemon to be allowed to set up ports using -R that accept connections from any IP, in addition to any firewall changes.

unilynx
  • 254
  • 1
  • 3