Here we'll guide you through setting up Kamailio to be a SIP registrar. We'll also set up a softphone to register with Kamailio..

SIP trunk registration is a method for softphones to register with a VoIP system even when they have dynamic IP addresses or sit behind NAT. This guide walks through setting up Kamailio to function as a SIP registrar, configuring a softphone (Zoiper on Android) to register with Kamailio, and integrating this setup with Telnyx SIP Trunking for enterprise-grade voice connectivity.
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 and 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.
Kamailio is an open-source SIP server capable of handling thousands of calls per second. Unlike traditional PBX systems that bundle signaling with media and business logic, Kamailio focuses purely on SIP signaling, making it ideal for large-scale, distributed deployments. Whether you're building a conversational AI solution or scaling a VoIP infrastructure for small business, Kamailio provides the flexibility and performance you need.
For a deeper understanding of SIP trunking fundamentals, see our comprehensive SIP Trunking explained guide and learn about SIP vs VoIP differences.
Before getting started, ensure you have:
For additional setup guidance, refer to the Telnyx SIP Trunking Quickstart documentation.
Assuming a Debian-like server, Kamailio can be easily installed via apt-get. The registration feature of Kamailio requires a database. For simplicity, SQLite will be used in this example. Start by installing Kamailio and the associated SQLite module, along with the optional command line interface for SQLite (useful for querying the Kamailio database):
sudo apt-get install kamailio kamailio-sqlite-modules sqlite3
Open up the kamctlrc file with your preferred editor:
sudo nano /etc/kamailio/kamctlrc
Uncomment and set the following variables:
DBENGINE=SQLITE
DB_PATH="/tmp/kamailio_sqlite.db"
While editing the kamctlrc file, also set the SIP_DOMAIN variable. This is needed to run Kamailio and have a softphone register with it. The SIP_DOMAIN variable should be set to the Kamailio host's public IP or domain name:
SIP_DOMAIN=<Kamailio host's public IP or domain name>
At this point, create the database with the kamdbctl command:
kamdbctl create
The following table outlines the essential Kamailio parameters that must be configured for SIP registration to work properly:
| Parameter | File | Value | Description |
|---|---|---|---|
DBENGINE | kamctlrc | SQLITE | Database engine selection |
DB_PATH | kamctlrc | /tmp/kamailio_sqlite.db | Location of SQLite database file |
SIP_DOMAIN | kamctlrc | Your public IP or domain | Domain for SIP URI construction |
listen | kamailio.cfg | udp:<IP>:5060 | SIP signaling port and protocol |
db_url | kamailio.cfg | sqlite:///tmp/kamailio_sqlite.db | Database connection string |
timer_interval | usrloc module | 60 (default) | Seconds between timer runs |
db_mode | usrloc module | 0-4 | Database persistence mode |
default_expires | registrar module | 3600 | Default registration expiry (seconds) |
min_expires | registrar module | 60 | Minimum allowed expiry value |
Edit the main Kamailio configuration file:
sudo nano /etc/kamailio/kamailio.cfg
Enable the required modules by uncommenting or adding these lines:
#!define WITH_SQLITE
#!define WITH_USRLOCDB
The key modules you need for registration are:
For production deployments, also consider enabling:
The usrloc module supports multiple database modes, each with different performance and persistence trade-offs. Choose based on your deployment requirements:
| Mode | Value | Behavior | Use Case |
|---|---|---|---|
| No DB | 0 | Memory only, no persistence | Development, high-performance testing |
| Write-Through | 1 | Immediate DB write on every change | High reliability, slower performance |
| Write-Back | 2 | Periodic DB sync via timer | Balance of performance and persistence |
| DB-Only | 3 | No memory cache, DB queries only | Multi-server with shared DB |
| DB-Readonly | 4 | Load from DB at startup, memory only at runtime | Replicated/clustered deployments |
Configure the mode in your kamailio.cfg:
modparam("usrloc", "db_mode", 1)
To add users for authentication, use the kamctl utility:
kamctl add testuser testpassword
This creates a subscriber entry in the database. Users will authenticate using these credentials when their softphone registers.
When connecting Kamailio to Telnyx SIP Trunks, map these settings in your configuration:
| Telnyx Setting | Kamailio Equivalent | Value/Notes |
|---|---|---|
| SIP Server | Outbound proxy | sip.telnyx.com |
| SIP Port | listen port | 5060 (UDP) or 5061 (TLS) |
| Connection Type | Authentication method | Credentials or IP-based |
| Username | uacreg l_uuid | From Telnyx portal |
| Password | uacreg auth_password | From Telnyx portal |
| Codec Priority | modparam codecs | G.711, G.729, Opus |
| AnchorSite | Outbound routing | Latency-based or specific region |
| Outbound Voice Profile | Routing rules | Configured in Telnyx portal |
For detailed configuration steps, consult the Telnyx SIP configuration guide and developer configuration guides.
When setting up SIP registration, you have several architectural choices. Here's how they compare:
| Feature | Kamailio Registrar | Direct Provider Registration | PBX Registration |
|---|---|---|---|
| NAT Traversal | Excellent (built-in) | Provider-dependent | Good with proper config |
| Scalability | High (thousands/sec) | Limited by provider | Medium |
| Customization | Full control | Limited | Vendor-specific |
| Database Options | SQLite, MySQL, PostgreSQL, Redis | N/A | Usually fixed |
| Authentication | Digest, TLS, IP-based | Provider credentials | Internal |
| Failover | Configurable | Provider-managed | Usually built-in |
| Cost | Open source | Per-trunk fees | License fees |
| Complexity | Higher | Low | Medium |
| Best For | Large deployments, custom routing | Simple setups | SMB unified comms |
"The default Kamailio config is not production-ready. You must enable authentication, rate limiting, and strict header validation to secure your server. When users are allowed to create their own passwords, there will be weak passwords—at thousands of SIP packets per second, it's worthwhile for attackers to guess credentials."
— Daniel-Constantin Mierla, Co-Founder and Core Developer, Kamailio Project
Implement these security measures for production deployments:
route[AUTH] {
if (!is_method("REGISTER|INVITE")) return;
if (!auth_check("$fd", "subscriber", "1")) {
auth_challenge("$fd", "0");
exit;
}
consume_credentials();
}
modparam("pike", "sampling_time_unit", 2)
modparam("pike", "reqs_density_per_unit", 16)
modparam("pike", "remove_latency", 4)
route[PIKE] {
if (!pike_check_req()) {
xlog("L_ALERT", "PIKE: Blocking $si\n");
exit;
}
}
if ($ua =~ "(friendly-scanner|sipvicious|sipcli)") {
xlog("L_WARN", "Blocked scanner from $si\n");
exit;
}
For comprehensive security guidance, review the Kamailio Security Wiki and NIST SP 800-58: Security Considerations for VoIP Systems.
After completing the configuration, start the Kamailio service:
sudo systemctl start kamailio
sudo systemctl enable kamailio
Check the status to ensure it's running:
sudo systemctl status kamailio
kamctl addOnce saved, registration should be successful. For alternative softphone options, see our guide on configuring Linphone with Telnyx.
On the Kamailio side, use the SQLite command line interface to verify successful registration:
sqlite3 /tmp/kamailio_sqlite.db
sqlite> SELECT * FROM location;
Successfully registered users will appear in the location table with their contact information, including the device's current IP address and port.
You can also use the kamcmd tool to dump user locations:
kamcmd ul.dump
To connect your Kamailio registrar to the PSTN through Telnyx:
Learn more about SIP trunk setup in our step-by-step SIP trunk guide and understand SIP channels and how they work.
This setup provides a foundation for using Kamailio as a SIP registrar. From here, you can:
For additional learning, the Nick vs Networking Kamailio 101 series provides excellent tutorials on Kamailio configuration.
To learn more about SIP Trunking and its uses, explore our SIP Trunking page or test it yourself in the Telnyx Mission Control Portal.
Have questions about SIP trunk registration in Kamailio? Join our subreddit.
Related articles