LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 09-17-2007, 04:45 PM   #1
jin01
LQ Newbie
 
Registered: Oct 2006
Distribution: FC6, Knoppix, other
Posts: 23

Rep: Reputation: 15
Error: Bind to port 22


Hi,

I get this error message:

sshd[3164]: Server listening on :: port 22.
sshd[3164]: error: Bind to port 22 on 0.0.0.0 failed: Address already in use.

I looked in some old post and it stated the following in one:

"is that sshd tries to bind port 22 using IPv6 first and next tries to bind port 22 on the IPv4 address in case the first attempt failed. If the first attempt was successful, then the second attempt fails due to the port already being bound. If you set a specific IP address in the "ListenAddress" directive of the sshd_config file, then you shouldn't get the error."

What is the command format to use in the "sshd_config" file set the "ListenAddress"? And would this be the solution to this problem?

Thanks,
 
Old 09-17-2007, 08:10 PM   #2
salasi
Senior Member
 
Registered: Jul 2007
Location: Directly above centre of the earth, UK
Distribution: SuSE, plus some hopping
Posts: 4,070

Rep: Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897
Quote:
I looked in some old post and it stated the following in one:

"is that sshd tries to bind port 22 using IPv6 first and next tries to bind port 22 on the IPv4 address in case the first attempt failed. If the first attempt was successful, then the second attempt fails due to the port already being bound. If you set a specific IP address in the "ListenAddress" directive of the sshd_config file, then you shouldn't get the error."

What is the command format to use in the "sshd_config" file set the "ListenAddress"? And would this be the solution to this problem?
To answer your last question first: No one can tell (on the info given). Whether the post that you have quoted is actually true in your case is unknown because that degree of detail of set-up is particular to the distro and version. So if the poster was talking about WonderWare 10.0 and you actually have MagicUX 15.372 they could be totally different. In fact even MagicUX 15.372 and MagicUX 14.999 aren't necessarily the same. MagicUX 15.372 is probably more likely to have the ipv6 stuff in by default than 14.999, but some earlier iteration will not have and there may be some intermediate iterations for which it depends on how you configure networking at install.

On the other hand, you can simply look up what is going on and put it right. This seems the better option, but YMMV.

So, firstly you need to know who has got hold of the port that you want. netstat is the command you want here, but the exact operation of netstat switches can throw you a bit at first. Try

netstat -na|grep :22

which should tell you if someone has grabbed the port (and maybe some other stuff that happens to have :22 somewhere on the line)

You can do this as an ordinary user, but to get the info that you really want, you have to be root (or use sudo) and execute

netstat -pantu|grep :22

This should tell you which process has grabbed the port (if you don't run as root it will likely not identify the stuff you want - if nothing at all shows up, omit the grep part and have a look at everything) and then you just have to alter the conf for that process OR alter things in the start up so that process doesn't run (I'm being vague about the details of how you do this as they are distro-specific).
 
Old 09-19-2007, 07:23 PM   #3
jin01
LQ Newbie
 
Registered: Oct 2006
Distribution: FC6, Knoppix, other
Posts: 23

Original Poster
Rep: Reputation: 15
Hi,

I am running Fedora Core 6. This is a list of what both commmands printed.

[root@station01 jnolo]# netstat -na|grep :22
tcp 0 0 127.0.0.1:2208 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:2207 0.0.0.0:* LISTEN
tcp 0 0 :::22 :::* LISTEN
[root@station01 jnolo]#

[root@station01 jnolo]# netstat -pantu|grep :22
tcp 0 0 127.0.0.1:2208 0.0.0.0:* LISTEN 3123/hpiod
tcp 0 0 127.0.0.1:2207 0.0.0.0:* LISTEN 3128/python
tcp 0 0 :::22 :::* LISTEN 3154/sshd
[root@station01 jnolo]#

Does this tell more? Is there a conflict between protocols?
 
Old 09-20-2007, 02:31 AM   #4
salasi
Senior Member
 
Registered: Jul 2007
Location: Directly above centre of the earth, UK
Distribution: SuSE, plus some hopping
Posts: 4,070

Rep: Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897
see the line

Quote:
tcp 0 0 :::22 :::* LISTEN
that tells you that something is listening on port 22, and with that happening nothing else can use that port to listen on.

However, the line

Quote:
tcp 0 0 :::22 :::* LISTEN 3154/sshd
tells you what process is listening on that port, and it is sshd. In other words the daemon for the ssh service is already listening on this port. So I think what is going on is that somewhere in the distro's start up arrangement, it is already starting up ssh and you are trying to start a second copy (which obviously doesn't work because of the contention over a single port, and it wouldn't be useful if it did.)

So, I think you have less of a problem than you though you had. You already have sshd running. You can test this supposition with

ps -ef|grep ssh

which return a list of tasks running, which include the string 'ssh' in the name. One of these will probably be the ps command itself, but, if I'm right, there should also be an entry for sshd, the ssh daemon.
 
Old 09-20-2007, 12:21 PM   #5
jin01
LQ Newbie
 
Registered: Oct 2006
Distribution: FC6, Knoppix, other
Posts: 23

Original Poster
Rep: Reputation: 15
This is the print from the command:

[root@station01 jnolo]# ps -ef|grep ssh
root 2835 1 0 10:10 ? 00:00:00 /usr/sbin/sshd
jnolo 6217 6157 0 11:41 ? 00:00:00 /usr/bin/ssh-agent /usr/bin/dbus-launch --exit-with-session /etc/X11/xinit/Xclients
root 6658 6634 0 12:16 pts/1 00:00:00 grep ssh
[root@station01 jnolo]#


How do I remove the extra start of the sshd? What does the above tell?
 
Old 09-20-2007, 09:01 PM   #6
jin01
LQ Newbie
 
Registered: Oct 2006
Distribution: FC6, Knoppix, other
Posts: 23

Original Poster
Rep: Reputation: 15
Hi,

I rebooted after I stopped the sshd service in the "System>Administration>Server Settings>Services". Then ran the commands over again and printed the following:

[root@station01 jnolo]# netstat -pantu|grep :22
tcp 0 0 127.0.0.1:2208 0.0.0.0:* LISTEN 2803/hpiod
tcp 0 0 127.0.0.1:2207 0.0.0.0:* LISTEN 2808/python
[root@station01 jnolo]# ps -ef|grep ssh
jnolo 4248 4188 0 20:23 ? 00:00:00 /usr/bin/ssh-agent /usr/bin/dbus-launch --exit-with-session /etc/X11/xinit/Xclients
root 4593 4560 0 20:33 pts/0 00:00:00 grep ssh
[root@station01 jnolo]#

[root@station01 jnolo]# ssh -1 localhost
ssh: connect to host localhost port 22: Connection refused
[root@station01 jnolo]#

The ssh is still running. Is this a client service and how do you turn it on and off. What instances would I use the Server Service or Client Service?

Thanks.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
SSH: error: Bind to port 22 on 0.0.0.0 failed: Address already in use. Swakoo Linux - Security 6 05-08-2007 04:24 AM
using bind to redirect to port setiDude Linux - Networking 8 11-17-2004 01:35 AM
Bind Port dvong3 Linux - Networking 2 05-14-2004 03:26 PM
how to bind port on RH9? oracsol Linux - Networking 1 09-26-2003 01:09 PM
Unable to bind a port svelango Linux - Networking 0 02-15-2002 08:07 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 10:48 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration