Setup of Twilio BYOC (Bring Your Own Carrier)
Introduction
Twilio’s Bring Your Own Carrier (BYOC) Trunking allows you to connect your existing SIP infrastructure (your own carrier, PBX, or SBC) to Twilio’s platform. This gives you the flexibility to use your preferred carrier for PSTN connectivity while leveraging Twilio’s APIs for programmability (SMS, Voice, Programmable Voice, etc.).
Key Benefits of BYOC
- Cost Control: Potentially lower calling rates by using your existing carrier agreements.
- Flexibility: Maintain relationships with your preferred carriers.
- Control: Greater control over your call routing and infrastructure.
- Number Portability: Often easier to port numbers to your existing carrier than directly to Twilio.
- Geographic Reach: Leverage your carrier’s existing coverage.
Prerequisites
Before you begin, ensure you have the following:
- A Twilio Account: You’ll need an active Twilio account. If you don’t have one, sign up at Twilio.
- A SIP Trunk from Your Carrier: This is the crucial part. You need a SIP trunk from your carrier that you’ll connect to Twilio. You’ll need the following information from your carrier:
- SIP Trunking Origination URI(s): These are the addresses Twilio will send calls to your carrier. Often in the format
sip:your-pbx.example.com
orsip:your-carrier-sbc.com
. You might have multiple for redundancy. - SIP Trunking Termination URI(s): These are the addresses your carrier will send calls from to Twilio. Twilio will provide these to you during the setup process.
- Authentication Credentials (if required): Username/password or IP-based authentication details for your SIP trunk. This is highly recommended for security.
- Supported Codecs: Ensure your carrier and Twilio support common codecs (G.711μ-law/a-law, G.729, etc.). Twilio primarily uses G.711μ-law.
- IP Addresses/Ranges: Your carrier may provide IP addresses or ranges that you’ll need to allowlist in your firewall for Twilio to connect. Twilio will also provide IP addresses you need to allowlist on your carrier’s side.
- SIP Trunking Origination URI(s): These are the addresses Twilio will send calls to your carrier. Often in the format
- Phone Numbers (Optional but Recommended): You can either purchase numbers from your carrier or port existing numbers to your carrier. You cannot use Twilio-purchased numbers with BYOC Trunking for outbound calls. You can use Twilio numbers for inbound calls to your BYOC trunk.
- Firewall Configuration: You’ll need to configure your firewall (and your carrier’s firewall, if applicable) to allow SIP and RTP traffic between Twilio and your infrastructure.
Step-by-Step Setup
- Create a BYOC Trunk in the Twilio Console:
- Log in to your Twilio Console.
- Navigate to Elastic SIP Trunking > Trunks.
- Click the „+“ button (or „Create new Trunk“ if you don’t have any).
- Give your trunk a friendly name (e.g., „My Carrier Trunk“).
- Select „Your Carrier (BYOC)“ as the Trunk Type.
- Click „Create“.
- Configure Origination Settings:
- Go to the Origination tab for your newly created trunk.
- Click the „+“ button to add an Origination URI.
- Enter the Origination URI provided by your carrier (e.g.,
sip:your-pbx.example.com
). - Set the Priority and Weight (for load balancing/failover if you have multiple Origination URIs). Lower priority numbers are tried first. Weight determines the distribution of calls among URIs with the same priority.
- Click „Save“.
- Repeat for any additional Origination URIs.
- Configure Termination Settings:
- Go to the Termination tab.
- Twilio automatically generates a Termination SIP URI for your trunk (e.g.,
sip:your-trunk-name.pstn.twilio.com
). You’ll need to provide this URI to your carrier. This is where your carrier will send calls to Twilio. - Credential Lists (Optional but Recommended): If your carrier requires username/password authentication, you’ll need to create a Credential List in the Twilio Console (Elastic SIP Trunking > Credential Lists) and associate it with your trunk’s Termination settings.
- IP Access Control Lists (Optional but Recommended): For IP-based authentication, create an IP Access Control List (Elastic SIP Trunking > IP Access Control Lists) and associate it with your trunk. Add your carrier’s IP addresses/ranges to this list.
- Configure Numbers:
- Go to the Numbers tab.
- You cannot add Twilio-purchased numbers to the BYOC trunk for outbound calling.
- You can add Twilio numbers for inbound calls. If you want to receive calls on a Twilio number and route them to your BYOC trunk, add the number here.
- You will manage your carrier-provided numbers within your carrier’s portal. You don’t add them directly to the Twilio BYOC trunk.
- Configure your Carrier’s SIP Trunk:
- This is the most carrier-specific part. You’ll need to log in to your carrier’s portal or work with their support team.
- Configure your carrier’s SIP trunk to send calls to the Termination SIP URI provided by Twilio.
- Configure your carrier’s SIP trunk to accept calls from the Twilio IP addresses (you can find these in the Twilio documentation: https://www.twilio.com/docs/sip-trunking/ip-addresses).
- Configure authentication (username/password or IP-based) if required, matching the settings you configured in Twilio.
- Test Your Setup:
- Outbound Call: Use a Twilio Programmable Voice TwiML Bin or a simple application to make an outbound call. Use a phone number associated with your carrier as the
From
number. TheTo
number can be any valid phone number. - Inbound Call: Call one of the phone numbers associated with your carrier. If you’ve configured a Twilio number for inbound calls to your BYOC trunk, call that number. Your call should route through Twilio and then to your carrier’s infrastructure.
- Outbound Call: Use a Twilio Programmable Voice TwiML Bin or a simple application to make an outbound call. Use a phone number associated with your carrier as the
Troubleshooting
- Check SIP Signaling: Use tools like
tcpdump
or Wireshark on your SBC or PBX to capture SIP traffic and diagnose connection issues. - Twilio Debugger: The Twilio Console has a debugger that can help identify errors.
- Carrier Support: Contact your carrier’s support team for assistance with their side of the configuration.
- Twilio Support: If you’re still having trouble, contact Twilio support.
Important Considerations
- E911: Ensure you have a proper E911 solution in place. BYOC Trunking itself doesn’t inherently provide E911. You’ll need to work with your carrier to configure E911 services.
- CNAM: Caller ID Name (CNAM) is typically handled by your carrier.
- T.38 Fax: If you need T.38 fax support, ensure both your carrier and your equipment support it. Twilio supports T.38 pass-through.
- Security: Always use authentication (username/password or IP ACLs) to secure your SIP trunk.
- High Availability: Consider using multiple Origination URIs with different priorities and weights for redundancy.
- Call Recording: If you use Twilio call recording, be aware of where the recording takes place.