0

When I am trying to SSH to Raspberry Pi using the same network, the following works: bash-3.2$ ssh pi@192.X.Y.Z

however when I am trying to SSH to it from home network it doesn't. How can I do so remotely?

ssh: connect to host 192.X.Y.Z port 22: Operation timed out
  • You made sure that ssh was enabled with sudo raspi-config, right? – Patrick Cook Mar 23 '16 at 2:47
  • I will get back to you tomorrow. Have no access to my Raspi now! – Mona Jalal Mar 23 '16 at 2:52
  • 1
    Could you please specify if the same network in your first half of the question refers to your home network that you mention in the second half? – Chris Mar 23 '16 at 3:15
  • 1
    I think you assume they are both on the internet, but that doesn't mean they are on the "same network". When you first tried ssh at the lab and now you try the same thing at home, you won't be able to reach the Pi with that 192.X.Y.Z IP, because it is outside of your home network. That's because 192.168.Y.Z refers to a local IP address, that is given to the Pi by your DHCP server in the lab (in the network router). You would have to know the external IP of the Pi and setup port-forwarding. This may not be possible depending on the firewall configuration and admin situation of your lab. – Chris Mar 23 '16 at 3:20
1

I think the problem is that you are no longer inside your lab's network. When you first tried it you were probably in the lab and you were in fact using the same network. Meaning: your RPi and your computer were on the same local network. Both had IPs given to them from the same DHCP and they looked something like this: 192.X.Y.Z

Now, when you are home, your local network has changed. Your Router at home will also give you a similar IP (maybe even the same one), but that doesn't mean you are both still on the same network. Every network address starting with 192.168.X.Y or 10.0.X.Y is reserved for local network services. That means every local network - your neighbours / mine / your labs / etc. uses these IPs internally.

However, externally, your network at home usually will only have one external IP. You can get this by looking at your router config or just visiting whatismyip.org.

Therefore, when you try to connect to your RPi from home, you won't be able to reach that Pi starting with 192.X.Y.Z, because it is actually outside of your home network. Instead you need to know the external IP and of the Pi and setup port-forwarding through the network router in your lab.

Note:

This (port-forwarding) may or may not be possible depending on the firewall configuration and admin situation of your lab. You can ask them and generally, SSH access should be allowed, but that's an individual policy.

Maybe you also actually don't have to setup anything and just find out the external IP. In our lab for example any device has an individual external IP and SSH is allowed for all of them - if this is the case - you are good to go and can just type: ssh pi@123.MY.EXTERNAL.IP

  • 1
    going a little bit beyond the scope, but if your lab actually uses dynamic IP address assignment - I would advice to use a dynamic DNS service, such as duckdns.org - they will give you a free address in this format: NAME_MY_PI.duckdns.org and they already have all the scripts you need to regularly update your actual external IP with them. You then won't have to remember the (changing) IP, but instead just type: ssh pi@NAME_MY_PI.duckdns.org - at least that's what I do :) – Chris Mar 23 '16 at 3:37
  • @MonaJalal - did you get a chance to check it out? – Chris Mar 29 '16 at 3:51
0

Well yeah. That's how it's supposed to work.

Make sure port 22 is port forwarded to your Pi if you want to access SSH from an external network.

Also, if you do SSH from an external network, make sure to use the public IP (X.X.X.X), not the private IP (192.168.1.NNN).

  • The OP does say 'on the same network' – Patrick Cook Mar 23 '16 at 2:46
  • The OP is actually not very clear and first refers to the same network and later to from the home network. This could suggest that the same network is not the home network, but the question should be made a bit more clear. – Chris Mar 23 '16 at 3:13
  • @PatrickCook The way I saw it was the same network refers to the network the Pi is on and home network is a separate network. – Gene Dela Rosa Mar 23 '16 at 5:41

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.