-1

I'm trying to connect to my server via SSH. I get the (well-known) error:

ssh: connect to host 12.345.678.910 port 2222: Connection refused

So I first thought the problem was with my modem, but I've verified that port 2222 is open (via http://portchecker.co/check)

The SSH deamon (sshd.socket) is also working and listening on port 2222 and I've changed my /etc/ssh/sshd_config to allow connections via port 2222.

I think the problem might be with my firewall because nmap -p 2222 12.345.678.910 shows that port 2222 is closed but host is up.

What should I do to allow SSH on my server via port 2222? What other diagnostics can I perform to see what the problem is?

===== EDIT =====

Resolved the issue:

The problem was not any of the above or as suggested in the "This question already has an answer so deal with it" but it had to do with that I was trying to log on to the server from the same network to which the server is connected. I tried to connect to the server from a different network (at university) and this worked perfectly. So is there something restricting me from logging on from the same network (so behind the same modem)?

1 Answers1

0

It could be your local iptables firewall. try the below command to open port 2222

#iptables -A INPUT -p tcp -m tcp --dport 2222 -j ACCEPT

Bhargav
  • 87
  • 6
  • I've tried this before (altough without the -m option) but it didn't work. Also now it doesn't work. I don't have to restart the SSH deamon, right? I noticed the iptables settings aren't saved when I reboot my system.. – MichaelDeSanta Jan 06 '16 at 00:02
  • Just to make sure if it is iptables or not. try disabling the iptables by doing #service iptables stop and then try if its connecting. if not it is something else. Don;t forget to start your iptables again after you've done the test. #service iptables start – Bhargav Jan 06 '16 at 00:03
  • Stopping iptables didn't solve it. What I found is that nmap myipaddress shows three ports open (ftp/telnet/http) but 2222 closed. But if I use an externel port check website these are all closed, except for 2222. How can this be? – MichaelDeSanta Jan 06 '16 at 00:10
  • You can also check if sshd is listening on port 2222. #netstat -tulpn | grep 2222 you'll have to be root to do this – Bhargav Jan 06 '16 at 00:11
  • I'm using ss, but the results is : tcp LISTEN 0 128 :::2222 :::*. Which I find weird because deamon sshd.socket is active(listening) on [::]:2222 – MichaelDeSanta Jan 06 '16 at 00:12
  • did you port forward 2222 in your router to your machine's ip? – Bhargav Jan 06 '16 at 00:27
  • yes, I did. I'm trying some web-based SSH services now and I seem to be getting a connection. Logging in doesn't really work. So maybe it's my client ssh that is giving problems. Which is weird because when I hooked up my laptop to my server directly I could SSH without problems. Maybe because I changed the default port though. I will try some more, thanks for you help so far – MichaelDeSanta Jan 06 '16 at 00:30