---
title: Connect Kamailio to TelecomsXchange
url: https://help.telecomsxchange.com/integrations/kamailio/
audience: Integrations
summary: Put sip:sip01.telecomsxchange.com:5060 in a dispatcher set, rewrite the Request-URI
  user to TECH_PREFIX plus the E.164 number, and relay. Authorise Kamailio's public
  IP on the account, or answer 401/407 in a failure route with uac_auth() and the
  VoIP login. Accept inbound calls with allow_source_address() for 174.136.44.213.
updated: '2026-10-23'
verified_commit: 83b4ebc96d0081a25213776d5a8871bd04941125
---

# Connect Kamailio to TelecomsXchange

> Put sip:sip01.telecomsxchange.com:5060 in a dispatcher set, rewrite the Request-URI user to TECH_PREFIX plus the E.164 number, and relay. Authorise Kamailio's public IP on the account, or answer 401/407 in a failure route with uac_auth() and the VoIP login. Accept inbound calls with allow_source_address() for 174.136.44.213.

## Kamailio to a purchased route

1. **Your Kamailio**: dispatcher set, identified by IP
2. **TelecomsXchange** (via `80039#447700900123`): sip01, UDP 5060
3. **Seller's route**: The route you purchased

Kamailio usually sits in front of your media servers as an SBC or routing proxy. This guide sends calls from it to TelecomsXchange and accepts TelecomsXchange's calls for routes you sell or numbers you bought. For every TelecomsXchange value in one place, see [Connect a SIP platform](https://help.telecomsxchange.com/integrations/connect-sip-platforms/).

!!! warning
    TelecomsXchange does not accept SIP REGISTER. Don't use `uac_reg` for it. Kamailio is recognised by its **source IP** or by **digest authentication on the INVITE**.

## Before you start

