[ejabberd] Ejabberd listening on port 1212

Badlop badlop at gmail.com
Wed Oct 24 01:11:17 MSD 2007


2007/10/23, jesus at isaatc.ull.es <jesus at isaatc.ull.es>:
> I have executed the command "netstat -tpa", those are the more
> relevant lines in command output:
>
> tcp        0      0 *:5280                  *:*
> LISTEN     3004/beam
> tcp        0      0 localhost.localdom:5281 *:*
> LISTEN     3004/beam
> tcp        0      0 *:xmpp-client           *:*
> LISTEN     3004/beam
> tcp        0      0 *:5223                  *:*
> LISTEN     3004/beam
> tcp        0      0 *:4369                  *:*
> LISTEN     2987/epmd
> tcp        0      0 *:xmpp-server           *:*
> LISTEN     3004/beam
> tcp        0      0 *:1212                  *:*
> LISTEN     3004/beam
>
> The port 1212 is opened by beam, as you can see.

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?

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

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?


More information about the ejabberd mailing list