Kamailio Dispatcher Algorithms: Full List for 2027
Every Kamailio dispatcher algorithm for ds_select_dst, from 0 to 16 and 64, by version, with what each needs and what an unknown number does.
By Arkay · Updated · Published

What are the Kamailio dispatcher algorithms?
The algorithms are the numbered selection methods passed as the second argument of ds_select_dst(set, alg). The number tells Kamailio how to pick one destination from the set: by hash, in turn, at random, by priority, by weight, by active calls or by latency.
ds_select_dst returns true if a new destination is set. It sets the destination URI, which is the outbound proxy, and leaves the SIP message unchanged. ds_select_domain rewrites the host and port of the Request-URI instead. The optional limit argument sets the maximum number of items stored in the XAVP list for later failovers. See the official dispatcher module documentation.
Which algorithm number does what, and in which version?
We compiled every value of alg from the official dispatcher documentation on November 15, 2026. The compiled list uses the stable, 5.8.x, 6.0.x, 6.1.x and development pages. It is a reading of published documentation, not a benchmark. Software documentation applies in every country.
"All four" in the table below means the 5.8.x, 6.0.x, 6.1.x and development pages.
| Number | What it does | What it needs | Listed in |
|---|---|---|---|
| 0 | Hash over Call-ID | Nothing extra | All four |
| 1 | Hash over From URI | Nothing extra | All four |
| 2 | Hash over To URI | Nothing extra | All four |
| 3 | Hash over Request-URI user | Nothing extra | All four |
| 4 | Round-robin | Nothing extra | All four |
| 5 | Hash over authorization username; round-robin if none is found | Credentials in the request | All four |
| 6 | Random destination | Nothing extra | All four |
| 7 | Hash over the content of pseudo-variables | hash_pvar module parameter | All four |
| 8 | Serial order by priority attribute | priority attribute | All four |
| 9 | Weight-based distribution | weight attribute, 1 to 100 (percent of calls) | All four |
| 10 | Call load: fewest active calls, INVITE only | duid attribute per address; ds_hash_size above 0 | All four |
| 11 | Relative weight distribution | rweight attribute, 1 to 100; optional cc=1 | All four |
| 12 | Parallel forking to every destination | Nothing extra | All four |
| 13 | Latency-optimized round-robin that favors higher-priority gateways | ds_ping_latency_stats set to 1 | All four |
| 14 | Round-robin if all destinations share one priority above 0, otherwise serial as in 8 | priority attribute | 6.1.x and development |
| 15 | SRV-style: lowest priority value first, calls split by weight within that level | priority and weight attributes | Development only |
| 16 | Pressure-based: lowest pressure wins, round-robin on ties | pressure attribute, changed through RPC | Development only |
| 64 | Round-robin that skips destinations by overload control rate | ocrate and ocmin attributes | 6.0.x, 6.1.x and development |
| Any other value | First entry in the set | None | All |
Algorithms 0 to 13 appear in all four pages. Algorithm 64 starts in 6.0.x, and algorithm 14 starts in 6.1.x. The 5.8.x page lists algorithms 0 to 13 only. Algorithms 15 and 16 appear only in the development branch, as of November 15, 2026. Neither is in the 6.1.x documentation.
Which Kamailio load balancing algorithms spread calls evenly?
Round-robin (algorithm 4) sends each request to the next destination in the set. Random (algorithm 6) picks a destination using rand(). Neither needs extra attributes, so they are the simplest to start with.
Call load distribution (algorithm 10) picks the destination with the fewest active calls. It needs a duid attribute on every address and ds_hash_size greater than 0. The documentation says it works only for INVITE requests. The advanced examples at the end show it in a configuration.
How do weight (9) and relative weight (11) differ?
Algorithm 9 is weight-based distribution. Each address takes a weight attribute from 1 to 100, which is the percentage of calls it receives. The weights should add up to 100. Destinations that push the sum over 100 are ignored. If the sum is less than 100, the last destination fills the missing percentage. An invalid weight is set to 0.
Algorithm 11 is relative weight distribution. It uses an rweight attribute from 1 to 100. An active host's share is its rweight divided by the sum of the rweights of all active hosts in the group. Weights of 1, 2 and 1 split 100 calls as 25%, 50% and 25%. If the third destination becomes inactive, the first and second take 33% and 67%, and the third gets 0%. Algorithm 11 can also enable congestion control with cc=1 on a destination.
Which algorithms keep a caller on the same destination?

