Kamailio is one of the most popular open-source SIP (Session Initiation Protocol) servers used for VoIP (Voice over IP) calls and real-time communication. Kamailio, previously known as OpenSER, allows for advanced control over SIP calls, their routing and security. Due to its high scalability and flexibility, it is used in systems with a very large number of users, such as VoIP service providers, communication platforms, as well as in corporate telecommunications infrastructures.
Kamailio is written in C and can handle millions of calls simultaneously, making it a suitable choice for large deployments. It offers advanced features such as authentication, call quality control, rule-based routing, database integration, as well as support for protocols such as WebSocket, XMPP, and others.
In this series of posts, I will take you through a step-by-step guide on how to install and configure Kamailio so you can take full advantage of this powerful tool.
First, let’s start by installing Kamailio 6 on Debian 12 with MySQL support.
Spis treści
1) Prerequisites
Here the matter is quite simple, because the only requirement is actually the installation of the operating system. When installing Debian 12, remember to set a static IP address.
If you forgot about it during the installation stage, you can simply edit the /etc/network/interfaces file. Its contents will probably be similar to the following.
At the time of writing this post, our Debian would have installed Kamailio 5.6.3 by default. We can check this with the command:
apt search kamailio
As Kamailio version 6.0.0 was announced in January 2025, we install a newer version of the software (https://www.kamailio.org/w/2025/01/kamailio-v6-0-0-released/). First, however, we need to add a new repository to our operating system.
To do this, we will first install a few packages:
apt -y install gpg curl
Next, we will add the Kamailio gpg key to our keyring and create a kamailio.list file with the new repository data.
curl -s https://deb.kamailio.org/kamailiodebkey.gpg | gpg --no-default-keyring --keyring gnupg-ring:/usr/share/keyrings/kamailiodebkey.gpg --import && chmod 644 /usr/share/keyrings/kamailiodebkey.gpg
echo "deb [signed-by=/usr/share/keyrings/kamailiodebkey.gpg] http://deb.kamailio.org/kamailio60 bookworm main" | tee -a /etc/apt/sources.list.d/kamailio.list
Hint
Of course, you can also install another version of Kamailio by changing the kamailio60 to e.g. kamailio58 in the file /etc/apt/sources.list.d/kamailio.list
Now that the new repository has been added, let’s refresh the information.
apt update
From now on, the command apt search kamailio will find us the latest version of the software.
2) Kamailio installation
Now that the repository is ready, we can install Kamailio using the command:
apt -y install kamailio kamailio-mysql-modules gdb
This will install both the software itself and the MySQL support modules and the gdb compiler, which we can use for debugging if necessary.
After installation, Kamailio will be launched automatically. To be sure, we will make sure that our software is already running and add it to autostart.
systemctl status kamailio
systemctl enable kamailio
From now on you can use kamctl commands e.g. to monitor a service.
Hint
If the system does not find commands such as kamailio or kamctl, check your system $PATH paths and possibly add support for /usr/sbin/ in the /etc/profile or $HOME/.profile file.
Hint
If the kamctl monitor command throws a column: not found error, it does not indicate a problem with the database, but rather a missing column command.
If the which column command does not show anything, install an additional package:
apt -y install bsdmainutils
After all this, the kamctl monitor command should work properly.
To be sure, you can check if the system is listening on port 5060.
3) Installing the MySQL database
Of course, there is nothing to stop you from staying at this stage and making changes to the /etc/kamailio/kamailio.cfg file itself. However, if you plan to use Kamailio as a SIP Proxy, SIP Registrar or similar, MySQL support will be irreplaceable.
Before installing the software, I recommend generating three secure passwords, e.g. using the https://www.avast.com/random-password-generator website
We need a password for 3 users (for configuration reasons, we do not recommend using the $ and ” characters in the password):
- root – the main database user, which we will use to create the next ones
- kamailio – the main user, which will be used to connect the service to the database
- kamailioro – an optional user with read-only permissions
Thus prepared, we can proceed to install the database.
apt -y install default-mysql-server
Then, using the mysql_secure_installation command, we will initially configure our database. During the configuration, you can answer yes to all questions and set a previously generated root password.
mysql_secure_installation
After installation, we will run our new service and add it to autostart.
systemctl start mysqld
systemctl enable mysqld
4) Generating Kamailio tables
Nothing makes us happier than ready-made scripts! And this time, Kamailio developers have prepared a ready-made script that will create both Kamailio users (kamailio and kamailioro) and all the necessary tables.
Before we run it, we need to prepare a few settings. In the /etc/kamailio/kamctlrc file, we recommend uncommenting the following lines and entering the following settings:
- SIP_DOMAIN – domain, e.g. server IP address
- DBENGINE – database engine
- DBRWUSER – username with read/write rights
- DBRWPW – user password with read/write rights
- DBROUSER – username with read-only rights
- DBROPW – user password with read-only rights
- CHARSET (optional) – character set to connect to the character database, e.g. latin1 (otherwise, the installer will ask for it)
A sample file content may look like this:
After entering the variables, we execute the script using the previously established root password (for the database, not the operating system), agreeing to create the selected tables.
kamdbctl create
To connect the created tables to Kamailio, it’s time to edit the main configuration file /etc/kamailio/kamailio.cfg. We recommend making a copy of it first.
cp /etc/kamailio/kamailio.cfg /etc/kamailio/kamailio.cfg-bak
In the /etc/kamailio/kamailio.cfg file itself, we suggest adding the following lines at the very beginning:
- #!define WITH_MYSQL – starts the connection to MySQL
- #!define WITH_AUTH – starts the possibility of authorization
- #!define WITH_USRLOCDB – allows permanent determination of the user’s location
In addition, in the line describing the connection to the database (starts with #!trydef DBURL "mysql:…), update the information about the data for the connection to the database.
The string "mysql://kamailio:kamailiorw@localhost/kamailio" used below is in the format: "base_engine://user:password@server_address/base_name"
Of course, everything will depend on the functionality and roles that it will run on the server. In any case, I recommend reviewing the kamailio.cfg file, which describes the entire syntax.
From now on, in every place in the code that uses a defined connection, you will be able to store information in the database.
There is nothing left for us to do but restart the service.
systemctl restart kamailio
From now on you can start registering SIP accounts and storing configuration in the database. To add a new user do:
kamctl add 101 password_for_101
5) First call
Since we are able to register SIP accounts, there is nothing stopping us from logging in two SIP accounts and making the first call.
For this purpose, let’s add one more user.
kamctl add 102 password_for_102
Once both accounts are registered, you can check which users are currently logged in using kamctl commands.
kamctl online # wyświetli aktualnie zalogowanych użytkowników
kamctl ul show 101 # wyświetli szczegóły lokalizacyjne dla danego konta
It’s that simple! From now on, accounts 101 and 102 can make calls within our environment.
Of course, this is where the fun begins! In the next post, you will see how to enable debugging in Kamailio and what software can help you track SIP packets.
Next post in the series: Kamailio part 2: Enable SIP monitoring and dialplan debug