[ejabberd] Ejabberd listening on port 1212
jesus at isaatc.ull.es
jesus at isaatc.ull.es
Thu Oct 25 03:52:17 MSD 2007
Respondiendo a Badlop <badlop at gmail.com>:
>
> Ah, this also puzzled me some time ago, and I took a look. Now that I
> remember this topic, let's see if this explanation also convinces you.
> I think this deserves a page in http://www.ejabberd.im/faq right?
>
Yes, this an odd thing. Many other people can get worried about have
an open port for no reason at all.
> If I'm right, that listening socket is not opened by ejabberd itself,
> but by the Erlang node. It is related to epmd and the node
> connectivity. The port number should be different each time you start
> an Erlang node. In my case, the numbers are usually high (30.000 ..
> 55.000).
>
Some week ago I thought, too, that listening socket is not opened by
ejabberd because I couldn't find any reference to port 1212 or to LUPA
service in its sources.
> I made an experiment with ejabberd SVN and Erlang R11B-5 in a Debian
> unstable. I set only one port in the listen section: 5222.
>
> # Check that there are no open sockets by beam or epmd:
> $ netstat -tpan | grep "beam\|epmd"
>
> # Start ejabberd:
> $ ./ejabberdctl start
>
> # Now ejabberd listens XMPP clients in port 5222, and Erlang
> connections in port 33335. As you can see, the ejabberd node already
> connected with epmd's standard port 4369:
> $ netstat -tpan | grep "beam\|epmd"
> tcp 0 0 0.0.0.0:5222 0.0.0.0:*
> LISTEN 7552/beam
> tcp 0 0 0.0.0.0:4369 0.0.0.0:*
> LISTEN 7550/epmd
> tcp 0 0 0.0.0.0:33335 0.0.0.0:*
> LISTEN 7552/beam
> tcp 0 0 127.0.0.1:48107 127.0.0.1:4369
> ESTABLISHED7552/beam
> tcp 0 0 127.0.0.1:4369 127.0.0.1:48107
> ESTABLISHED7550/epmd
>
> # Now, in a different console I start an Erlang node that just
> attaches to the already running ejabberd node. This is useful to
> manually administer the ejabberd server:
> $ ./ejabberdctl debug
>
> # If all went correctly, now we have two Erlang nodes. The first runs
> ejabberd, and the second is connected to the first one:
> $ netstat -tpan | grep "beam\|epmd"
> tcp 0 0 0.0.0.0:5222 0.0.0.0:*
> LISTEN 7552/beam
> tcp 0 0 0.0.0.0:4369 0.0.0.0:*
> LISTEN 7550/epmd
> tcp 0 0 0.0.0.0:33335 0.0.0.0:*
> LISTEN 7552/beam
> tcp 0 0 0.0.0.0:44476 0.0.0.0:*
> LISTEN 7562/beam
> tcp 0 0 127.0.0.1:33335 127.0.0.1:45535
> ESTABLISHED7552/beam
> tcp 0 0 127.0.0.1:48107 127.0.0.1:4369
> ESTABLISHED7552/beam
> tcp 0 0 127.0.0.1:45535 127.0.0.1:33335
> ESTABLISHED7562/beam
> tcp 0 0 127.0.0.1:4369 127.0.0.1:49926
> ESTABLISHED7550/epmd
> tcp 0 0 127.0.0.1:49926 127.0.0.1:4369
> ESTABLISHED7562/beam
> tcp 0 0 127.0.0.1:4369 127.0.0.1:48107
> ESTABLISHED7550/epmd
>
> As you can see the port 33335 was listening for connections from other
> Erlang nodes. This feature is also used to stop the ejabberd server,
> and use commands such as reopenlog and others.
>
> In fact, ejabberd is not involved in that 33335 port opening. So the
> experiment can be reduced to just Erlang:
>
> # First check there are no open sockets:
> $ netstat -tpan | grep "beam\|epmd"
>
> # Then start an Erlang node, and move it to the background:
> $ erl -sname testnode
> Erlang (BEAM) emulator version 5.5.5 [source] [async-threads:0]
> [kernel-poll:false]
>
> Eshell V5.5.5 (abort with ^G)
> (testnode at localhost)1>
> [1]+ Stopped erl -sname testnode
>
> # Leave the program running, and check open ports:
> $ netstat -tpan | grep "beam\|epmd"
> tcp 0 0 0.0.0.0:4369 0.0.0.0:*
> LISTEN 7613/epmd
> tcp 0 0 0.0.0.0:36190 0.0.0.0:*
> LISTEN 7606/beam
> tcp 0 0 127.0.0.1:41149 127.0.0.1:4369
> ESTABLISHED7606/beam
> tcp 0 0 127.0.0.1:4369 127.0.0.1:41149
> ESTABLISHED7613/epmd
>
> There we have: beam now listens in the port 36190. It also connected
> to epmd port 4369 to gather some information. I didn't investigate
> that so much to sniff the traffic. If you have time to do this... tell
> me your findings.
>
> The only thing that still doesn't match for me is: the listening ports
> I observed are always different, and quite high: 30.000, 50.000... In
> your system the port is quite low: 1212. And is it always the same
> after ejabberd restarts?
I have done all your test and my opinion is that you are right. The
opened port (1212) in my system is used by erlang for comunication
between nodes, as in your system. The used port is different after
ejabberd restarts, always higher than 1024, but never as high as in
your system.
After investigate a little I found this in epmd manpage:
"This daemon acts as a name server on all hosts involved in
distributed Erlang computations. When an Erlang node starts, the node
has a name and it obtains an address from the host OS kernel. The name
and the address are sent to the epmd daemon running on the local host.
In a TCP/IP environment, the address consists of the IP address and a
port number. The name of the node is an atom on the form of Name at Node.
The job of the epmd daemon is to keep track of which node name listens
on which address. Hence, epmd map symbolic node names to machine
addresses."
And I tried to launch epmd with option -names:
$ epmd -names
epmd: up and running on port 4369 with data:
name ejabberd at port 1212
As you said, that port is opend by erlang for node communications.
Thank you.
--
// Jesús Miguel Torres Jorge - jesus en isaatc.ull.es
// Dpto. de Ingeniería de Sistemas y Automática
// y Arquitectura y Tecnología de Computadores
// Universidad de La Laguna - Tenerife, Spain
// Linux Counter Registered User #247255 - GULiC
// www.gulic.org - OpenXML no debe ser ISO 29500
// http://www.openxml.info/
More information about the ejabberd
mailing list