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 ( 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
Bind to port 22 on 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*      LISTEN
tcp6   0    0 :::22           :::*           LISTEN

netstat -tulpn

Proto Recv-Q  Send-Q   Local Address       Foreign Address      State    PID/Program name
tcp     0       0  *          LISTEN     620/sshd
tcp6    0       0      :::22                 :::*               LISTEN     620/sshd
udp     0       0  *                     604/dhclient3
  • What does the listening socket look like? Find it in netstat. Jan 19, 2012 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, 2012 at 2:18
  • updated answer. I'm using Ubuntu server Jan 19, 2012 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, 2012 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 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, 2012 at 3:56

2 Answers 2


sshd is already running, as evidenced by your netstat. It is also bound to all IPs ( 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.

  • 1
    I concur. The sshd is not the problem. Check firewall, port forward and you ISP.
    – jkj
    Jan 19, 2012 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. Jan 19, 2012 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. Jan 19, 2012 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? Jan 19, 2012 at 12:03
  • I think I can confirm the port change was successful. I can still access my server using the IP with port 46000. I must apologize, the port checker is now saying that 46000 is open and seems to be trustworthy Jan 19, 2012 at 12:29

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
  • That's a great alternative to lsof -i. Thanks!
    – atripes
    Aug 1, 2017 at 11:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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