How to SSH to a private ip behind a router using public dynamic IP

ipssh

In my office there are 2 PC, both of them are behind a router with his own private IP. I'm trying to connect to them via SSH but it only seems to work while my notebook is connected to the same Wifi (meaning, all pc's are in the same network). How can I SSH to work from home?

I guess It's using the public IP (the one that you get from www.whatismyip.com or similar), but I can't find a way to tell the SSH to connect to a specific PC.

Also, I have a dynamic IP, so I set a DNS server (using my.noip.com).

All this is on Ubuntu, btw.

Thanks in advance.

Edit:

I have added some options to the router (it an apple time capsule A1470) under the Internet tab (Enabled NAT Port Mapping Protocol) and I added a Port Mapping Setup using port 22 and the private IP Address of the PC that I'm interested. Still, no clue on how to using public IP to get into the private one.

Edit 2:

Aparently, my port-forwarding is working, but I think I have two IP's, one for the router and a public one, though it seems like the public IP isn't reaching the Router IP. In my router info there's an IP which is like 172.x.x.x; when I ssh through that IP, and specify a port, I cant get into one of the two PC's in my office that Im interested, if I change the port (the one I set previously in the port-forwarding) I can get into the other PC. Problem is that PC's out of the network can't use the IP repoted in router. Public IP isn't working either, not even from the same network.

Best Answer

You have to add a port-forward rule in your router and set the destination IP address of the required computers LAN IP and port 22.

You can not specify to SSH which computer you want to connect to, you can only connect to an IP address (or a resolvable domain name) and a port (default 22). Only to those for which you set a port-forward rule on your router.

However, you can add multiple rules to each computer but the WAN side port must be different for each one, ie. you can use port 22 only once.

For example:

  • WAN port 22 ---> LAN IP: 192.168.1.1 PORT: 22
  • WAN port 2220 ---> LAN IP: 192.168.1.2 PORT: 22
  • WAN port 2221 ---> LAN IP: 192.168.1.3 PORT: 22

See my answer to a very similar question: Why can't I access my web server from outside the network?

Related Question