-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)?

0
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

7
  • 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 6 '16 at 0: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 6 '16 at 0: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 6 '16 at 0: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 6 '16 at 0: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 6 '16 at 0:12

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