Friday 2 June 2017

OpenSIPS server installation

OpenSIPS is an open source SIP proxy server. This post will go through bringing up a working OpenSIPS istallation on Ubuntu 16.04 LTS. First we will install OpenSIPS and then verify that the installation by performing a SIP Registration using a CLI based SIP phone called linphone (specifically linphonec, the CLI version of the SIP phone)

Installing OpenSIPS


1. Adding keys: First fire the following commands in succession on the terminal to setup the keys and repositories for installation:

  apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 049AD65B
  echo "deb http://apt.opensips.org jessie 2.3-releases" >> /etc/apt/sources.list
  apt-get update

The above commands are explained below: 
a. The first command adds the keys from the keyserver.
b. Then we add the opensips repository to the sources.list file so that apt-get can locate the OpenSIPS server.
c. Then we update the package list available at the newly added repository by firing "apt-get update".
   
root@ubuntu:~# apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 049AD65B
Executing: /tmp/tmp.bZeJxENy5e/gpg.1.sh --keyserver
keyserver.ubuntu.com
--recv-keys
049AD65B
gpg: requesting key 049AD65B from hkp server keyserver.ubuntu.com
gpg: key 049AD65B: public key "OpenSIPS Project <info@opensips.org>" imported
gpg: Total number processed: 1
gpg:               imported: 1  (RSA: 1)
root@ubuntu:~#
root@ubuntu:~# echo "deb http://apt.opensips.org jessie 2.3-releases" >> /etc/apt/sources.list
root@ubuntu:~#
root@ubuntu:~# apt-get update
.
.
root@ubuntu:~#

2. Installing OpenSIPS:  Now install opensips with the apt-get command.

apt-get install opensips

root@ubuntu:~# apt-get install opensips
.
.
root@ubuntu:~#

3. Editing the OpenSIPS Config file: The OpenSIPS config file is located at "/etc/opensips/opensips.cfg". In the file we need to replace the IP at which we want OpenSIPS to listen. This is done by replacing the IP in the line mentioning "listen" with the IP address at which you want OpenSIPS to listen(this will be an IP address at an interface in the machine). As we can see below the line is conveniently marked with a comment "CUSTOMIZE ME" to allow it to be easily searchable.

 41
 42 listen=udp:127.0.0.1:5060   # CUSTOMIZE ME
 43

So, replace line 42 to the following replacing the IP address to your IP address.

listen=udp:172.16.76.132:5060

The relevant portion of the config file now looks like this:

 41
 42 listen=udp:172.16.76.132:5060   # CUSTOMIZE ME
 43


4. Start OpenSIPS: Start OpenSIPS server with the command "service opensips start"

root@ubuntu:~# service opensips start
root@ubuntu:~#

5. Verify OpenSIPS is running: Verify that OpenSIPS is running with the "netstat -tulpn" command. The following output shows that OpenSIPS is running on port 5060 for SIP over UDP.


REGISTER a client


Now to verify that OpenSIPS is indeed running properly we will use a SIP phone called linphone to register to the OpenSIPS server. To follow this we first install linphonec, the CLI version of the linphone client, by following the steps given below.  (Note: I installed linphonec on a different machine but it can be done on the same machine that is running OpenSIPS as well)

1. Install linphonec: Fire command "apt-get install linphone-nogtk"

root@ubuntu:~# apt-get install linphone-nogtk
Reading package lists... Done
Building dependency tree     
.
.
.
root@ubuntu:~#


2. Register to OpenSIPS server using linphone client:

a. Start linphonec by firing command "linphonec"
b. Send a REGISTER message to OpenSIPS server by firing "register sip:user1@172.16.76.132 sip:172.16.76.132:5060". The IP address used here is the IP address of the OpenSIPS server. The username can be set to whatever is desired. The Registration successful messages conveys that the client successfully registered

root@ubuntu:~# linphonec
ALSA lib conf.c:4738:(snd_config_expand) Unknown parameters 0
ALSA lib control.c:954:(snd_ctl_open_noupdate) Invalid CTL default:0
XDG_RUNTIME_DIR (/run/user/1000) is not owned by us (uid 0), but by uid 1000! (This could e g happen if you try to connect to a non-root PulseAudio as a root user, over the native protocol. Don't do that.)
Ready
Warning: video is disabled in linphonec, use -V or -C or -D to enable.
linphonec> register sip:user1@172.16.76.132 sip:172.16.76.132:5060
linphonec> Registration on <sip:172.16.76.132:5060> successful.
linphonec>
root@ubuntu:~#

3. Crossverify client is registered at the OpenSIPS server: Now to crossverify that the client is registered, lets check the list of users currently registered to OpenSIPS.

On a terminal on the OpenSIPS machine fire the command "./opensipsctl ul show". It will show the currently registered users. As we can see below the user "user1" is registered with the OpenSIPS server. The Contact header specifies the contact of the user as "sip:user1@172.16.76.131"

root@ubuntu:/usr/sbin# ./opensipsctl ul show
Domain:: location table=512 records=1
    AOR:: user1
        Contact:: sip:user1@172.16.76.131;line=34937d1b1e5e27a Q=
            ContactID:: 1829798454851812362
            Expires:: 3510
            Callid:: 1216646129
            Cseq:: 1
            User-agent:: Linphone/3.6.1 (eXosip2/4.1.0)
            State:: CS_NEW
            Flags:: 0
            Cflags::
            Socket:: udp:172.16.76.132:5060
            Methods:: 4294967295
root@ubuntu:/usr/sbin#


A tcpdump trace at the OpenSIPS server shows that the following were the SIP messages that were exchanged during REGISTRATION :

23:44:09.743014 IP (tos 0x68, ttl 64, id 37937, offset 0, flags [DF], proto UDP (17), length 404)
    172.16.76.131.sip > 172.16.76.132.sip: [udp sum ok] SIP, length: 376
    REGISTER sip:172.16.76.132 SIP/2.0
    Via: SIP/2.0/UDP 172.16.76.131:5060;rport;branch=z9hG4bK1833702289
    From: <sip:user1@172.16.76.132>;tag=674536071
    To: <sip:user1@172.16.76.132>
    Call-ID: 1216646129
    CSeq: 1 REGISTER
    Contact: <sip:user1@172.16.76.131;line=34937d1b1e5e27a>
    Max-Forwards: 70
    User-Agent: Linphone/3.6.1 (eXosip2/4.1.0)
    Expires: 3600
    Content-Length: 0
   
23:44:09.743656 IP (tos 0x10, ttl 64, id 31501, offset 0, flags [DF], proto UDP (17), length 431)
    172.16.76.132.sip > 172.16.76.131.sip: [bad udp cksum 0xf2d4 -> 0x7ff8!] SIP, length: 403
    SIP/2.0 200 OK
    Via: SIP/2.0/UDP 172.16.76.131:5060;received=172.16.76.131;rport=5060;branch=z9hG4bK1833702289
    From: <sip:user1@172.16.76.132>;tag=674536071
    To: <sip:user1@172.16.76.132>;tag=bfa0967ee99eeb3ff1f10d7eea5636c7.3367
    Call-ID: 1216646129
    CSeq: 1 REGISTER
    Contact: <sip:user1@172.16.76.131;line=34937d1b1e5e27a>;expires=3600
    Server: OpenSIPS (2.3.0 (x86_64/linux))
    Content-Length: 0
   
Thanks for reading!

1 comment:

  1. Doesn't it need mysql to register users? If yes, please share the configurations to add within opensips.
    I have tried registering user but it shows
    Warning: database engine not found: tried 'MYSQL'.

    ReplyDelete