
This article provides a guide demonstrating how to deploy Kamailio on Ubuntu VPS.
Kamailio is a high-performance SIP (Session Initiation Protocol) server used for VoIP infrastructures, SIP trunking, IMS deployments, SBCs, and large-scale telecommunications platforms. It can handle thousands of concurrent calls while maintaining low resource usage.
This guide demonstrates how to deploy Kamailio 6.x on an Ubuntu VPS using the official Kamailio repositories.
Prerequisites
Before attempting to deploy Kamailio on Ubuntu VPS, ensure you have:
- Ubuntu 22.04 or Ubuntu 24.04 VPS
- Root or sudo access
- Public IP address
- Minimum:
- 2 GB RAM
- 2 CPU cores
- 20 GB storage
- Firewall access to open SIP ports
Compare Ubuntu VPS Plans
How to Deploy Kamailio on Ubuntu VPS
To deploy Kamailio on Ubuntu VPS, follow the steps outlined below:
-
Update the Server
Update all installed packages:
sudo apt update sudo apt upgrade -y
Install required utilities:
sudo apt install -y curl gnupg2 wget
-
Add the Official Kamailio Repository
Import the Kamailio repository signing key:
curl -fsSL https://deb.kamailio.org/kamailiodebkey.gpg | \ sudo gpg --dearmor -o /usr/share/keyrings/kamailio.gpg
For Ubuntu 24.04 (Noble):
echo "deb [signed-by=/usr/share/keyrings/kamailio.gpg] https://deb.kamailio.org/kamailio60 noble main" | \ sudo tee /etc/apt/sources.list.d/kamailio.list
For Ubuntu 22.04 (Jammy):
echo "deb [signed-by=/usr/share/keyrings/kamailio.gpg] https://deb.kamailio.org/kamailio60 jammy main" | \ sudo tee /etc/apt/sources.list.d/kamailio.list
The Kamailio project maintains official repositories for Kamailio 6.x releases on Ubuntu and Debian systems.
Update package indexes:
sudo apt update
-
Install Kamailio 6
Install the core package:
sudo apt install -y kamailio
Verify installation:
kamailio -V
Example output:
version: kamailio 6.0.x
-
Install Useful Kamailio Modules
For most production deployments, install additional modules:
sudo apt install -y \ kamailio-mysql-modules \ kamailio-tls-modules \ kamailio-websocket-modules \ kamailio-utils-modules
These modules provide:
Module Purpose MySQL User authentication and location storage TLS Secure SIP over TLS WebSocket WebRTC support Utils Administrative tools -
Configure Firewall
Open SIP ports:
sudo ufw allow 5060/udp sudo ufw allow 5060/tcp sudo ufw allow 5061/tcp
Enable firewall:
sudo ufw enable
Verify:
sudo ufw status
-
Configure Kamailio
Backup the default configuration:
sudo cp /etc/kamailio/kamailio.cfg \ /etc/kamailio/kamailio.cfg.backup
Edit configuration:
sudo nano /etc/kamailio/kamailio.cfg
Locate the listening directive and configure your VPS IP:
listen=udp:YOUR_SERVER_IP:5060
Example:
listen=udp:203.0.113.10:5060
Set server alias:
alias="sip.example.com"
Replace with your actual domain.
-
Enable Database Support (Optional)
Install MariaDB:
sudo apt install -y mariadb-server
Secure database:
sudo mysql_secure_installation
Edit Kamailio database settings:
sudo nano /etc/kamailio/kamctlrc
Configure:
DBENGINE=MYSQL DBHOST=localhost SIP_DOMAIN=sip.example.com
Create Kamailio database:
sudo kamdbctl create
Follow the prompts to create:
- Database
- Tables
- Permissions
Database-backed deployments are commonly used for subscriber authentication, registration storage, and accounting.
-
Enable Authentication Modules
Open:
sudo nano /etc/kamailio/kamailio.cfg
Enable the following definitions near the top:
#!define WITH_MYSQL #!define WITH_AUTH #!define WITH_USRLOCDB #!define WITH_ACCDB
These enable:
- Database storage
- SIP authentication
- User location services
- Call accounting
-
Validate Configuration
Before restarting Kamailio:
sudo kamailio -c
Expected result:
configuration file OK
Fix any reported syntax errors before proceeding.
-
Start Kamailio
Enable service at boot:
sudo systemctl enable kamailio
Start service:
sudo systemctl start kamailio
Check status:
sudo systemctl status kamailio
You should see:
Active: active (running)
Kamailio includes native systemd service files for modern Ubuntu deployments.
-
Create a SIP User
Add a SIP account:
sudo kamctl add testuser password123
Verify:
sudo kamctl ul show
-
Test SIP Registration
Configure a SIP softphone such as:
Use:
Username: testuser Password: password123 Domain: sip.example.com Port: 5060 Transport: UDP
Attempt registration.
Monitor logs:
sudo journalctl -u kamailio -f
-
Monitor SIP Traffic
Install sngrep:
sudo apt install -y sngrep
Launch:
sudo sngrep
You can now watch:
- REGISTER requests
- INVITE messages
- SIP responses
- Call flows
-
Enable SIP over TLS
TLS encrypts SIP signaling traffic, protecting registrations, authentication credentials, and call setup messages.
Install TLS Modules
sudo apt install -y kamailio-tls-modules openssl
Create TLS Certificates
For production, use Let’s Encrypt.
Install Certbot:
sudo apt install -y certbot
Generate certificate:
sudo certbot certonly --standalone -d sip.example.com
Certificates will be stored in:
/etc/letsencrypt/live/sip.example.com/
Create Kamailio TLS Configuration
Create:
sudo nano /etc/kamailio/tls.cfg
Example:
[server:default] method = TLSv1.2+ private_key = /etc/letsencrypt/live/sip.example.com/privkey.pem certificate = /etc/letsencrypt/live/sip.example.com/fullchain.pem ca_list = /etc/ssl/certs/ca-certificates.crt verify_certificate = no require_certificate = no
Enable TLS in Kamailio
Edit:
sudo nano /etc/kamailio/kamailio.cfg
Enable:
#!define WITH_TLS
Add TLS listener:
listen=tls:YOUR_SERVER_IP:5061
Load TLS module if not already loaded:
loadmodule "tls.so" modparam("tls", "config", "/etc/kamailio/tls.cfg")Open Firewall
sudo ufw allow 5061/tcp
Validate Configuration
sudo kamailio -c
Restart Kamailio:
sudo systemctl restart kamailio
Verify:
sudo ss -tlnp | grep 5061
Expected:
LISTEN 0 128 0.0.0.0:5061
Configure Softphones
Set:
Transport: TLS Port: 5061
You should now see TLS registrations in:
sudo sngrep
-
Install and Configure RTPEngine
RTPEngine provides media proxying for:
- NAT traversal
- SRTP support
- WebRTC
- Codec transcoding
- RTP anchoring
Install RTPEngine
Ubuntu package:
sudo apt install -y rtpengine
Configure Kernel Module
Load:
sudo modprobe xt_RTPENGINE
Verify:
lsmod | grep RTPENGINE
Configure RTPEngine
Edit:
sudo nano /etc/rtpengine/rtpengine.conf
Example:
[rtpengine] table = 0 interface = public/YOUR_PUBLIC_IP listen-ng = 127.0.0.1:2223 port-min = 10000 port-max = 20000 foreground = false
Open RTP Ports
sudo ufw allow 10000:20000/udp
Start RTPEngine
sudo systemctl enable rtpengine sudo systemctl restart rtpengine
Verify:
sudo systemctl status rtpengine
Enable RTPEngine in Kamailio
Install module:
sudo apt install -y kamailio-extra-modules
Verify:
ls /usr/lib/x86_64-linux-gnu/kamailio/modules/rtpengine.so
Add to
kamailio.cfg:loadmodule "rtpengine.so" modparam("rtpengine", "rtpengine_sock", "udp:127.0.0.1:2223")Route SIP Traffic Through RTPEngine
Inside
request_route:if (is_method("INVITE")) { rtpengine_offer(); } if (is_method("BYE")) { rtpengine_delete(); }Inside
onreply_route:if (status =~ "[12][0-9][0-9]") { rtpengine_answer(); }Validate:
sudo kamailio -c
Restart:
sudo systemctl restart kamailio
-
Configure SIP Load Balancing with Dispatcher
Kamailio’s Dispatcher module allows SIP traffic distribution across multiple PBX servers.
Example topology:
Internet | Kamailio | +----+----+ | | Asterisk1 Asterisk2Install Dispatcher Module
Usually included:
sudo apt install -y kamailio
Verify:
find /usr -name dispatcher.so
Enable Dispatcher
Add:
loadmodule "dispatcher.so" modparam("dispatcher", "list_file", "/etc/kamailio/dispatcher.list")Create Backend List
sudo nano /etc/kamailio/dispatcher.list
Example:
1 sip:10.0.0.11:5060 1 sip:10.0.0.12:5060 1 sip:10.0.0.13:5060
Group 1 contains three SIP servers.
Configure Round-Robin Routing
Add to
request_route:if (is_method("INVITE")) { if (!ds_select_dst("1", "4")) { send_reply("500", "No Destination"); exit; } t_relay(); exit; }Dispatcher algorithm values:
Value Algorithm 0 Hash Call-ID 2 Hash From URI 4 Round Robin 8 Random 10 Weight Based Recommended:
ds_select_dst("1", "4")for even distribution.
Enable Backend Health Checks
Add:
modparam("dispatcher", "ds_ping_interval", 30) modparam("dispatcher", "ds_probing_mode", 1)Kamailio will automatically probe servers and remove failed nodes from rotation.
Reload Dispatcher Without Restart
After editing
dispatcher.list:kamcmd dispatcher.reload
View status:
kamcmd dispatcher.list
Example:
SET: 1 sip:10.0.0.11:5060 ACTIVE sip:10.0.0.12:5060 ACTIVE sip:10.0.0.13:5060 ACTIVE
Recommended Production Architecture
Internet
|
TLS 5061 / UDP 5060
|
+----------------+
| Kamailio |
| Load Balancer |
+----------------+
|
RTPEngine
|
+---------------+---------------+
| |
+--------------+ +--------------+
| Asterisk #1 | | Asterisk #2 |
+--------------+ +--------------+
| |
SIP Users SIP Users
This architecture provides:
- SIP over TLS encryption
- RTP media anchoring via RTPEngine
- NAT traversal
- SIP load balancing
- High availability
- Horizontal scaling for thousands of concurrent calls
- WebRTC readiness (when combined with WSS and SRTP)
Useful Commands
Restart Kamailio:
sudo systemctl restart kamailio
Reload configuration:
sudo kamcmd cfg.reload
Check running processes:
ps aux | grep kamailio
View logs:
sudo journalctl -u kamailio
Next Steps
Once Kamailio is running successfully, consider adding:
-
- WebRTC support
- Dispatcher module
- Failover routing
- SBC functionality
- FreeSWITCH or Asterisk integration
These features transform Kamailio from a basic SIP proxy into a carrier-grade VoIP platform capable of handling large-scale deployments.
Conclusion
You now know how to deploy Kamailio on Ubuntu VPS.









