Hi.
I'm trying to make failover-failback without any Load-Balancing with kamailio paired with HiPath 3800.
Ubuntu 20.04, kamailio 5.5.7
# dispatcher.list 1 sip:192.168.1.10:5060 0 0 p=primary 1 sip:192.168.1.11:5060 0 0 p=secondary
# IP Addresses of Kamailio Server listen=udp:10.0.0.203:5060 listen=tcp:10.0.0.203:5060 listen=tls:10.0.0.203:5060
# --- Module Parameters --- modparam("tm", "fr_timer", 10000) modparam("tm", "fr_inv_timer", 60000) modparam("dispatcher", "list_file", "/etc/kamailio/dispatcher.list") modparam("dispatcher", "flags", 2) modparam("dispatcher", "force_dst", 1) modparam("dispatcher", "ds_ping_method", "OPTIONS") modparam("dispatcher", "ds_ping_interval", 10) modparam("dispatcher", "ds_probing_mode", 1) # Probes all nodes, even if inactive modparam("dispatcher", "ds_probing_threshold", 2) modparam("dispatcher", "ds_inactive_threshold", 5)
# --- Routing Logic --- request_route { if (is_method("INVITE|REGISTER")) { if (!ds_select_dst("1", "8")) { sl_send_reply("503", "No servers available"); exit; } xlog*("Selected Destination $rd/$du \n"); t_on_failure("FAILOVER"); t_relay(); } }
failure_route[FAILOVER] { if (t_check_status("503|408")) { xlog("Failed Destination $rd/$du \n"); if (ds_next_dst()) { t_on_failure("FAILOVER"); t_relay(); } } }
When both PBXs are online I check the log file and see that Selected Destination is 10.0.0.203/sip:10.0.0.65. I also check via sngrep: if both PBXs are up I see OPTIONS to both of them 10.0.0.65 and 10.0.0.75
When I shutdown 10.0.0.65, log file says Failed Destination is 10.0.0.203/sip:10.0.0.65 and that's it.
ds_next_dst not triggering at all.
Thanks in advance.
My dispatcher.list is like this # dispatcher.list 1 sip:10.0.0.65:5060 0 5 1 sip:10.0.0.75:5060 0 1
Hi,
Please have a look at the example config in the documentation for the dispatcher module - https://kamailio.org/docs/modules/5.8.x/modules/dispatcher.html#dispatcher.e...
With your current config failover to node Y will only happen if node X responds with 503 or 408.
In the example config I refer to above you can find the failover condition you need for the scenario when node X is down completely: (t_branch_timeout() and !t_branch_replied())
Another thing you need to change is to add an exit; statement after the t_relay(); statements.
Lars
Den 2026-04-03 kl. 20:41, skrev Kama User via sr-users:
Hi.
I'm trying to make failover-failback without any Load-Balancing with kamailio paired with HiPath 3800.
Ubuntu 20.04, kamailio 5.5.7
# dispatcher.list 1 sip:192.168.1.10:5060 0 0 p=primary 1 sip:192.168.1.11:5060 0 0 p=secondary
# IP Addresses of Kamailio Server listen=udp:10.0.0.203:5060 listen=tcp:10.0.0.203:5060 listen=tls:10.0.0.203:5060
# --- Module Parameters --- modparam("tm", "fr_timer", 10000) modparam("tm", "fr_inv_timer", 60000) modparam("dispatcher", "list_file", "/etc/kamailio/dispatcher.list") modparam("dispatcher", "flags", 2) modparam("dispatcher", "force_dst", 1) modparam("dispatcher", "ds_ping_method", "OPTIONS") modparam("dispatcher", "ds_ping_interval", 10) modparam("dispatcher", "ds_probing_mode", 1) # Probes all nodes, even if inactive modparam("dispatcher", "ds_probing_threshold", 2) modparam("dispatcher", "ds_inactive_threshold", 5)
# --- Routing Logic --- request_route { if (is_method("INVITE|REGISTER")) { if (!ds_select_dst("1", "8")) { sl_send_reply("503", "No servers available"); exit; } xlog*("Selected Destination $rd/$du \n"); t_on_failure("FAILOVER"); t_relay(); } }
failure_route[FAILOVER] { if (t_check_status("503|408")) { xlog("Failed Destination $rd/$du \n"); if (ds_next_dst()) { t_on_failure("FAILOVER"); t_relay(); } } }
When both PBXs are online I check the log file and see that Selected Destination is 10.0.0.203/sip:10.0.0.65. I also check via sngrep: if both PBXs are up I see OPTIONS to both of them 10.0.0.65 and 10.0.0.75
When I shutdown 10.0.0.65, log file says Failed Destination is 10.0.0.203/sip:10.0.0.65 and that's it.
ds_next_dst not triggering at all.
Thanks in advance. __________________________________________________________ Kamailio - Users Mailing List - Non Commercial Discussions -- sr-users@lists.kamailio.org To unsubscribe send an email to sr-users-leave@lists.kamailio.org Important: keep the mailing list in the recipients, do not reply only to the sender!
Thanks for the answer. I made the changes but unfortunately the result is the same.
/etc/kamailio/dispatcher.list: 1 sip:10.0.0.65:5060 0 2 1 sip:10.0.0.75:5060 0 1
/etc/kamailio/kamailio.cfg: # --- Global Parameter --- debug=2 log_stderror=no log_facility=LOG_LOCAL0 fork=yes children=4
# IP Addresses of Kamailio Server listen=udp:10.0.0.203:5060 listen=tcp:10.0.0.203:5060
# Module Loading mpath="/usr/lib/x86_64-linux-gnu/kamailio/modules/"
# --- Load Modules --- loadmodule "tm.so" loadmodule "sl.so" loadmodule "rr.so" loadmodule "pv.so" loadmodule "textops.so" loadmodule "dispatcher.so" loadmodule "maxfwd.so" loadmodule "corex.so" loadmodule "xlog.so" loadmodule "ctl.so"
# --- Module Parameters --- modparam("tm", "fr_timer", 5000) modparam("tm", "fr_inv_timer", 30000) modparam("dispatcher", "list_file", "/etc/kamailio/dispatcher.list") modparam("dispatcher", "force_dst", 1) modparam("dispatcher", "flags", 2) modparam("dispatcher", "ds_ping_method", "OPTIONS") modparam("dispatcher", "ds_ping_interval", 10) modparam("dispatcher", "ds_probing_mode", 1) modparam("dispatcher", "ds_probing_threshold", 2) modparam("dispatcher", "ds_inactive_threshold", 4)
request_route { if (is_method("INVITE|REGISTER")) { if (!ds_select_dst("1", "4")) { sl_send_reply("503", "No servers available"); exit; }
xlog*("Selected Reg Trunk $rd/$du \n"); t_on_failure("FAILOVER"); t_relay(); exit; } }
failure_route[FAILOVER] { if (t_check_status("503|408") or t_branch_timeout() or !t_branch_replied()) { xlog("Failed Trunk $rd/$du Detected \n"); if (ds_next_dst()) { t_on_failure("FAILOVER"); t_relay(); exit; } } }
Can I do failover-failback with this construction? rewritehostport("10.0.0.65:5060"); forward();
Thanks in advance.
Today I also tried this setup.
request_route { if (is_method("INVITE|REGISTER")){ rewritehost("10.0.0.65"); t_on_failure("FAILOVER"); t_relay_to_tcp("10.0.0.65","5060"); exit; }
failure_route[FAILOVER] { rewritehost("10.0.0.75"); t_relay_to_tcp("10.0.0.75","5060"); exit; }
This the setup did the trick, when I turn off PBX1 (10.0.0.65) subscriber registers on PBX2 (10.0.0.75) and vice versa. Sometime connection goes down on the subscriber side though.
But I don't know why I can do call from Subscriber to PBX1 and PBX2 and can hear the voice, but when I try to call from PBX1 and PBX2 I got the call but no voice whatsoever.
Thanks.
Hello,
the approach below with the failure_route and the ds_next_dst() should work for you. This is used in many installations.
If its not working, then there is some issue in your configuration. Add some more debugging for example to find out why.
Cheers,
Henning
-----Original Message----- From: Kama User via sr-users sr-users@lists.kamailio.org Sent: Montag, 6. April 2026 14:52 To: sr-users@lists.kamailio.org Cc: Kama User magerram@gmail.com Subject: [SR-Users] Re: Failover-Failback without any Load-Balancing
Thanks for the answer. I made the changes but unfortunately the result is the same.
/etc/kamailio/dispatcher.list: 1 sip:10.0.0.65:5060 0 2 1 sip:10.0.0.75:5060 0 1
/etc/kamailio/kamailio.cfg: # --- Global Parameter --- debug=2 log_stderror=no log_facility=LOG_LOCAL0 fork=yes children=4
# IP Addresses of Kamailio Server listen=udp:10.0.0.203:5060 listen=tcp:10.0.0.203:5060
# Module Loading mpath="/usr/lib/x86_64-linux-gnu/kamailio/modules/"
# --- Load Modules --- loadmodule "tm.so" loadmodule "sl.so" loadmodule "rr.so" loadmodule "pv.so" loadmodule "textops.so" loadmodule "dispatcher.so" loadmodule "maxfwd.so" loadmodule "corex.so" loadmodule "xlog.so" loadmodule "ctl.so"
# --- Module Parameters --- modparam("tm", "fr_timer", 5000) modparam("tm", "fr_inv_timer", 30000) modparam("dispatcher", "list_file", "/etc/kamailio/dispatcher.list") modparam("dispatcher", "force_dst", 1) modparam("dispatcher", "flags", 2) modparam("dispatcher", "ds_ping_method", "OPTIONS") modparam("dispatcher", "ds_ping_interval", 10) modparam("dispatcher", "ds_probing_mode", 1) modparam("dispatcher", "ds_probing_threshold", 2) modparam("dispatcher", "ds_inactive_threshold", 4)
request_route { if (is_method("INVITE|REGISTER")) { if (!ds_select_dst("1", "4")) { sl_send_reply("503", "No servers available"); exit; }
xlog*("Selected Reg Trunk $rd/$du \n"); t_on_failure("FAILOVER"); t_relay(); exit; } }
failure_route[FAILOVER] { if (t_check_status("503|408") or t_branch_timeout() or !t_branch_replied()) { xlog("Failed Trunk $rd/$du Detected \n"); if (ds_next_dst()) { t_on_failure("FAILOVER"); t_relay(); exit; } } }
Can I do failover-failback with this construction? rewritehostport("10.0.0.65:5060"); forward();
Thanks in advance. __________________________________________________________ Kamailio - Users Mailing List - Non Commercial Discussions -- sr- users@lists.kamailio.org To unsubscribe send an email to sr-users-leave@lists.kamailio.org Important: keep the mailing list in the recipients, do not reply only to the sender!
Thanks for the answer.
I did some debbugging and noticed that some time $rd and $du are the same and equal to 10.0.0.203.
Can you suggest some debugging xlog, and what exactly should I catch.
Thanks.
Make sure you’re actually gettting the response for which you have the failover. We usually do something like 5XX\4XX for testing as you might not be matching it. I also didn’t see a
t_branch_timeout()
On your failover.
Also, if the gateway is down and not even responding, Kamailio won’t even try that destination.
Regards,
David Villasmil email: david.villasmil.work@gmail.com
On Mon, Apr 6, 2026 at 11:34 PM Kama User via sr-users < sr-users@lists.kamailio.org> wrote:
Thanks for the answer.
I did some debbugging and noticed that some time $rd and $du are the same and equal to 10.0.0.203.
Can you suggest some debugging xlog, and what exactly should I catch.
Thanks. __________________________________________________________ Kamailio - Users Mailing List - Non Commercial Discussions -- sr-users@lists.kamailio.org To unsubscribe send an email to sr-users-leave@lists.kamailio.org Important: keep the mailing list in the recipients, do not reply only to the sender!
Thanks for the answer.
In my case something strange is happening.
The only code which worked pretty well was this one:
request_route { if (is_method("INVITE|REGISTER")){ rewritehost("10.0.0.65"); t_on_failure("FAILOVER"); t_relay_to_tcp("10.0.0.65","5060"); exit; }
failure_route[FAILOVER] { rewritehost("10.0.0.75"); t_relay_to_tcp("10.0.0.75","5060"); exit; }
I've seen a lot of articles where the ds_select_dst and ds_next_dst approach is working with no issue.
I'll add some debug stuff and see if I can find the cause of that strange behaviour.
Thanks.
Hi again,
In your quoted config, you have: if (t_check_status("503|408") or t_branch_timeout() or !t_branch_replied()) {
, but according to the example in the module docs it should be if (t_check_status("503|408") or (t_branch_timeout() and !t_branch_replied())) {
- This config works for me, where 'or (t_branch_timeout() and !t_branch_replied())' kicks in when a target is completely down
Lars
Den 2026-04-06 kl. 14:52, skrev Kama User via sr-users:
Thanks for the answer. I made the changes but unfortunately the result is the same.
/etc/kamailio/dispatcher.list: 1 sip:10.0.0.65:5060 0 2 1 sip:10.0.0.75:5060 0 1
/etc/kamailio/kamailio.cfg: # --- Global Parameter --- debug=2 log_stderror=no log_facility=LOG_LOCAL0 fork=yes children=4
# IP Addresses of Kamailio Server listen=udp:10.0.0.203:5060 listen=tcp:10.0.0.203:5060
# Module Loading mpath="/usr/lib/x86_64-linux-gnu/kamailio/modules/"
# --- Load Modules --- loadmodule "tm.so" loadmodule "sl.so" loadmodule "rr.so" loadmodule "pv.so" loadmodule "textops.so" loadmodule "dispatcher.so" loadmodule "maxfwd.so" loadmodule "corex.so" loadmodule "xlog.so" loadmodule "ctl.so"
# --- Module Parameters --- modparam("tm", "fr_timer", 5000) modparam("tm", "fr_inv_timer", 30000) modparam("dispatcher", "list_file", "/etc/kamailio/dispatcher.list") modparam("dispatcher", "force_dst", 1) modparam("dispatcher", "flags", 2) modparam("dispatcher", "ds_ping_method", "OPTIONS") modparam("dispatcher", "ds_ping_interval", 10) modparam("dispatcher", "ds_probing_mode", 1) modparam("dispatcher", "ds_probing_threshold", 2) modparam("dispatcher", "ds_inactive_threshold", 4)
request_route { if (is_method("INVITE|REGISTER")) { if (!ds_select_dst("1", "4")) { sl_send_reply("503", "No servers available"); exit; }
xlog*("Selected Reg Trunk $rd/$du \n"); t_on_failure("FAILOVER"); t_relay(); exit; } }
failure_route[FAILOVER] { if (t_check_status("503|408") or t_branch_timeout() or !t_branch_replied()) { xlog("Failed Trunk $rd/$du Detected \n"); if (ds_next_dst()) { t_on_failure("FAILOVER"); t_relay(); exit; } } }
Can I do failover-failback with this construction? rewritehostport("10.0.0.65:5060"); forward();
Thanks in advance. __________________________________________________________ Kamailio - Users Mailing List - Non Commercial Discussions -- sr-users@lists.kamailio.org To unsubscribe send an email to sr-users-leave@lists.kamailio.org Important: keep the mailing list in the recipients, do not reply only to the sender!
Hi. Thanks for the answer.
I divided "(t_branch_timeout() and !t_branch_replied())" into "t_branch_timeout() or !t_branch_replied()" to get more chanses to trigger ds_next_dst. In this case of this (t_check_status("503|408") or t_branch_timeout() or !t_branch_replied()) I believe kamailio should trigger if any of these conditions hit.
I haven't tried t_branch_timeout() yet.
But so far only this code worked pretty much well for me
request_route { if (is_method("INVITE|REGISTER")){ rewritehost("10.0.0.65"); t_on_failure("FAILOVER"); t_relay_to_tcp("10.0.0.65","5060"); exit; }
failure_route[FAILOVER] { rewritehost("10.0.0.75"); t_relay_to_tcp("10.0.0.75","5060"); exit; }
Good evening,
Here is a vital fact I failed to mention previously: For the condition (t_branch_timeout() and !t_branch_replied()) to kick in fast when a dead target gives no repsonse whatsoever you need to tune the fr_timer. The condition will not be true before fr_timer has expired.
First I think you should read an old but still relevant (AFAIK) document on transaction timers - https://sip-router.org/wiki/ref_manual/timers
Then you can either change the the vaulue in the module parameter setting modparam("tm", "fr_timer", xxx),
or you could use t_set_fr(0, xxx); like this:
if (is_method("INVITE|REGISTER")) { if (!ds_select_dst("1", "4")) { sl_send_reply("503", "No servers available"); exit; } xlog*("Selected Reg Trunk $rd/$du \n"); t_set_fr(0, xxx); t_on_failure("FAILOVER"); t_relay(); exit; }
To guarantee fast failover you should set xxx to e.g. 200 - meaning in practice that you deem the target to be down if you haven't seen a 100 Trying in 200 ms after the INVITE was sent.
You should then use 'if (t_check_status("503|408") or (t_branch_timeout() and !t_branch_replied()))' as the condition in your failure_route.
Please have a look at t_branch_timeout() and t_branch_replied() in the module docs for the TM module.
Taken together as (t_branch_timeout() and !t_branch_replied()) my interpretation is in plain language: "No response whatsoever has been received and thus the branch must have timed out because the fr_timer has expired."
Lars
Den 2026-04-08 kl. 17:20, skrev Kama User via sr-users:
Hi. Thanks for the answer.
I divided "(t_branch_timeout() and !t_branch_replied())" into "t_branch_timeout() or !t_branch_replied()" to get more chanses to trigger ds_next_dst. In this case of this (t_check_status("503|408") or t_branch_timeout() or !t_branch_replied()) I believe kamailio should trigger if any of these conditions hit.
I haven't tried t_branch_timeout() yet.
But so far only this code worked pretty much well for me
request_route { if (is_method("INVITE|REGISTER")){ rewritehost("10.0.0.65"); t_on_failure("FAILOVER"); t_relay_to_tcp("10.0.0.65","5060"); exit; }
failure_route[FAILOVER] { rewritehost("10.0.0.75"); t_relay_to_tcp("10.0.0.75","5060"); exit; } __________________________________________________________ Kamailio - Users Mailing List - Non Commercial Discussions -- sr-users@lists.kamailio.org To unsubscribe send an email to sr-users-leave@lists.kamailio.org Important: keep the mailing list in the recipients, do not reply only to the sender!
Hi. Thanks for the answer.
I changed fr_timer from "5000" to "500". Thanks for the tip.
I use these tm module parameters: fr_timer fr_inv_timer
Unfortunately dispatcher module (ds_select_dst, ds_next_dst) didn't work for me as intended.
Only this code worked for me as expected.
request_route { if (is_method("INVITE|REGISTER")) { rewritehost("10.0.0.65"); t_on_failure("FAILOVER"); t_relay_to_tcp("10.0.0.65","5060"); exit; }
failure_route[FAILOVER] { if (t_branch_timeout()) { rewritehost("10.0.0.75"); t_relay_to_tcp("10.0.0.75","5060"); exit; } }
I still have some issues with this code tho. I can't call back to sip subscriber, which uses kamailio ip as a registrar.
Hi guys.
I ended up using DNS SRV, which worked for me pretty well and was quite easy to configure.
Thanks yall for the help.