The hashing algorithms do this. Algorithm 0 hashes over the Call-ID, 1 over the From URI, 2 over the To URI, 3 over the Request-URI user, 5 over the authorization username and 7 over the pseudo-variables named in hash_pvar. Algorithm 5 falls back to round-robin when no username is found.
The Call-ID contains a globally unique identifier for the call, so hashing over it keeps the messages of one call on one destination. The documentation calls the dispatcher stateless, but hashing algorithms still send later requests of the same dialog to the same destination. The documentation warns that hashing does not guarantee a fair distribution. Bit 1 of the flags parameter makes URI hashes use only the username part.
How do you set the ds_select_dst algorithm in kamailio.cfg?
Load the dispatcher module, point list_file at the destination list, and call ds_select_dst with a set id and an algorithm number. The default list path is /etc/kamailio/dispatcher.list or /usr/local/etc/kamailio/dispatcher.list, so the path below is an example.
In kamailio.cfg, the module is loaded and pointed at the list:
loadmodule "dispatcher.so"
modparam("dispatcher", "list_file", "/run/kamailio/dispatcher.list")
Each line of the list has a set id, a destination, flags, a priority and attributes. The addresses below are documentation examples. Set 1 has two gateways whose weights add up to 100.
In dispatcher.list, the two gateways of set 1 are:
1 sip:192.0.2.21 0 0 weight=50
1 sip:192.0.2.22 0 0 weight=50
In the route block of kamailio.cfg, the call is dispatched to set 1 with algorithm 9:
route[DISPATCH] {
if (!ds_select_dst("1", "9")) {
send_reply("404", "No destination");
exit;
}
route(RELAY);
}
route[RELAY] {
t_relay();
exit;
}
If ds_select_dst returns false, no destination was set, so the script replies 404. Otherwise the request goes to the destination URI that ds_select_dst set, and the RELAY route passes it on. t_relay() is a function of the tm module.
To check the loaded groups, use kamcmd from a shell:
kamcmd dispatcher.list
kamcmd dispatcher.reload
dispatcher.list lists the routing groups with their destination addresses and attributes. dispatcher.reload reloads the groups and destinations, but the documentation disables it for call load based dispatching (algorithm 10).
How do I fail over to the next destination when the selected one does not answer?

Failover needs bit 2 of the flags module parameter. With it set, the remaining addresses of the set are stored in XAVPs, and ds_next_dst() moves to the next one. The documentation's sample sets flags to 2 and names the XAVPs with xavp_dst and xavp_ctx.
In kamailio.cfg, the documentation's failover setup looks like this. The dispatch uses round-robin (algorithm 4) on set 1:
modparam("dispatcher", "flags", 2)
modparam("dispatcher", "xavp_dst", "_dsdst_")
modparam("dispatcher", "xavp_ctx", "_dsctx_")
route[DISPATCH] {
if (!ds_select_dst("1", "4")) {
send_reply("404", "No destination");
exit;
}
t_on_failure("RTF_DISPATCH");
route(RELAY);
}
failure_route[RTF_DISPATCH] {
if (t_is_canceled()) {
exit;
}
# next DST - only for 500 or local timeout
if (t_check_status("500") or (t_branch_timeout() and !t_branch_replied())) {
ds_next_dst();
t_on_failure("RTF_DISPATCH");
route(RELAY);
}
}
The failure route exits when the call was canceled. It moves to the next destination only for a 500 reply or a local timeout. ds_next_dst() takes the next address from the XAVPs and sets it as the outbound proxy address, and the route then relays the request again. The RELAY route is the one defined in the previous section.
Two details matter here. Algorithm 12 does not set the XAVPs, so one failed branch cannot mark a single destination inactive. ds_mark_dst("ip") marks the last used address as inactive and probing.
What does a dispatched call look like message by message in sngrep?

