Kamailio
Route the number to another IP as per DST number
16 views
Code
# Kamailio configuration for routing based on destination number
# Define the destination number patterns and their corresponding servers
modparam("htable", "htable", "dstroutes=>size=10;autoexpire=3600")
# Fill the hash table with destination patterns and target IPs
request_route {
# ... other configuration ...
# Check if it's an INVITE
if (is_method("INVITE")) {
# Extract the destination number from the Request-URI
if ($rU =~ "^(1234.*)$") {
# Route calls to numbers starting with 1234 to a specific server
$du = "sip:$rU@192.168.1.10:5060";
route(RELAY);
exit;
}
if ($rU =~ "^(5678.*)$") {
# Route calls to numbers starting with 5678 to another server
$du = "sip:$rU@192.168.1.20:5060";
route(RELAY);
exit;
}
# Default routing if no pattern matches
# ...
}
# ... continue with other routing logic ...
}
# Relay route
route[RELAY] {
if (!t_relay()) {
sl_reply_error();
}
}
Explanation
This Kamailio configuration snippet demonstrates how to route calls based on the destination number pattern. It uses regular expressions to match the destination number in the Request-URI and routes the call to different SIP servers based on the pattern match. This is useful for implementing number-based routing policies in a SIP proxy.
Rate this snippet
Have a Better Solution?
Know a more efficient way to solve this problem? Share your own code snippet and help the community!
Submit Your Version