Kamailio's dispatcher module is the standard way to load balance SIP traffic across multiple backend servers — Asterisk clusters, media servers, or SIP application servers. Here's how to configure it correctly and diagnose failures.
The dispatcher module (mod_dispatcher) provides load balancing and failover for SIP traffic in Kamailio. It maintains a list of destination servers, monitors their health via OPTIONS pings, and routes incoming requests according to a configurable algorithm. When a destination fails, dispatcher removes it from the active set and redistributes traffic.
Common use cases: distributing calls across multiple Asterisk servers, load balancing to a FreeSWITCH cluster, routing to geographically distributed media servers.
The first parameter of ds_select_dst() defines the algorithm:
For most PBX cluster deployments, algorithm 4 (weighted round robin) or 9 (round robin) works well. Use algorithm 0 (hash over callid) when you need call affinity — all re-INVITEs and BYEs must reach the same server as the INVITE.
Dispatcher sends OPTIONS pings to all destinations and marks them inactive if they don't respond. Key parameters:
Check destination health from the CLI:
All destinations showing DX (Disabled): The health check OPTIONS pings are failing. Check that your Asterisk/FreeSWITCH servers respond to OPTIONS from Kamailio's IP. Check firewall rules. Verify the ds_ping_from URI is valid on the destination.
Calls going to wrong server: Check algorithm selection. Algorithm 0 (callid hash) ensures affinity — re-INVITEs go to the same server. With round robin, mid-dialog requests may go to different servers unless you've implemented dialog-based routing.
Failover not working: Verify the failure_route is set with t_on_failure() before t_relay(). Check that ds_next_dst() is called in the failure route. Verify ds_inactive_threshold is low enough to detect failures quickly.
Reload after database changes:
Kamailio dispatcher is a load balancing module that distributes SIP traffic across multiple backend servers. It supports multiple algorithms (round robin, weighted, hash-based), automatic health checks via OPTIONS pings, and failover routing. Commonly used to balance calls across Asterisk or FreeSWITCH clusters.
Use kamcmd dispatcher.list to see all destinations and their status. AP means Active Probing, AX is Active not probing, IP is Inactive Probing (recovering), DX is Disabled. If destinations show DX, the OPTIONS health check pings are failing — check firewall rules and that backends respond to OPTIONS from Kamailio.
Set t_on_failure() before t_relay() in your routing script. In the failure_route, call ds_next_dst() to select the next available destination and re-relay. Handle 503 and 408 responses as failure triggers. Set ds_inactive_threshold=3 so failed servers are removed from the active pool after 3 missed health check pings.
Paste your Kamailio debug output or SIP trace into SIPSymposium. The analyzer identifies dispatcher routing failures, health check issues, and failover problems.