Kamailio SIP Server

Kamailio (former OpenSER) is an Open Source SIP Server.

“To know Kamailio is to know SIP.” – Fred Posner

A Quick Introduction to Kamailio, by Olle E Johansson

Note: AstLinux 1.2.0 or later is required, with custom build

Initial Configuration

The CLI (Command Line Interface) must be used to enable, and disable kamailio. Kamailio will be enabled if the /mnt/kd/kamailio/kamailio.cfg file exists. On first install, issue the command…

cp -a /stat/etc/kamailio /mnt/kd/

The /mnt/kd/kamailio/ directory now exists, populated with a default configuration, including kamailio.cfg . Start kamailio with the following command, this will also create a symlink from /etc/kamailio//mnt/kd/kamailio/

service kamailio init

You should see output similar to:

Starting kamailio...
loading modules under /usr/lib/kamailio/modules/
Listening on 
             udp: 127.0.0.1:5065
Aliases: 
             udp: localhost:5065

Not all configurations will require a database, though at this point you can create a SQLite database with the standard schema. Issue the command…

kamdbctl create

You should see output similar to:

INFO: creating database /mnt/kd/kamailio/data/kamailio.sqlite3 ...
INFO: Core Kamailio tables succesfully created.
Install presence related tables? (y/n): y
INFO: creating presence tables into /mnt/kd/kamailio/data/kamailio.sqlite3 ...
INFO: Presence tables succesfully created.
Install tables for imc cpl siptrace domainpolicy carrierroute
		userblacklist htable purple uac pipelimit mtree sca mohqueue
		rtpproxy? (y/n): y
INFO: creating extra tables into /mnt/kd/kamailio/data/kamailio.sqlite3 ...
INFO: Extra tables succesfully created.

At this point you can customize your kamailio configuration. Edit the /etc/kamailio/kamailio-local.cfg file to add switches such as “#!define WITH_ASTERISK” and interfaces/ip's to listen on. More detailed examples are described below. Apply any edits to the files in /etc/kamailio/ with the command…

service kamailio restart

Tip → The web interface may be used to Edit the configuration and Restart Kamailio.

While the default configuration files in the /stat/etc/kamailio/ directory are typically only used one time for initial configuration, the files are a good reference using “diff -u” with your custom configuration.

Note → On devices with slower storage (like Soekris net5501 and Alix 2D13) you might experience database locking issues, when using the SQlite database in some use cases.

Configuration Examples


Kamailio proxy's SIP but Asterisk does the RTP directly:

Example: EXTIP 10.10.50.65 - DNS 'pbx4', INTIP 192.168.110.1/24 network

/etc/kamailio/kamailio-local.cfg:

####### Include Local Config #########

#!define WITH_ASTERISK

auto_aliases=no
alias="pbx4"
listen=udp:127.0.0.1:5060
listen=udp:10.10.50.65:5060
listen=udp:192.168.110.1:5060

/etc/asterisk/sip.conf snippet:

udpbindaddr=0.0.0.0:5080

Note → Requires firewall Pass EXT→Local UDP 10000-20000 (default asterisk rtp.conf range)


Kamailio proxy's SIP and RTP using rtpproxy:

Example: EXTIP 10.10.50.65 - DNS 'pbx4', INTIP 192.168.110.1/24 network

/etc/kamailio/kamailio-local.cfg:

####### Include Local Config #########

#!define WITH_NAT
#!define WITH_ASTERISK

auto_aliases=no
alias="pbx4"
listen=udp:127.0.0.1:5060
listen=udp:10.10.50.65:5060
listen=udp:192.168.110.1:5060

/etc/asterisk/sip.conf snippet:

udpbindaddr=127.0.0.1:5080

Tip → The 'rtpproxy' daemon is automatically started when WITH_NAT is defined.

Note → Requires firewall Pass EXT→Local UDP 16384-16639 (default rtpproxy range)