SIP Trunk Registration is a method for Softphones to register with a VoIP system even though they may have dynamic IP addresses or may be behind NAT.
This blog entry will go through setting up Kamailio to be a SIP registrar. It will also briefly set up a softphone (namely Zoiper on Android) to register with Kamailio.
Once configured, the softphone will register periodically (typically every 60 seconds) with the Kamailio host on port 5060. Since registration takes place so frequently, Kamailio will be able to detect if the softphone IP changes and continue to route calls to/from it. Additionally, since it’s the softphone that’s reaching out to Kamailio when sending calls to the softphone, Kamailio can just point to the softphone IP and ephemeral port allowing it to reach the softphone even if it’s behind NAT.
Assuming a Debian-like server, Kamailio can be easily installed via apt-get. The registration feature of Kamailio will require the use of a database - for simplicity, SQLite will be used in this example.
Start by installing Kamailio and the associated SQLite module, optionally the command line interface for SQLite which can be useful for poking around the Kamailio database:
1$ sudo apt-get install kamailio kamailio-sqlite-modules sqlite3
2. Database Creation
Next, set up the SQLite database. Open up the kamctlrc file with a preferred editor:
1$ sudo vim /etc/kamailio/kamctlrc
variable and set it to
And set the
variable to somewhere writable by Kamailio (
works for this example):
While editing the
file, now would be a good time to also set the variable
. This is not strictly needed to create the database but will be needed later to actually run Kamailio and have a SoftPhone register with it. The
variable will need to be set to the Kamailio host’s public IP or domain name:
1SIP_DOMAIN=<Kamailio host’s public IP or domain name>
At this point, the database can be created with the kamdbctl command. The ownership of the file may also need to be changed to allow the Kamailio user read/write access to the database.
1$ sudo kamdbctl create 2$ sudo chown kamailio:kamailio /tmp/kamailio.db
3. Kamailio Configuration
Open up the
file with a preferred editor:
1$ sudo vim /etc/kamailio/kamailio.cfg
Add the following lines to the top of the
1#!define WITH_SQLITE 2#!define WITH_AUTH 3#!define WITH_USRLOCDB
In the Defined Values section, add the following block to set the database location for SQLite:
1#!ifdef WITH_SQLITE 2#!ifndef DBURL 3#!define DBURL "sqlite:///tmp/kamailio.db" 4#!endif 5#!endif
In the Modules Section, add the following block to have Kamailio to load the SQLite module:
1#!ifdef WITH_SQLITE 2loadmodule "db_sqlite.so" 3``#!endif
variable needs to be set to the Kamailio node’s public IP or domain name and port.
1alias=<Kamailio host’s public IP or domain name>:5060
That about covers the
file. The next thing to tackle is the Kamailio default file:
1$ sudo vim /etc/default/kamailio
Set the following variables to have the Kamailio service run as under the Kamailio user and group and to enable Kamailio to run
1RUN_KAMAILIO=yes 2USER=kamailio 3GROUP=kamailio
4. Adding a User to Kamailio
Next, add a user to Kamailio - this is the account the softphone will use to register with Kamailio
1$ sudo kamctl add testuser testpasswd
At this point,
command line interface can be used to poke around the database. Specifically, the
table will have a list of users that should be able to register, e.g:
1$ sqlite3 /tmp/kamailio.db 2SQLite version 18.104.22.168 2014-10-29 13:59:56 3Enter ".help" for usage hints. 4sqlite> select * from subscriber; 51|testuser|22.214.171.124|testpasswd||2215e221e0006cdf04ed82aa 6a0b9c366|d0a735afa4fc0bb97805e5f82da52736| 7sqlite>
5. Setup Softphone (Zoiper on Android)
Zoiper is a softphone that can be installed from the Google Play store. Once installed, start up Zoiper and navigate to Config and then Accounts.
Next select Add account, and on the dialog that asks whether or not there are a username and password, select Yes , and then Manual configuration.
Choose SIP Account and set the Account name , Host , Username and Password.
The Username and Password should be the same as used in step 4 above, and Host should point to the Kamailio instance’s IP or domain. Once the account is saved, registration should be successful.
On the Kamailio side,
command line interface can be used to also check for successful registration. Successfully registered users will show up in the
1$ sqlite3 /tmp/kamailio_sqlite.db 2SQLite version 126.96.36.199 2014-10-29 13:59:56 3Enter ".help" for usage hints. 4sqlite> select * from location; 51|uloc-56561efc-27ec-b|testuser||sip:[email protected]:44449;transport=UDP;rinstance=acddf60257622f19| 6|2457352.40403356|-1.0|YJboWl_-kBRQd1Zt03ojJA..|4|2457352.40333912|0|0|Zoiper r34646|udp:10.240.0.2:5060|5087||0 7sqlite>
That should be enough to get one started using Kamailio as a registrar. A future entry will cover integrating the aforementioned set up with FreeSWITCH and what the call flow looks like moving between the pieces.
Share on Social