I know this question has been asked many times but I could not get it running so I decided to ask it here. I have a Raspberry PI running on my local network which I can easily SSH it through my macbook, using the following code:

ssh pi@192.168.0.x

However for external connection I use the public IP instead such as:

ssh pi@213.xx.xx.x

But I get the following error:

ssh: connect to host 213.xx.xx.x port 22: Operation timed out

On my router I set up port forwarding, for service SSH from and to port 22 based on the Raspberry's local IP address.

Is the commands and setting correct? obviously SSH is enabled on Raspberry PI as I can SSH it locally. But is there anything else I need to do on it prior the connection?

  • The model doesn't really matter here, and the OS probably doesn't either since some GNU/Linux variant is implied. – goldilocks May 20 at 21:10
  • It could very well be a problem with the router NAT not working properly.... it could also be that your ISP is filtering out traffic to TCP port 22 (which would not be the first time it happens). In order to make sure at least the problem is not on the rpi, you can use a sniffer. Use tshark, for example and run something like: sudo tshark -n -i eth0 tcp and port 22 (adjust to the interface you are using) and try to connect. If when you try to connect from internet you get no traffic on tshark, then it's the router or the ISP to blame. Test tshark by connecting from private network. – eftshift0 May 20 at 23:09
  • ask one of your friends to try connecting .... i have had issues with connecting to my router ip when i was at home ..... i set up a web server on my PC, set up port forwarding to the PC .... i was unable to connect to the PC web server through the router's IP on any device that was connected to the local lan .... i had to use a smart phone that was not connected to lan – jsotola May 21 at 0:08

Although there can be a variety of issues for port forwarding to fail, here are some possibilities:

  1. The router will ask for an external IP address. It seems that you put in your external IP address in the box, but I had this issue, and, for my router, you put in 0.0.0.0

  2. Your ISP blocks port forwarding on specific ports to keep bandwidth usage down (so their customers don't host a mass downloading service on their network). It seems unlikely that they'd block port 22, but it is a possibility.

  3. There's a firewall enabled on your Raspberry Pi, or some other sort of service that blocks connections from certain IP addresses.

  4. Your router isn't directly connected to a external internet interface, i.e. there's another modem or other device that needs to be port forwarded as well.

Although this is not a complete list, these are some issues I have ran into personally while setting up port forwarding. I hope this helps.

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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