Forward website traffic to a different firewalled server using SSH - ssh

I'm trying to forward website traffic to a secondary server (as a temp workaround) using SSH.
ServerA for example can be accessed with serverA.example.com:8080
ServerB can't be accessed from outside, but running a wget localhost:8888 on ServerB returns the website I want to display on serverA.example.com:8080
Both serverA and serverB can be SSH'ed into.
I'm guessing for this scenario, Remote Forwarding is needed ...
So from ServerA, I run the following:
ssh -R8080:localhost:8888 jan#serverB.example.com
or
ssh -R8888:localhost:8080 jan#serverB.example.com
In both cases if I go to serverA.example.com:8080, I get a "This webpage is not available"
In short, I need to be able to point my browser to serverA:8080 which should forward it to serverB:8888 via SSH as SSH is the only open port on serverB.
Any idea how I can get this setup working?

You don't need to use Remote port forwarding -R but Local port forwarding -L. As this on serverA :
ssh -L8080:localhost:8888 jan#serverB.example.com
This will redirect local port 8080 from serverA to port 8888 on serverB through the ssh connection to serverB.
Be sure that nothing is running on local port 8080 on serverA before launching your command.

Related

Double tunnel hop ssh

I'm using WinSSHTerm to connect to a proxy, from which I then connect to a server hosting a data warehouse. I just can't figure out how to reproduce my Putty connection using a shell command.
Short recap:
I first connect to the proxy server which maps the port 5432 to my local port 10001. After that, i connect to the database server and map its 5432 port to my proxy's 5432 port, which I previously mapped to my 10001 port locally. I am then able to connect to the databse via a database manager locally.
To do so:
I created the following connection to my proxy server first.
I then added a tunnel from there to my localhost port 10001.
Once I'm logged in to the proxy server, I use the following command to connect to the database server and map its 5432 port to the proxy's 5432 port.
ssh username#databaseServer -L 127.0.0.1:5432:databaseServer:5432
I'd like to leave putty and move to WinSSHterm, predefine some login commands for a specific server.
How may I reproduce the behavior above using a shell command?
Here's my initial try, which is unfortunately not working:
ssh username#databaseServer -L 127.0.0.1:5432:databaseServer:5432
Thank you
I was finally able to find the correct way to write it.
Loginc Cmds
ssh username#databaseServer -L 127.0.0.1:5432:databaseServer:5432
Cmd-line Args
-L 10001:localhost:5432

Connect from local PC to remote server with Docker web server

my Docker-Container is on my server.
Via SSH I can connect to the server from my local PC.
ssh user#RemoteServerIP -p 3360
From there I can connect to the Docker container via SSH
ssh userRemoteServer#DockerContainerOnServerIP -p 22
A Apache Webserver is running on the Docker-Container.
How can I access the Webserver on my local computer?
from you server try to figure out which port the apache container is using.. you can use netstat command sudo netstat -ntlp usually in the PID/Program name docker port is PID/docker-proxy .
after you know which port apache container is using, then u can access it using yourServerIP:ApacheContainerPort from you local computer
assuming of course the way you exposing apache port inside container is correct.

Create ssh tunnel for avoid firewall blocking

I have remote host/server with ssh access.
I have my computer in my work network which can connect via ssh only
in within this network.
And i can not connect via ssh to other world because of port 22
blocked by firewall.
I am trying to create ssh tunnel to forward example localhost:80 to remote_server:22.(i suppose to connect via ssh to localhost and will be forwarded to my remote server)
I tried for example without proxy
sudo ssh -L localhost:443:remote_server_ip:22 root#remote_host_name
and with proxy
https://wiki.archlinux.org/index.php/Tunneling_SSH_through_HTTP_proxies_using_HTTP_Connect
I have read a lot and checked stackoverflow but it still is not clear for me how to resolve this issue.

Reach webserver via SSH tunnel

I have a RaspberryPi in my private local network (example: 192.168.1.2) and I have a dedicated server (example: 99.99.99.99) from some provider.
From my RaspberryPi I can connect to the server via ssh without trouble, the opposite situation is not possible. The RaspberryPi is not reachable from the internet.
Now I want to reach the webserver on my RaspberryPi from the internet with some ssh brigde/tunnel.
So if I enter the IP 99.99.99.99 in my browser, I want to see the website from the RaspberryPi. How it is possible?
The -R option to ssh will permit a remote tunnel to be opened towards the ssh client. So, if from the pi you run
ssh -R0.0.0.0:8080:address_of_pi:80 99.99.99.99
Then you will open an ssh and while that ssh is active anyone can go to 99.99.99:8080 and get to your pi.
You need to use 8080 as the port on the webserver address because the ssh process cannot bind to port 80 without being root.

Connecting MySQL to server through another server by SSH

Setup:
My computer (linux / unix) has an arbitrary IP address
I can connect to a central linux server which has a static ip
Remote linux systems are set up so they only respond to central server IP address on port 22
I want to port forward through the central server so I can use MySQLWorkbench and make python scripting connections on port 3306 to the remote systems.
Ideally, I would like the syntax for ssh command to make the port forwarding work;
Suppose I want to forward local port 3307 to 3306 on the remote system. Assume my ip is x.x.x.x, the central server IP is y.y.y.y, and the remote system IP is z.z.z.z;
I think it has something to do with ssh -L but I can only forward to the central server so far. Maybe I need to connect to the central server, set up forwarding there, then set up forwarding on my machine? I think functionality exists to do it with a single command using ssh.
If this is a duplicate, it should not be marked as such because without knowing what magic keyword to search for, you can't find the duplicate;
Clarification: port 3306 is NOT open on the remote server. Only 22
ssh -L :3307:z.z.z.z:3306 user#y.y.y.y -Nf
Works fine
or
ssh -L 3307:z.z.z.z:3306 user#y.y.y.y -Nf
To only bind to x.x.x.x's localhost
The first example binds to all interfaces
edit...
Just seen that z.z.z.z only has port 22 open.
on y.y.y.y you will also need to have a local port open
run on y.y.y.y
ssh -L 3307:localhost:3306 user#z.z.z.z -Nf
then on x.x.x.x
ssh -L 3307:localhost:3307 user#y.y.y.y -Nf
run these commands in a screen for best results
You can actually condense these 2 commands together
ssh -L 3307:localhost:3307 user#y.y.y.y -f 'ssh -L 3307:localhost:3306 user#z.z.z.z -Nf'
ssh -L <local-port-to-listen>:<remote-host>:<remote-port>
The ā€˜Lā€™ switch indicates that a local port forward is need to be created
Best method is to create the tunnel using putty (ssh client). so you can start the shell, and it will create the ssh tunnel for you. this is a good reference
https://howto.ccs.neu.edu/howto/windows/ssh-port-tunneling-with-putty/