Setting ejjaberd on Debian Jessie

Setting ejjaberd on Debian Jessie

Hi everybody!
In the last few weeks I've been immersed in, paradoxically, Debian server setups, but not only at work, but also as part of some funny classes at Intitut Obert de Catalunya that deal about Internet Services.
Among several typical examples and exercices, there was a one that, sincerely, was a little bit challenging because I found documentation pretty much outdated (and probably because I'm getting also a little bit outdated :-p)... ejabberd

So, after putting all pieces to together and having fun playing with pidgin, I decided that that would be a nice matter to post about... so, here we go!

Setting the naming services.

XMPP - ejabberd works over domains much as mailing does, but, having not the luxury of things like MX RECORDS, there is where SRV records do the job.
This, of course means that we do have to get our domain up and running, and our server/clients well configured to work on it.
So, for that reason, I'll briefly introduce for the shake of the example my test domain pixapins.lan

As usual, first we setup the hostname

From jessie onwards, we do use hostnamectl command, like so:

hostnamectl set-hostname jabber


Now hostname direct resolving

Yet again, /etc/hosts comes into play
The following is the looking of Jessie's default hosts file modified for the example. Here, note my domain associated network subnet was, being the servers IP address       localhost.localdomain localhost      jabber.pixapins.lan   jabber

# The following lines are desirable for IPv6 capable hosts
::1     localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters


Setting up bind9

Things go hotter now... we needed to set up a fully working Domain Name Service, but... that's a piece of cake!!!
Installing bind9 DNS server and common CLI utilities is as easy as:

apt-get install bind9 dnsutils

Then, we do configure, our server at /etc/bind/named.conf.options
Note that I'm setting google DNS public servers ( and as forwarders, you may change this to your ISP ones or whathever... Out of comments, the file should have a looking like this:

options {
        directory "/var/cache/bind";

       forwarders {

        dnssec-validation no;

        auth-nxdomain no;    # conform to RFC1035
        listen-on-v6 { any; };

        allow-query-cache {any; };

        recursion yes;
        allow-recursion { any; };


Next step is to declare the DNS name zone pixapins.lan and the reverse subnet zone for
We need to declare both zones, and the their related records files at /etc/bind/named.conf.local... Among any other zones, the following would have to be added there:

zone "pixapins.lan"{
                type master;
                file "/etc/bind/db.pixapins.lan";
                allow-query {;;};

zone ""{
                type master;
                file "/etc/bind/";
                allow-query {;;};

And then, we must ensure to create, and fill with correct DNS zone records both /etc/bind/db.pixapins.lan and /etc/bind/ files.

The /etc/bind/db.pixapins.lan zone file has the very basic set of records for the typical domain: SOA, NS, MX and A records, along with xmpp/jabber SRV records.
Note how SRV records point to existing A record...

;Zone configuration file for direct resolutions at pixapins.lan.
pixapins.lan.   IN SOA jabber.pixapins.lan. root.pixapins.lan. (
                2016091810                      ;Serial
                3H                              ;Refresh
                2H                              ;Retry
                4D                              ;Expire
                3D      )                       ;Negative Cache TTL

;Nameservers section
pixapins.lan.           IN      NS              jabber.pixapins.lan.

;Mailservers section
pixapins.lan.           IN      MX      1       mail.pixapins.lan.

;Hosts section
jabber  IN      A     
mail    IN      A     

;SRV section
_jabber._tcp.pixapins.lan.              IN SRV 5 0 5222 jabber
_xmpp-server._tcp.pixapins.lan. IN SRV 5 0 5269 jabber
_xmpp-client._tcp.pixapins.lan. IN SRV 5 0 5222 jabber

The file /etc/bind/ looks like this

;Zone configuration file for reverse resolutions at pixapins.lan.
$TTL 1D  IN SOA jabber.pixapins.lan. root.pixapins.lan. (
                2016091801                      ;Serial
                3H                              ;Refresh
                2H                              ;Retry
                4D                              ;Expire
                3D      )                       ;Negative Cache TTL

;Nameservers section  IN      NS              jabber.pixapins.lan.

;PTRs section
1                       IN      PTR             jabber.pixapins.lan.
1                       IN      PTR             mail.pixapins.lan.

And that's all about DNS settings...
It is time to restart our DNS server to ensure it reads our config changes:

service bind9 restart


Reconfigure name resolving

Now that our server is a fully funtional DNS server, we will ask him to use itself as its DNS server instead of the ones provided by our ISP connection, this means modifying /etc/resolv.conf

domain pixapins.lan
search pixapins.lan


Testing SRV records to work

Before going further, it is a good idea to check that our SRV records and the domain in general is working.
Issue the following command:

dig _jabber._tcp.pixapins.lan srv

Here's a console example of how it may look if everything goes well:

root@jabber:~# dig _jabber._tcp.pixapins.lan srv

; <<>> DiG 9.9.5-9+deb8u8-Debian <<>> _jabber._tcp.pixapins.lan srv
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 17005
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 2

; EDNS: version: 0, flags:; udp: 4096
;_jabber._tcp.pixapins.lan.             IN      SRV

_jabber._tcp.pixapins.lan.      86400   IN      SRV     5 0 5222 jabber.pixapins.lan.

pixapins.lan.           86400   IN      NS      jabber.pixapins.lan.

jabber.pixapins.lan. 86400 IN   A

;; Query time: 3 msec
;; WHEN: Thu Nov 10 20:51:01 CET 2016
;; MSG SIZE  rcvd: 130

So, we got bind9 up and running!

Setting XMPP ejjaberd server

One the most shocking things I faced was to discover that the classic /etc/ejabberd/ejabberd.cfg DOES NO LONGER EXIST!!!
Apparently, since it is a monolithic, very long config file, it has been decided by project developers to migrate its format to .yml file format...
The decision isn't probably fresh news, since, as of Jessie release, the change is there, so now, config file is /etc/ejabberd/ejabberd.yml.
I'm a .json format enthusiast, old school .xml is pretty good for me too... but .yml is still somehow too much to me :-P

So, since the config file is quite long, here are the relevant excerpts to look into, and modify. Remember that, everything here onwards takes place somewhere at /etc/ejabberd/ejabberd.yml.
Changed parts are shown in order of aparition:

First section:

###   ================

## hosts: Domains served by ejabberd.
## You can define one or several, for example:
## hosts:
##   - ""
##   - ""
##   - ""
  - "localhost"
  - "pixapins.lan"

Second one:

###   ==============

## auth_method: Method used to authenticate the users.
## The default method is the internal.
## If you want to use a different method,
## comment this line and enable the correct ones.
auth_method: internal

## Store the plain passwords or hashed for SCRAM:
## auth_password_format: plain
auth_password_format: scram
## Define the FQDN if ejabberd doesn't detect it:
fqdn: "jabber.pixapins.lan"

Third one:

###.   ====================
  ## The 'admin' ACL grants administrative privileges to XMPP accounts.
  ## You can put here as many accounts as you want.
         - "admin": "localhost"
         - "admin": "pixapins.lan"

That's all changes needed for a very very basic functional domain xmpp service... so, restart the service as usual:

service ejabberd restart


Adding user jabber domain accounts

Now comes the funny part... try adding a pair of test users!
If everything is good, you can add users and specify you want them to be part of your domain.
ejabberd comes with a set of CLI management command tools provided with the installation. We will use the ejabberdctl register command.
Syntax is as follows:

ejabberdctl register USERNAME DOMAIN PASSWORD

Here's an example on the console:

root@jabber:~# ejabberdctl register testuser1 pixapins.lan secretpassword1
User testuser1@pixapins.lan successfully registered

And that's all folks...

Testing it works!

To test it all works, we need to add a pair of user accounts, then register them as accounts on your IM client, and create cross contacts between them... it may sound tricky, but can be easily explained:

Let's say you create testuser1@pixapins.lan and testuser2@pixapins.lan user accounts at the server terminal.
Ok, then add both accounts at your IM client, it should work automagically if your client has connectivity to the server on the same subnet... Accept the certificate, and go on!
Now comes the funny part...
Add a buddy/contact, indicating testuser2 as user name and pixapins.lan as domain, and associate it to testuser1@pixapins.lan account.
Now, inversely, Add a buddy/contact, indicating testuser1 as user name and pixapins.lan as domain, and associate it to testuser2@pixapins.lan account.
Now, you'll have two contacts of your own server at your IM client!!!
Try to start a conversation on either of them... if you chat to contact testuser1@pixapins.lan you'll do from its associated source account testuser2@pixapins.lan, and vice-versa, so, you can chat from one chat to another... weird!