Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am trying to get my own web server started. I have installed a fresh copy of ubuntu server and openSSH.

I can SSH into the server fine by using the internal IP (192.168.1.12) but cannot access it through my external IP address. I have set up port forwarding but still get 'connection refused' from putty.

One thing I have noticed is that if I log on to my web server and type sudo /usr/sbin/sshd -d I get the following errors:

debug1: Bind to port 22 pm 0.0.0.0
Bind to port 22 on 0.0.0.0 failed: Address already in use.
debug1: Bind to port 22 on ::.
Bind to port 22 on :: failed: Address already in use.

I'm guessing this is the cause of my problems trying to ssh using my external address? I've tried to disable ipv6, but only one of the errors is fixed when I do this

EDIT: netstat -tan | grep LIST gives the following result

tcp    0    0 0.0.0.0:22      0.0.0.0:*      LISTEN
tcp6   0    0 :::22           :::*           LISTEN

netstat -tulpn

Proto Recv-Q  Send-Q   Local Address       Foreign Address      State    PID/Program name
tcp     0       0      0.0.0.0:22            0.0.0.0:*          LISTEN     620/sshd
tcp6    0       0      :::22                 :::*               LISTEN     620/sshd
udp     0       0      0.0.0.0:68            0.0.0.0:*                     604/dhclient3
share|improve this question
    
What does the listening socket look like? Find it in netstat. –  David Schwartz Jan 19 '12 at 2:11
    
you already have something running under port 22. Find out which service with "netstat -tulpn" . I am assuming you are using linux-flavored distro ! –  kaji Jan 19 '12 at 2:18
    
updated answer. I'm using Ubuntu server –  Roger Templeton Jan 19 '12 at 2:23
    
ip addr You have not specified how your "external address" is configured other than to say you setup port forwarding which could mean a number of things. –  dmourati Jan 19 '12 at 2:28
5  
You already have sshd running. It's running perfectly fine, as evidenced by the fact that you can ssh directly to 192.168.1.12 and the results for the netstat. What's most likely happening is that the port forwarding from your router either isn't working/setup properly. What's your public IP address? (ok, maybe don't tell us that :-). Does your internal server have only 1 IP address? Or does it have two, one in the DMZ and one internal? If there's a DMZ IP make sure the SSHD conf binds to that IP too (should be default default to all IPs). –  SuperMagic Jan 19 '12 at 3:56
show 3 more comments

2 Answers

up vote 5 down vote accepted

sshd is already running, as evidenced by your netstat. It is also bound to all IPs (0.0.0.0 in the netstat) so there should be no problem there.

Do you have a firewall on your router? You may have port forwarding enabled but a firewall may still be dropping the 22. It is also possible that your ISP is blocking 22 before it even gets to you. I would also do an iptables -F (drop all the iptables rules) to be sure; they'll return on a reboot (or you can restore them using iptables-restore).

You can confirm that sshd is not refusing the connections by checking /var/log/auth.log for the refused connections.

If you've confirmed that you have no refused connections in your logs and no firewall on your router then I would suggest changing SSH to use a port other than 22 (a random high port > 1024). You can do that by editing /etc/ssh/ssh_config and changing "Port 22" to something higher.

EDIT: Update from the comments to save a read; you should also try checking from an IP outside of your network in circumstances like this. In this case the ISP was blocking port 22, and connecting to a high port internally (specifying the external IP) was not working, probably due to a lack of hairpin NAT.

share|improve this answer
1  
I concur. The sshd is not the problem. Check firewall, port forward and you ISP. –  jkj Jan 19 '12 at 8:48
    
Hi, thanks for your answer. My router does have a firewall and I have just tried disabling it without any luck. I have also checked the log and there is nothing there about refusing connections. I've also tried using port 46000 but still have the same issue. I'm assuming this would have resolved the situation if my ISP was blocking 22. I must not be forwarding the port correctly as I've ran a port checker on my server and it confirms the port 46000 is not open. –  Roger Templeton Jan 19 '12 at 11:46
    
Then again, if I use the same method for port forwarding as I do successfully for my deskop and utorrent, then It should be working correctly. –  Roger Templeton Jan 19 '12 at 11:47
    
You're correct that switching it to port 46000 should bypass any ISP restriction; were you able to confirm that sshd took the port change on your netstat? It does seem likely that you are port forwarding correctly if it is working for other services on other hosts. Can the port checker successfully confirm your other services are port forwarded? –  nullity Jan 19 '12 at 12:03
    
I think I can confirm the port change was successful. I can still access my server using the IP 192.168.1.12 with port 46000. I must apologize, the port checker is now saying that 46000 is open and seems to be trustworthy –  Roger Templeton Jan 19 '12 at 12:29
show 5 more comments

Address already in use typically means some service is already running in port in question ie. 22 ? have you checked listening services ? can you dump

netstat -tan | grep LIST
share|improve this answer
    
ok i'll update my question. thanks –  Roger Templeton Jan 19 '12 at 2:12
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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