Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to forward ssh requests that come in over a certain port to another machine?

I have a small local network. Only one of the machines is available to the outside world (this is not easily changeable). I'd like to be able to set it up such that ssh requests that don't come in on the standard port go to another machine. Is this possible? If so, how?

Oh and all of these machines are running either Ubuntu or OS X.

like image 216
Paul Wicks Avatar asked Sep 05 '08 04:09

Paul Wicks


People also ask

Can you port forward SSH?

SSH is a secure shell and it offers a private connection between hosts. SSH port forwarding is one method that is used to tunnel traffic through an SSH connection. This can be done either locally or remotely if you are not close by to the target machine. Port 22 is used by default for establishing SSH connections.

Can I forward port 22?

Unfortunatly, port 22 (SSH) is a port that you cannot forward when using the radio in NAT mode. You'll either need to setup the radio as a bridge OR router mode. You could however use a different external port number, like 222, and then forward to internal port 22.

How do I forward one port to another?

To forward ports on your router, log into your router and go to the port forwarding section. Next, enter the port numbers and your device's IP address. Choose a forwarding protocol and save your changes. Note: If you don't see a port forwarding option in your router's settings, you might have to upgrade.


1 Answers

Another way to go would be to use ssh tunneling (which happens on the client side).

You'd do an ssh command like this:

ssh -L 8022:myinsideserver:22 paul@myoutsideserver

That connects you to the machine that's accessible from the outside (myoutsideserver) and creates a tunnel through that ssh connection to port 22 (the standard ssh port) on the server that's only accessible from the inside.

Then you'd do another ssh command like this (leaving the first one still connected):

ssh -p 8022 paul@localhost

That connection to port 8022 on your localhost will then get tunneled through the first ssh connection taking you over myinsideserver.

There may be something you have to do on myoutsideserver to allow forwarding of the ssh port. I'm double-checking that now.

Edit

Hmmm. The ssh manpage says this: **Only the superuser can forward privileged ports. **

That sort of implies to me that the first ssh connection has to be as root. Maybe somebody else can clarify that.

It looks like superuser privileges aren't required as long as the forwarded port (in this case, 8022) isn't a privileged port (like 22). Thanks for the clarification Mike Stone.

like image 179
Mark Biek Avatar answered Sep 30 '22 06:09

Mark Biek