Back to articles
Technology Insight

Scaling Enterprise VoIP: How to Install and Configure Kamailio SIP Server on the Cloud

June 3, 2026

Introduction: The Challenge of Million-User VoIP Architecture

In the modern enterprise communication landscape, scalability is no longer a luxury—it is a foundational requirement. As organizations transition from legacy telephony to cloud-native Voice over IP (VoIP) infrastructures, traditional Private Branch Exchanges (PBXs) often become bottlenecks. When managing millions of concurrent sessions, a robust, carrier-grade Session Initiation Protocol (SIP) routing engine is essential. This is where Kamailio SIP Server excels.

Kamailio is an open-source SIP server capable of handling thousands of call setups per second. It acts as a stateless or stateful SIP proxy, load balancer, and security firewall. Unlike application servers like Asterisk or FreeSWITCH, which handle media processing and heavy business logic, Kamailio is built almost exclusively for high-throughput signaling. This blog post provides a comprehensive, step-by-step guide to installing, configuring, and optimizing Kamailio on a cloud environment to sustain millions of users.

1. Understanding the Cloud Architecture for Kamailio

Before diving into the installation, it is crucial to understand where Kamailio fits within a cloud topology. To support massive scale, a decoupled architecture is recommended. Kamailio sits at the edge of your network, acting as the primary entry point for all SIP traffic.

Architectural Principle: Separate your signaling plane from your media plane. Let Kamailio handle the SIP routing, while delegating media handling (RTP) to dedicated media servers like RTPEngine or RTProxy.

A typical cloud deployment includes:

  • Public Load Balancer / Floating IP: Distributes incoming SIP traffic across multiple Kamailio nodes.
  • Kamailio Edge Proxies: Handle registration, authentication, NAT traversal, and security.
  • Database Cluster: A highly available MySQL or PostgreSQL cluster to store user locations, profiles, and routing logic.
  • Media Server Pool: Back-end Asterisk or FreeSWITCH servers for voicemail, IVR, and conferencing.

2. Step-by-Step Installation on Ubuntu Server

For this guide, we will deploy Kamailio on an Ubuntu 24.04 LTS cloud instance. We will use the official Kamailio repositories to ensure we get the latest stable version with security patches.

Step 2.1: Update System and Add Repositories

First, update your local package index and install the necessary prerequisites:

sudo apt update && sudo apt install -y gnupg2 wget curl debian-keyring debian-archive-keyring

Next, import the Kamailio GPG key and add the official repository to your system sources:

wget -O- [https://deb.kamailio.org/kamailio.key](https://deb.kamailio.org/kamailio.key) | sudo gpg --dearmor -o /usr/share/keyrings/kamailio-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/kamailio-archive-keyring.gpg] [http://deb.kamailio.org/kamailio57](http://deb.kamailio.org/kamailio57) noble main" | sudo tee /etc/apt/sources.list.d/kamailio.list

Step 2.2: Install Kamailio and Core Modules

Update your package lists again and install the core Kamailio packages along with the database modules:

sudo apt update
sudo apt install -y kamailio kamailio-mysql-modules kamailio-tls-modules kamailio-websocket-modules

Verify the installation by checking the version:

kamailio -v

3. Configuring the Database Backend

Kamailio uses a database to manage subscriber provisioning, location tracking (lookups), and routing policies. We will use MySQL for this setup.

Step 3.1: Edit kamctlrc

Before creating the database, you need to configure the Kamailio control tool. Open /etc/kamailio/kamctlrc and uncomment or modify the following lines to match your database settings:

DBENGINE=MYSQL
DBHOST=localhost
DBNAME=kamailio
DBRWUSER=kamailio
DBRWPW="YourSecurePassword"
SIP_DOMAIN=your.cloud.domain.com

Step 3.2: Create the Kamailio Database

Run the Kamailio database creation script. It will prompt you to confirm the creation of tables for core functions, presence, and extra features. Answer Y (Yes) to all prompts:

sudo kamdbctl create

4. Customizing kamailio.cfg for Cloud Deployment

The main configuration file is located at /etc/kamailio/kamailio.cfg. Due to the complexities of cloud networking—specifically Network Address Translation (NAT)—specific parameters must be explicitly defined.

Step 4.1: Enable Essential Modules

At the very top of kamailio.cfg, add the following directives to enable MySQL, authentication, and NAT traversal:

#!define WITH_MYSQL
#!define WITH_AUTH
#!define WITH_USRLOCDB
#!define WITH_NAT

Step 4.2: Handle NAT and Cloud IPs

Cloud instances typically have a private IP mapped to a public IP. Kamailio must be aware of both to route SIP messages correctly. Find the listen directive and configure it as follows:

listen=udp:10.0.0.5:5060 advertise 203.0.113.50:5060

In this example, 10.0.0.5 represents the internal cloud IP, and 203.0.113.50 represents the public facing IP address.

5. Performance Tuning for Millions of Users

Out-of-the-box configurations are not optimized for large-scale enterprise deployments. To handle millions of users, Kamailio requires deep kernel and application-level tuning.

5.1: Memory Management

Kamailio uses two types of memory: Private Memory (pkg) for individual processes and Shared Memory (shm) shared across all processes. Edit /etc/default/kamailio to scale these values based on your cloud hardware:

# Allocate 4GB of Shared Memory and 32MB of Private Memory
MEMORY_SHM=4096
MEMORY_PKG=32

5.2: Increasing Process Workers

By default, Kamailio forks a small number of worker processes. For heavy production traffic, increase the child processes in kamailio.cfg to match your CPU core count:

children=16

5.3: Linux Kernel Optimization

Add the following network stack optimizations to /etc/sysctl.conf to prevent packet loss under high SIP traffic volume:

net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
et.core.netdev_max_backlog = 10000
net.ipv4.udp_mem = 8388608 12582912 16777216

Apply the changes using sudo sysctl -p.

Conclusion and Next Steps

You have now deployed and configured a carrier-grade Kamailio SIP server tailored for cloud operations. By separating the signaling plane from media, properly handling cloud NAT, and tuning memory allocations, your infrastructure is primed to scale efficiently. As a next phase, consider integrating RTPEngine for robust media proxying and establishing an Anycast IP setup to achieve geographical redundancy and true high availability.

Scaling Enterprise VoIP: How to Install and Configure Kamailio SIP Server on the Cloud | DPTCloud