SSH to server port forwarding through router

configurationport-forwardingssh

Hi so we have multiple machines on our network running ssh on port 22, because of this we set up port forwarding in the router as 22->22 for one of the machines and 222->22 on the other machine. The one that is set up to be 222 for the outside world will not allow us to connect to the machine unless its outside port is also 22 thus making us disable outside access to the first machine. Is there some sort of config that disables access for this type of situation?

Desired Functionality:

Outside----P22----->router-----P22----->Machine1 (Currently Works)
Outside----P222---->router-----P22----->Machine2 (Returns Connection Refused)

Only port 22 on the outside to either machine (with the other disabled) has worked so far.

Router: Linksys E2500

Best Answer

Instead of punching multiple holes in your router you may decide to use the following trick:

  1. open a connection to the first machine in one terminal window with the following command:

    ssh -L 10022:machine-2-local-ip:22 user-on-machine-1@router

  2. open another terminal window and you will be able to securely connect to machine-2 using

    ssh -p10022 user-on-machine-2@0

To describe it in plain English:

The first command starts up an ssh session with the router on port 22 and sets up ssh port-forwading binding your localhost's port 10022 to the machine-2-local-ip address on port 22 (as visible from the router). So, if you have proper internal DNS or a name defined in /etc/hosts on the router you can use a name in place of machine-2-local-ip, otherwise use the internal IP address of the second machine there.

The second command connects to port 10022 on your localhost. This port is forwarded through the established ssh session in step 1 to machine-2. :)

Hope this helps.

Related Topic