1

I'm trying to connect to myself through ssh. (For testing purpose). I'm on a Ubuntu laptop. I successfully launched a ssh serveur, and "ssh localhost" works fine. If I try "ssh ", it works too. (I got it from ifconfig) But if I try with my public IP adress (got it on whatismyipadress.com), it doesn't work, I get a timeout after 2 minutes. (Note that "ping " works fine)

Any idea about why I get this ? I wouldn't be surprised if the problem came from my router (or is it a modem, or something like that ? I don't know), which would be working fine but have no idea about where to redirect ssh request (maybe on a computer from home which doesn't run ssh server ?)

  • 2
    Have you forwarded the ports to your computer? – lw1.at Sep 18 '16 at 17:48
  • @Findus23 : I'm sorry, I have no idea of what it means. I guess the answer is no. – bisthebis Sep 18 '16 at 18:15
  • First, is your laptop behind a NAT? If so, have forwarded the 22 ports from the router to your laptop? – TJM Sep 18 '16 at 18:16
1

As @Findus23 says, you have to forward a port (different from the 22, which is perhaps used as default port to connect to SSH router itself) from the router to your PC.

I make an example:

PC [192.168.1.10] <==> [192.168.1.1] Router [1.1.1.1] <==> Internet  

As you can see, connecting through SSH to the address 1.1.1.1 results in connecting to the port 22 of your router on his public interface (faced to Internet).

If you want to access a PC located behind the router (so, in the private network of address space 192.168.1.0/24) you have to enable Port Forwarding.
This is mandatory because your router must know which host it has to contact from the full address space of PCs connected to it. For example:

(PC1[192.168.1.2], PC2[192.168.1.3]) <==> Router  

Router cannot know if it has to route to PC1 or PC2 when contacted to a specified port.
Enabling Port Forwarding you can say:

All connections from Internet to port X of the router, must be routed to port Y of PCZ

So, in your case:

Router:<port> => PC1:22 (route connection from router port 4000 to port 22 of PC1)
ssh -p <port> user@<router-IP>  

results in connecting, from Internet, to the specified local host.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.