PBX · Kamailio 5.7+

Use DIDHub as a Kamailio dispatcher upstream

For high-volume deployments, Kamailio's dispatcher module load-balances outbound INVITEs across DIDHub's primary and secondary PoPs and fails over automatically. This tutorial shows the dispatcher list, module config, and routing logic.

/etc/kamailio/dispatcher.list

# groupid destination_uri flags priority attrs
1 sip:sip.didhub.io;transport=udp 0 100 weight=70;ping_from=sip:[email protected]
1 sip:sip-bk.didhub.io;transport=udp 0 50 weight=30;ping_from=sip:[email protected]

kamailio.cfg (relevant sections)

loadmodule "dispatcher.so"
loadmodule "auth.so"
loadmodule "auth_db.so"

modparam("dispatcher", "list_file", "/etc/kamailio/dispatcher.list")
modparam("dispatcher", "flags", 2)              # probing enabled
modparam("dispatcher", "ds_ping_interval", 30)
modparam("dispatcher", "ds_ping_method", "OPTIONS")
modparam("dispatcher", "ds_probing_threshold", 3)

route[OUTBOUND_PSTN] {
    # Pick best DIDHub PoP weighted by priority + alive status
    if (!ds_select_dst("1", "4")) {
        sl_send_reply("503", "All upstreams down");
        exit;
    }
    t_on_failure("DISPATCH_FAILOVER");
    t_relay();
}

failure_route[DISPATCH_FAILOVER] {
    if (t_check_status("5[0-9][0-9]")) {
        # 5xx from primary — retry next upstream
        ds_next_dst();
        t_on_failure("DISPATCH_FAILOVER");
        t_relay();
    }
}

Outbound auth (digest, when not using IP ACL)

Add uac_auth + uac_replace_from to handle 401 challenges from DIDHub:

loadmodule "uac.so"
modparam("uac", "auth_username_avp", "$avp(auser)")
modparam("uac", "auth_password_avp", "$avp(apass)")
modparam("uac", "auth_realm_avp", "$avp(arealm)")

# In your route logic before t_relay:
$avp(auser) = "trunk_xxxxx";
$avp(apass) = "<PASSWORD>";
$avp(arealm) = "sip.didhub.io";
uac_auth();

Verify dispatcher health

kamcmd dispatcher.list

# Expected:
SET 1
DEST sip:sip.didhub.io;transport=udp     PRIO 100  FLAGS AP  # A=active P=probed
DEST sip:sip-bk.didhub.io;transport=udp  PRIO 50   FLAGS AP

Ready to get a number?

Pick a DID in 130+ countries from $1.99/month. Activates instantly on most numbers.