- A [SIP account](https://help.telecomsxchange.com/buyers/create-your-first-account/) with Kamailio's public IP, for example `203.0.113.10`, or a VoIP login and password from **Edit Account → Add SIP Digest Auth**.
- A [purchased route](https://help.telecomsxchange.com/buyers/find-and-buy-routes/) and its tech prefix from **My Interconnections**, for example `80039#`.
- Kamailio with the `tm`, `dispatcher`, `permissions` and `uac` modules available.
- To sell: a [route](https://help.telecomsxchange.com/sellers/add-your-first-route/) with **IP Address:Port** set to Kamailio, for example `203.0.113.10:5060`, and the values in [Interconnect Info](https://help.telecomsxchange.com/sellers/interconnect-info/).

## How do I send calls to TelecomsXchange?

1. Add TelecomsXchange as dispatcher set 1, and your own media servers as set 2 for inbound calls:

```text
# /etc/kamailio/dispatcher.list
# setid  destination
1 sip:sip01.telecomsxchange.com:5060
2 sip:10.0.0.21:5060
```

2. Load the modules and set their parameters in `kamailio.cfg`:

```text
loadmodule "dispatcher.so"
loadmodule "permissions.so"
loadmodule "uac.so"

modparam("dispatcher", "list_file", "/etc/kamailio/dispatcher.list")
modparam("permissions", "address_file", "address.list")   # next to kamailio.cfg
# digest credentials are read from these AVPs in the failure route
modparam("uac", "auth_username_avp", "$avp(auser)")
modparam("uac", "auth_password_avp", "$avp(apass)")
modparam("uac", "auth_realm_avp", "$avp(arealm)")
```

3. Rewrite the number and relay. `80039#` is the `TECH_PREFIX` from **My Interconnections**:

```text
route[TO_TCXC] {
    # strip + or 00 so the number is plain E.164
    if ($(rU{s.substr,0,1}) == "+") {
        $rU = $(rU{s.substr,1,0});
    } else if ($(rU{s.substr,0,2}) == "00") {
        $rU = $(rU{s.substr,2,0});
    }
    $rU = "80039#" + $rU;              # TECH_PREFIX + E.164
    if (!ds_select_dst("1", "4")) {
        send_reply("503", "TelecomsXchange unavailable");
        exit;
    }
    t_on_failure("TCXC_AUTH");
    route(RELAY);
    exit;
}

failure_route[TCXC_AUTH] {
    if (t_is_canceled()) exit;
    # digest variant: answer TCXC's challenge with the account's VoIP login
    if (t_check_status("401|407")) {
        $avp(auser) = "VOIP_LOGIN";
        $avp(apass) = "VOIP_PASSWORD";
        $avp(arealm) = $null;          # empty: use the realm from the challenge
        if (uac_auth()) {
            t_relay();
        }
        exit;
    }
}
```

Call `route(TO_TCXC)` from `request_route` for the INVITEs your customers send to international numbers, after your own authentication of those customers.

With IP authentication only, TelecomsXchange doesn't challenge and the failure route is never used for auth; keep it anyway, so adding a VoIP login later needs no script change.

!!! tip
    sip01 is a single host, so set 1 has one destination. To fail over between purchased routes, dial a [routing group](https://help.telecomsxchange.com/buyers/routing-groups-and-route-testing/) prefix such as `444101#` and let TelecomsXchange pick the route.

## How do I receive calls from TelecomsXchange?

Calls on routes you sell, and on numbers you bought, come from `174.136.44.213` over UDP, from source ports 5060 to 5072, with the number in E.164 format such as `14165551234`.

1. Allow `174.136.44.213` on your firewall for UDP 5060.
2. Add it to the permissions address file as group 10:

```text
# /etc/kamailio/address.list
# group  address         mask  port  tag
10 174.136.44.213 32 0 tcxc
```

3. Near the top of `request_route`, before your customer authentication, send TelecomsXchange's INVITEs to your media servers:

```text
if (is_method("INVITE") && allow_source_address("10")) {
    # route sold: E.164 number in $rU, e.g. 14165551234
    if (!ds_select_dst("2", "4")) {
        send_reply("503", "No media server");
        exit;
    }
    route(RELAY);
    exit;
}
```

4. Reload with `kamcmd permissions.addressReload` and `kamcmd dispatcher.reload`.

If your route has an **Outgoing Prefix** or strips digits (**Edit Route → Outgoing Number Translation Parameters**), expect the number in that format.

## How do I receive calls on numbers I bought?

Set the number's **SIP Endpoint (Primary)** in **DID Settings** to Kamailio, for example `sip:14165551234@203.0.113.10:5060`. The INVITE comes from `174.136.44.213`, matches `allow_source_address("10")`, and goes to your media servers with the number in `$rU`.

## How do I test it?

1. Check the configuration: `kamailio -c -f /etc/kamailio/kamailio.cfg`, then `kamcmd dispatcher.list` and `kamcmd permissions.addressDump`.
2. Start a capture: `sngrep port 5060`.
3. Place a call from one of your customers and check the INVITE to sip01 carries `80039#447700900123` (or `80039%23447700900123`) and the reply code.
4. In the portal, watch the call in **Live Calls** and find its SIP code in **Logs → CDR (Voice)**.

## What if something goes wrong?

| You see | What to do |
|---|---|
| 401 or 407 passed back to your customer | The failure route isn't armed or `uac_auth()` failed. Check `t_on_failure("TCXC_AUTH")` runs before the relay, and the VoIP login and password. |
| 403 Forbidden | Kamailio's public IP isn't authorised and no valid credentials were sent. Check the source IP in sngrep against **IP Address** and **Additional Allowed IPs**; check the account isn't blocked or out of balance. |
| 404 Not Found | Missing or wrong tech prefix, or `+`/`00` left in the number. Log `$rU` before `ds_select_dst()`. |
| 408 Request Timeout | No reply from sip01. Check outbound UDP 5060, and that Kamailio resolved the hostname (`kamcmd dispatcher.list`). |
| 503 Service Unavailable | From TelecomsXchange: the route is blocked or failed; check **My Interconnections**. From Kamailio: the dispatcher set has no active destination. |
| One-way or no audio | Your media servers advertise private IPs. Add rtpengine or set their external address, and open the RTP range. |
| No inbound calls | `174.136.44.213` isn't allowed on the firewall or not in `address.list`, or the route or number points at the wrong host or port. |

## References

- [Kamailio dispatcher module](https://www.kamailio.org/docs/modules/stable/modules/dispatcher.html)
- [Kamailio permissions module](https://www.kamailio.org/docs/modules/stable/modules/permissions.html)
- [Kamailio uac module](https://www.kamailio.org/docs/modules/stable/modules/uac.html)
- [Kamailio core cookbook: transformations](https://www.kamailio.org/wikidocs/cookbooks/devel/transformations/)

## Frequently asked questions

**Q: Can Kamailio register to TelecomsXchange?**

A: No. TelecomsXchange is peering only and does not accept REGISTER, so don't use the uac module's remote registration. Kamailio is recognised by its source IP, or by answering the digest challenge with uac_auth().

**Q: Does Kamailio need to handle media?**

A: Kamailio only relays signalling. Media flows between the endpoints in the SDP, so if your media servers are behind NAT, add rtpengine or set their public IP. TelecomsXchange doesn't transcode.

**Q: How do I use several purchased routes?**

A: Choose the tech prefix per destination in the script, for example from an htable or a database lookup, or dial a routing group prefix starting with 444 and let TelecomsXchange choose.

**Q: Which Kamailio version is this for?**

A: The modules and functions used, dispatcher, permissions and uac, are the same in Kamailio 5.8 and 6.0.
