SIP Trunking

Kamailio SIP Trunk Registration

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..

By Sara Weichhand

Kamailio SIP trunk registration: A complete setup guide

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.

Why use Kamailio for SIP registration?

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.

Prerequisites

Before getting started, ensure you have:

  • A Debian-like server (Ubuntu 20.04+ recommended)
  • Root or sudo access
  • Basic knowledge of SIP and Linux shell
  • A public IP address (if registering remote clients)
  • A Telnyx Mission Control Portal account for SIP trunk connectivity

For additional setup guidance, refer to the Telnyx SIP Trunking Quickstart documentation.

Installing Kamailio

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

Setting up the SQLite database

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

Required Kamailio parameters

The following table outlines the essential Kamailio parameters that must be configured for SIP registration to work properly:

ParameterFileValueDescription
DBENGINEkamctlrcSQLITEDatabase engine selection
DB_PATHkamctlrc/tmp/kamailio_sqlite.dbLocation of SQLite database file
SIP_DOMAINkamctlrcYour public IP or domainDomain for SIP URI construction
listenkamailio.cfgudp:<IP>:5060SIP signaling port and protocol
db_urlkamailio.cfgsqlite:///tmp/kamailio_sqlite.dbDatabase connection string
timer_intervalusrloc module60 (default)Seconds between timer runs
db_modeusrloc module0-4Database persistence mode
default_expiresregistrar module3600Default registration expiry (seconds)
min_expiresregistrar module60Minimum allowed expiry value

Configuring Kamailio for registration

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:

  • registrar: Handles SIP REGISTER requests
  • usrloc: Manages user location records (Address of Record)
  • auth_db: Provides authentication against a database

For production deployments, also consider enabling:

  • pike: Rate limiting to prevent DoS attacks
  • htable: Hash table for caching
  • permissions: IP-based access control

Kamailio usrloc module database modes

The usrloc module supports multiple database modes, each with different performance and persistence trade-offs. Choose based on your deployment requirements:

ModeValueBehaviorUse Case
No DB0Memory only, no persistenceDevelopment, high-performance testing
Write-Through1Immediate DB write on every changeHigh reliability, slower performance
Write-Back2Periodic DB sync via timerBalance of performance and persistence
DB-Only3No memory cache, DB queries onlyMulti-server with shared DB
DB-Readonly4Load from DB at startup, memory only at runtimeReplicated/clustered deployments

Configure the mode in your kamailio.cfg:

modparam("usrloc", "db_mode", 1)

Adding users for authentication

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.

Telnyx trunk settings mapping

When connecting Kamailio to Telnyx SIP Trunks, map these settings in your configuration:

Telnyx SettingKamailio EquivalentValue/Notes
SIP ServerOutbound proxysip.telnyx.com
SIP Portlisten port5060 (UDP) or 5061 (TLS)
Connection TypeAuthentication methodCredentials or IP-based
Usernameuacreg l_uuidFrom Telnyx portal
Passworduacreg auth_passwordFrom Telnyx portal
Codec Prioritymodparam codecsG.711, G.729, Opus
AnchorSiteOutbound routingLatency-based or specific region
Outbound Voice ProfileRouting rulesConfigured in Telnyx portal

For detailed configuration steps, consult the Telnyx SIP configuration guide and developer configuration guides.

Configuration options comparison

When setting up SIP registration, you have several architectural choices. Here's how they compare:

FeatureKamailio RegistrarDirect Provider RegistrationPBX Registration
NAT TraversalExcellent (built-in)Provider-dependentGood with proper config
ScalabilityHigh (thousands/sec)Limited by providerMedium
CustomizationFull controlLimitedVendor-specific
Database OptionsSQLite, MySQL, PostgreSQL, RedisN/AUsually fixed
AuthenticationDigest, TLS, IP-basedProvider credentialsInternal
FailoverConfigurableProvider-managedUsually built-in
CostOpen sourcePer-trunk feesLicense fees
ComplexityHigherLowMedium
Best ForLarge deployments, custom routingSimple setupsSMB unified comms

Security best practices




"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:

Enable digest authentication

route[AUTH] {
    if (!is_method("REGISTER|INVITE")) return;
    
    if (!auth_check("$fd", "subscriber", "1")) {
        auth_challenge("$fd", "0");
        exit;
    }
    consume_credentials();
}

Rate limiting with pike module

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;
    }
}

Block known malicious user agents

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.

Starting Kamailio

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

Setting up Zoiper softphone

  1. Download and install Zoiper from the app store on your Android device
  2. Open Zoiper and select Add account
  3. When asked whether there are a username and password, select Yes, then Manual configuration
  4. Choose SIP Account and configure:
    • Account name: Any descriptive name
    • Host: Kamailio host's public IP or domain name
    • Username: The username created with kamctl add
    • Password: The corresponding password

Once saved, registration should be successful. For alternative softphone options, see our guide on configuring Linphone with Telnyx.

Verifying registration

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

Integrating with Telnyx for PSTN connectivity

To connect your Kamailio registrar to the PSTN through Telnyx:

  1. Create a Telnyx account and complete verification
  2. Set up a SIP Connection with credential-based authentication
  3. Purchase phone numbers in the Mission Control Portal
  4. Configure Kamailio to route outbound calls through Telnyx

Learn more about SIP trunk setup in our step-by-step SIP trunk guide and understand SIP channels and how they work.

Next steps

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.

Additional resources

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.

Share on Social