Ake Koomsin

SSH to a Computer Inside an Internal Network

There are times that I want to access to my computer in my laboratory remotely. However, it is inside the lab’s internal network. Luckily, There is a gateway that I make a ssh connection to. The simplified scenario is shown below.

1
2
3
|---------|      |-------|      |-----------|
|my laptop|------|gateway|------|my computer|
|---------|      |-------|      |-----------|

To access my computer in the internal network, I can create a tunnel by running this command on my laptop:

1
ssh -L PORT:MY_COMPUTER_INTERNAL_IP:22 gateway -lUSER_TO_LOGIN_ON_THE_GATEWAY -N

This command will create a tunnel that will forward the local port PORT to my computer port 22 (SSH). -N is for not executing a remote command.

After that, I can simply ssh to my computer using the following command:

1
ssh -lUSER_TO_LOGIN_ON_MY_COMPUTER -pPORT localhost

And that’s all.