Start a WS connection on a server that's being accessed by SSH port forwarding - ssh

I have an EC2 Instance(A) and a RaspberryPi(B). I want to access a HTML page in B.
Here are the steps I did:
Created a simple index.html in B that connects to a WebSocket running on 5443 also in B
Served it with SimpleHTTPServer on port 1337
Created a port forwarding. When I access A:9000 it should redirect to B:1337. Used: ssh -f -N -R 9000:127.0.0.1:1337 A
With that I'm able to access my index.html page, however it fails when trying to connect to the WebSocket server with
WebSocket connection to 'ws://localhost:5553/' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED
When I use VNC to connect to B, and access the browser in localhost:1337 I'm able to see the page AND the WebSocket connection succeeds.
I'm not sure why it fails when I try to access it through the EC2 instance. Does anyone have any clues on what might be the problem? thanks
**All ports are open in my EC2 instance

Even though I was port forwarding, localhost:5553 wasn't the raspberry pi IP, was the EC2. I created a new port forwarding from 9001 in A to 5443 in B to tunnel the Websocket connection and it worked.

Related

Reverse SSH tunneling with not localhost

I have local computer and remote server. Remote server is isolated and is only accessible with this computer. I want to connect to site from server, let it be https://example.com/site
I tried to make a tunnel via ssh -R 6761:example.com:80 remote-server. But when I am trying to use wget http://localhost:6761/site on the remote server - it doesn't work and show 404 whilst wget http://example.com/site working well on local computer.
What I am doing wrong?
You cannot tunnel HTTP that way.
The name of the server you are trying to reach will be included in the request (the Host header), but it will most likely only listen to example.com, not localhost.
You will need to set up a HTTP Proxy (Forward Proxy) on your local machine and tell your http client(s) to use that. (How depends on the client.)

How to fix ngrok forwarding port?

I am ssh-ing onto a remote desktop. Since I have to connect over the internet, I have exposed the ssh port (22) on the remote side using ngrok, and everything is working great. I connect to the desktop using the command
ssh username#2.tcp.ngrok.io -p portno
where I get the portno from the remote side, when I start the ngrok service from the line that says
Forwarding tcp://2.tcp.ngrok.io:portno -> localhost:22
However, everytime I start a new ngrok session on the remote side, a new portno is generated. Now, unless I have a secondary connection open (typically using teamviewer), I would not be able to know what that port number is.
How can I start the ngrok service with a fixed portno. This is because I want to have the ngrok service on startup as I would have to restart my remote desktop a couple of times and still want to connect to the desktop using ssh.
Thanks.
You'll need to reserve a TCP address on ngrok, which will give you a fixed address.
To associate a tunnel with a reserved TCP address, you should include the remote-addr option in your ngrok config when starting the tunnel.
An example from the docs: ngrok tcp --region=us --remote-addr 1.tcp.ngrok.io:20301 22

Forward server HTTP traffic to handle in another device via SSH Tunnel

I'm developing some webhook required direct access public domain to internal machine, thinking use SSH tunnel to forward data, or got alternative solution?
Hosting server & development machine are in same network
192.168.1.2/24 (Hosting server)
2nd machine is virtual mapping using forticlient firewall without static or dynamic IP in visible in hosting server, so is 1 way initial communication right now.
In this case possible to setup SSH tunnel forward all traffic from 192.168.1.2:80 to handle in development machine port 8080?
How to ssh syntax look like?
Thanks.
This could be done by setting up an SSH tunnel to the remote machine:
ssh -L localhost:80:localhost:8080 development-system
Every request to port 80 on the hosting-server is now forwarded to port 8080 on the development-system.
Please note, that the port 80 on the hosting-server could only be used, when you start the SSH command as root. Also note that the port 80 is only accessible from the hosting-server. To access the port 80 on the hosting-server from everywhere use the following:
ssh -L 80:localhost:8080 development-system
Be sure that you want that.
A good introduction to the topic could be found at
https://www.ssh.com/ssh/tunneling/example
https://unix.stackexchange.com/questions/115897/whats-ssh-port-forwarding-and-whats-the-difference-between-ssh-local-and-remot

firewall has blocked ssh. any wayarounds?

I want to connect to remote amazon aws service(EC2 instance) , and I would like to be able to ssh to it from my laptop while using the campus provided network (which has cyberoam firewall). However, they have pretty much every port blocked and ssh won't work. Is there anything i can do? does ssh run through port 80? I don't really know what to do .
All it says is :
ssh_exchange_identification: read: Software caused connection abort
ssh works elsewhere.
You can set your SSH server to use port 80 (or 443 if 80 is used for a webserver). Just check the configuration file of your ssh server for more details!

Xampp, Apache and SSH tunneling

I'm developing a PHP application on my localhost (Windows) using Xampp. I need to access a third party API from my application but I only have access to the API using our online server IP address.
How can I re-route my Apache requests to internet thru our online server using SSH tunnel?
(I can't setup a VPN connection)
Thanks
Assuming your the URL for your third party API is at:
192.168.200.100 on port 80
And your online server IP is:
10.10.10.100
To open the tunnel run the following command:
ssh -L127.0.0.1:8888:192.168.200.100:80 10.10.10.100
The ssh command will manually connect you to your online server and open an SSH tunnel that you can reference at:
127.0.0.1 on port 8888
So in your PHP application instead of connecting directly to the third party server at 192.168.200.100, you use your local IP and port (127.0.0.1:8888) instead.