This walk-through follows one call as sngrep would show it, with the caller, Kamailio, and the gateway that ds_select_dst chose in the route block above. Each item is one SIP message, in the order it is sent.
- The caller sends
INVITEto Kamailio. - Kamailio sends
100 Tryingback to the caller. - Kamailio sends
INVITEto the gateway. - The gateway sends
180 Ringingto Kamailio. - Kamailio sends
180 Ringingto the caller. - The gateway sends
200 OKto Kamailio. - Kamailio sends
200 OKto the caller. - The caller sends
ACKto Kamailio.
The call then ends:
- The caller sends
BYEto Kamailio. - Kamailio sends
BYEto the gateway. - The gateway sends
200 OKto Kamailio. - Kamailio sends
200 OKto the caller.
Either side can end a call with a BYE, which is confirmed with a 200 OK. This example shows the caller ending it.
Advanced examples: how do failover and priorities combine?
The two examples below combine documented pieces. The first uses priority ordering with algorithm 8 and the failover route from the section above. The second uses call load distribution with duid and maxload attributes.
For the first example, set 3 holds two gateways with priority values. In dispatcher.list:
3 sip:192.0.2.41 0 1
3 sip:192.0.2.42 0 5
The priority sets the initial ordering inside the set, and algorithm 8 selects destinations sorted by that priority value. In kamailio.cfg, the documentation's sample parameters and a priority route look like this:
modparam("dispatcher", "flags", 2)
modparam("dispatcher", "xavp_dst", "_dsdst_")
modparam("dispatcher", "xavp_ctx", "_dsctx_")
modparam("dispatcher", "ds_ping_from", "sip:proxy@kamailio.org")
modparam("dispatcher", "ds_ping_interval", 60)
modparam("dispatcher", "ds_probing_mode", 1)
modparam("dispatcher", "ds_timer_mode", 1)
route[PRIORITY_DISPATCH] {
if (!ds_select_dst("3", "8")) {
send_reply("404", "No destination");
exit;
}
t_on_failure("RTF_DISPATCH");
route(RELAY);
}
ds_probing_mode controls which gateways are tested to see if they are reachable. The sample sets it to 1, along with ds_timer_mode. Use the failure_route[RTF_DISPATCH] from the failover section with this route. When a branch returns 500 or times out, ds_next_dst() moves to the next address in the set.
For the second example, the gateways of set 2 carry a duid and a maxload. In dispatcher.list:
2 sip:192.0.2.31 0 0 duid=gw31;maxload=20
2 sip:192.0.2.32 0 0 duid=gw32;maxload=20
Every address needs a duid. maxload sets the upper limit of active calls per destination, and 0 means no limit. In kamailio.cfg, the call load route uses algorithm 10:
modparam("dispatcher", "ds_hash_size", 1)
route[CALL_LOAD] {
if (!ds_select_dst("2", "10")) {
send_reply("404", "No destination");
exit;
}
route(RELAY);
}
The documentation requires ds_hash_size to be greater than 0. The value 1 here is an example. Algorithm 10 works only for INVITE requests. It keeps its own call tracker keyed by Call-ID. The documentation's example calls ds_load_update() on BYE and CANCEL and on 2xx replies to INVITE, and ds_load_unset() on 3xx to 6xx replies, so the counts stay current.
More guides in Open-Source PBX and SIP Servers.
Related guides
Frequently asked questions
- Which algorithm number is call load distribution: 9 or 10?
- Call load distribution is algorithm 10, which picks the destination with the fewest active calls. Algorithm 9 is weight-based distribution, so the two numbers do different jobs.
- What happens if I pass an algorithm number that does not exist?
- Kamailio chooses the first entry in the set. Check each number against the table above before you deploy the script.
Sources
- ds_select_dst(set, alg[, limit]) selects a destination from an address set and returns tru (www.kamailio.org)
- The Kamailio 5.8.x dispatcher documentation lists algorithms 0 to 13 only. (kamailio.org)
- The development-branch documentation, checked on November 15, 2026, adds algorithm 15 (SRV (kamailio.org)
- Algorithm 14 is round-robin when all destinations in the group have the same priority (gre (kamailio.org)
- In SIP, INVITE is the method used to establish a session. A proxy that receives an INVITE (www.rfc-editor.org)