Skip to contentSkip to navigationSkip to topbar
On this page

Sending SIP to Twilio - Best Practices



Overview

overview page anchor

This document covers technical details to ensure that calls sent from a customer's SIP infrastructure to Twilio Elastic SIP Trunking are properly processed. For a successful integration it is important to follow the following guidelines:

  • Traffic should be evenly load balanced across Twilio infrastructure IP addresses.
  • Traffic should not exceed 30 CPS sent from a single customer IP to a single Twilio IP. This is to avoid network-level constraints and anti-abuse mechanisms. If your traffic might exceed this rate consider adding more IPs that you are sending traffic from or load balance to multiple Twilio edge locations.

Your Elastic SIP trunk has a unique domain name, such as mytrunk.pstn.twilio.com; this is referred to in your Twilio console as your Termination SIP URI. It is important that the request URI (specifically the host part) contains this domain name so that Twilio can identify your traffic. When targeting your traffic to a specific Twilio Edge Location(link takes you to an external page) there are two main approaches:

Using a localized SIP URI

using-a-localized-sip-uri page anchor

Your Twilio SIP domain comes in a localized version, mytrunk.pstn.[edge].twilio.com, for example mytrunk.pstn.ashburn.twilio.com. Using this domain is simple but may be less flexible since the same name is used for identifying your trunk as well as controlling where traffic is routed. Specifically there may be limitations on how your server is able to load balance traffic across Twilio IPs.

All Twilio customer SIP domains resolve to the same A DNS record, which means customers share the same Twilio SIP endpoints. These A records provide all IPs in random order, but it is up to your SIP server to load balance across all of them. This behavior will vary by vendor and In many cases only the first IP is used which would not produce the expected load balancing.

Using your SIP URI and an Outbound Proxy or Route Header

using-your-sip-uri-and-an-outbound-proxy-or-route-header page anchor

A more reliable approach for predictable load balancing is to configure your SIP server with both your personalized domain name and an "Outbound Proxy" or Route header set to one of Twilio's generic localized edge domain names. These domains offer NAPTR and SRV records (see RFC 3263(link takes you to an external page)). The DNS names for these records are pstn.[edge].twilio.com, for example pstn.ashburn.twilio.com.

These records resolve to the same IPs as the personal localized SIP Trunk domain name, but supported SIP servers can query the SRV record for additional load balancing information.

To be able to use this option, your SIP server still has to use your personal trunk domain name in the Request URI. You can do this by specifying the generic localized DNS as the "Outbound Proxy" in your configuration. The exact name might vary and might include configuring a Route header or similar. Consult your vendor's manual for details.

Example configuration:

  • Request Domain: mytrunk.pstn.twilio.com
  • Outbound Proxy/Route: pstn.ashburn.twilio.com

The following examples are DNS queries for the A record of the localized domain as well as the NAPTR and SRV of the proxy domain. Examples are from US East, Ashburn.

1
dig +short mytrunk.pstn.ashburn.twilio.com
2
54.172.60.0
3
54.172.60.1
4
54.172.60.3
5
54.172.60.2
6
7
dig +short SRV _sip._udp.pstn.ashburn.twilio.com
8
10 10 5060 public-sip0.ashburn.twilio.com.
9
10 10 5060 public-sip1.ashburn.twilio.com.
10
10 10 5060 public-sip2.ashburn.twilio.com.
11
10 10 5060 public-sip3.ashburn.twilio.com.
12
13
dig +short NAPTR pstn.ashburn.twilio.com
14
10 10 "S" "SIP+D2U" "" _sip._udp.pstn.ashburn.twilio.com.
15
20 10 "S" "SIPS+D2T" "" _sips._tcp.pstn.ashburn.twilio.com.
16
20 10 "S" "SIP+D2T" "" _sip._tcp.pstn.ashburn.twilio.com.