Twilio Elastic SIP Trunk

This guide covers setting up Twilio Elastic SIP Trunking as a PSTN gateway for the VoIP Server. Once configured, crew members can dial external phone numbers (mobile, landline) directly from the vehicle intercom system.

Prerequisites

  • A Twilio account with Elastic SIP Trunking enabled
  • A purchased or ported phone number (DID) for caller ID
  • The vehicle's public IP or VPN endpoint accessible from the internet
  • VoIP Server running with the Twilio gateway plugin (libgw-twilio.so)

Setup Steps

1. Create a SIP Trunk

  1. Log in to Twilio Console
  2. Navigate to Elastic SIP Trunking → Trunks → Create new Trunk
  3. Set a friendly name (e.g. "GVA Vehicle Trunk")
  4. Under Termination (outbound calls):
    • Set the Termination SIP URI (e.g. your-trunk.pstn.twilio.com)
    • Enable Credential List authentication
  5. Under Origination (inbound calls):
    • Add your vehicle's public IP or VPN endpoint as an Origination URI
    • Format: sip:<your-ip>:5080;transport=udp

2. Create a Credential List

  1. Go to Elastic SIP Trunking → Authentication → Credential Lists
  2. Create a new credential list
  3. Add a username and password — these go into voip-settings.json

3. Assign a Phone Number

  1. Purchase or port a phone number (DID) under Phone Numbers
  2. Configure the number to route to your SIP Trunk
  3. Set the callerIdNumber in the gateway config to this number (E.164 format)

4. Configure the Gateway Plugin

Add the Twilio route to your voip-settings.json:

{
    "gateways": {
        "routes": [
            {
                "plugin": "libgw-twilio.so",
                "prefixes": ["+", "00"],
                "config": {
                    "trunkHost": "your-trunk.pstn.twilio.com",
                    "trunkPort": 5060,
                    "transport": "udp",
                    "username": "your-credential-list-username",
                    "password": "your-credential-list-password",
                    "callerIdNumber": "+441234567890",
                    "allowedIps": [
                        "54.172.60.0/23",
                        "54.244.51.0/24",
                        "34.203.250.0/23",
                        "54.171.127.192/26",
                        "35.156.191.128/25",
                        "54.65.63.192/26",
                        "54.169.127.128/26",
                        "54.252.254.64/26"
                    ],
                    "codecs": ["PCMU", "PCMA"]
                }
            }
        ]
    }
}

5. Configure Allowed IPs

Twilio's signalling IPs must be whitelisted so the server can validate inbound trunk traffic. The allowedIps list in the config above contains Twilio's current IP ranges. Check Twilio's documentation for the latest ranges for your region.

Testing

Start the Server

./build/bin/gva-voip-server --domain=0 -f /etc/gva-voip-server/voip-settings.json

Place an Outbound Call

Dial a PSTN number from the VoIP client. The + or 00 prefix routes through the Twilio gateway:

Dialed: +441234567890

Verify in Logs

Check the server logs for gateway activity:

[gateway] Twilio: Ready (trunk: your-trunk.pstn.twilio.com:5060/udp)
[gateway] Routing +441234567890 via twilio (prefix: "+")
[gateway] Twilio: 100 Trying
[gateway] Twilio: 180 Ringing
[gateway] Twilio: 200 OK (call connected)

Verify in Twilio Console

Navigate to Monitor → Logs → Programmable Voice in the Twilio Console to see call records and any error codes.

Troubleshooting

Symptom Likely Cause Fix
403 Forbidden on outbound Credential mismatch Verify username/password match Twilio credential list
No audio after connect NAT/firewall blocking RTP Ensure UDP 10000-10100 is open; check external IP
408 Request Timeout inbound Trunk can't reach server Verify Origination URI and firewall rules for port 5080
488 Not Acceptable Codec mismatch Ensure PCMU or PCMA is in both trunk and client config
Calls drop after 30s Missing ACK/keepalive Check NAT timeout settings; enable SIP session timers

Security Considerations

  • IP Whitelisting: Always validate inbound trunk traffic against Twilio's published IP ranges
  • TLS Transport: For production, consider transport: "tls" with Twilio's secure trunk endpoints
  • Credential Rotation: Rotate Twilio credentials periodically
  • Rate Limiting: Configure max concurrent trunk calls to prevent toll fraud

See Also