4

I am having trouble accessing my Pi from the internet using SSH. I have been searching around a number of websites, seen similar but not exactly the same issues as mine so hope someone on here can help. First up, I am a relative novice when it comes to networking so have gone right back to the basics to try to set this up as I do not yet understand technical speak.

My pi is a fresh install of Raspbian. It was then apt-get “updated” and “upgraded” successfully, so I am assuming everything should be up to date. No additional software has been installed yet.

I did this “headless” using SSH over my local network. SSH seems to work fine on the local network inside my house.

I set the pi up with a static internal ip address on my BT router. Note: this router can not be set up to be “pinged” I don’t know if that matters but more on that in a moment.

Port forwarding has been enabled on the router for port 22 and set to point to the “raspberrypi”.

As a BT customer, I then popped outside and hooked onto a neighbour’s “fon” service and logged in using my Dell running Ubuntu 16.04. Did a test search on google to validate the connection was up.

I opened a terminal window and typed:

ssh [email protected] 

The IP address used was that dynamic IP address provided by BT to my home network before I went outside (and it still was when I went back in). To be clear I did not type xxx this was a three digit number.

I was not sure what my username was on the pi because it only ever asks for my password so I typed whoami whilst using SSH with the Pi on my home network. The response was pi.

Hence I thought it should work but it did not. After pressing return there was a long pause and then it timed out.

Suspecting the ping issue was the problem and that the BT Home Hub 3 modem was operating in some sort of stealth mode not readily apparent from searching the advanced settings, I bought a new ADSL router that can be pinged (I am serious about getting this working). It was an older model Belkin.

Setting up as before more or less (I seem unable to set a static ip internally for the pi with this modem but no matter for now, because it stays put at 192.168.2.3 when it is on) I was able to use SSH in the house with no problem. With ping on I went outside and tried again.

Ping worked

but ssh pi@ [correct public ip address for router at that time] did not work This time there was a much faster response – a one liner ending with “connection refused”

This was repeatable with ping on or off which is a relief because I’d rather it be off.

So 2 issues

  1. Why did I get two different results with different modems?
  2. How can I get it to work?

Apologies for the epic tale, but from what I have learnt so far, details can be very important.

8
  • "Connection refused" == Nothing listening on that port (i.e., it is reachable, but there is no ssh server there).
    – goldilocks
    Commented May 13, 2016 at 13:55
  • The question is very similar to raspberrypi.stackexchange.com/questions/13861/…
    – joan
    Commented May 13, 2016 at 13:57
  • Your comment is in alignment with another I have seen on a similar topic (unresolved). But I can't understand how it can be that " there is no ssh server there" when it works in the house on the lan. I wonder if the pi has been set to ignore incoming traffic from the internet (for security reasons) until specific exceptions are set up somewhere. But I have not found any resolution based on this approach. Thanks for your quick response.
    – Adan
    Commented May 13, 2016 at 13:59
  • My point about "connection refused" is that this message eliminates two possibilities: 1) That a firewall is preventing or forbidding the connection, 2) That there is no computer at that address. It is consequent of a specific ICMP message sent from an operating system to indicate that the port is accessible (i.e., not blocked) but there is no server listening on it. While in theory that could be faked, I promise your pi is not doing any such thing. So you can stop searching for issues in those two directions.
    – goldilocks
    Commented May 13, 2016 at 17:37
  • Put another way, the likely explanations here are: 1) Wrong IP address, 2) The router is not forwarding properly, 3) The SSH server has stopped.
    – goldilocks
    Commented May 13, 2016 at 17:40

2 Answers 2

1

You have to set port forwarding and check if it open correctly.

WAN port : port number you want to connect from outside (e.g 54345)

LAN port : 22, and point to your LAN IP address of your Pi,

Enable Port Mapping, save.

Google to find how to check if the port is open :)

If all good, you should now able to ssh it by

ssh [email protected] -p 54345

Remember you must specify the port you want to connect from outside network, otherwise ssh [email protected] will try connect to port 22 only as default :)

1

Additionally ..

  • Your BT IP address will change regularly, so sign up for a dynamic DNS service. Assuming your BT router is a homehub, set it up under Advanced Settings -> Broadband -> Dynamic DNS. With that, and port forwarding, you'll be able to access the pi using your Dynamic DNS address, for example "ssh fbloggs.myftp.org"
  • you don't need a static IP on your raspi as you stated you're port forwarding by device name.
  • ensure that you change your pi user password !
  • consider how you'll block the gazillions of login attempts that you'll get as soon as your pi's exposed to the Internet (for example fail2ban, iptables rules, SSH keys)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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