Pre-Configuration Checklist

Before configuring your SIP trunk, ensure the following prerequisites are met:

Check ItemRequirementVerification
Network BandwidthG.711: 87kbps/call, G.729: 31kbps/callFormula: calls × per-call bandwidth × 1.3 overhead
SIP Signaling Port5060 UDP/TCP or 5061 TLStelnet/traceroute port reachability test
RTP Media Ports10000-65535 UDP (open sub-range as needed)Firewall rule confirmation
DNS ResolutionSIP domain resolves correctlynslookup/dig verification
Static IPStatic public IP recommendedcurl ifconfig.me to confirm
Time SyncNTP synchronized, drift <1 secondntpstat check

Asterisk Configuration

sip.conf Example

; /etc/asterisk/sip.conf

[cainiao-trunk]
type=peer
host=sip.cainiaovoice.com
port=5060
transport=udp
context=from-cainiao
disallow=all
allow=g711
allow=g729
allow=g722
dtmfmode=rfc2833
insecure=port,invite
qualify=yes
qualifyfreq=60
nat=force_rport,comedia
canreinvite=no

; SIP registration (if required)
register => username:password@sip.cainiaovoice.com:5060/100

extensions.conf Dialplan

; /etc/asterisk/extensions.conf

[from-cainiao]
; Inbound call handling
exten => _X.,1,NoOp(Inbound call from ${CALLERID(num)})
exten => _X.,n,Dial(SIP/1001,30)
exten => _X.,n,Hangup()

[outbound-cainiao]
; Domestic outbound
exten => _NXXXXXXXXX,1,NoOp(Calling ${EXTEN})
exten => _NXXXXXXXXX,n,Dial(SIP/cainiao-trunk/${EXTEN})
exten => _NXXXXXXXXX,n,Hangup()

; International outbound
exten => _011X.,1,NoOp(International call to ${EXTEN})
exten => _011X.,n,Dial(SIP/cainiao-trunk/${EXTEN:3})
exten => _011X.,n,Hangup()

Key Configuration Notes

  • dtmfmode=rfc2833: Recommended for best DTMF compatibility
  • nat=force_rport,comedia: NAT traversal — resolves one-way audio issues
  • qualify=yes: Enables keepalive heartbeat to monitor gateway connectivity
  • canreinvite=no: Prevents direct RTP, ensuring media flows through Asterisk

FreeSWITCH Configuration

Gateway Configuration

<!-- /etc/freeswitch/sip_profiles/external/cainiao.xml -->
<include>
  <gateway name="cainiao-trunk">
    <param name="realm" value="sip.cainiaovoice.com"/>
    <param name="username" value="your_username"/>
    <param name="password" value="your_password"/>
    <param name="register" value="true"/>
    <param name="caller-id-in-from" value="true"/>
    <param name="ping-interval" value="30"/>
    <param name="extension" value="100"/>
  </gateway>
</include>

Dialplan

<!-- /etc/freeswitch/conf/dialplan/default.xml -->
<extension name="outbound-cainiao">
  <condition field="destination_number" expression="^(.+)$">
    <action application="set" data="effective_caller_id_number=your_did"/>
    <action application="bridge" data="sofia/gateway/cainiao-trunk/$1"/>
  </condition>
</extension>

3CX Quick Setup

  1. Navigate to 3CX Admin → SIP Trunks → Add SIP Trunk
  2. Select "Generic SIP Trunk" template
  3. Enter: Main Server=sip.cainiaovoice.com, Port=5060
  4. Authentication ID=your_username, Password=your_password
  5. Select Bridge mode, configure STUN server (stun.3cx.com)
  6. Choose G.711 and G.729 codecs
  7. Create inbound/outbound routing rules

Cisco CUCM Setup

  1. Create SIP Trunk Security Profile: Device → Device Settings → SIP Trunk Security Profile
  2. Create SIP Profile: Select standard SIP Profile, enable SIP OPTIONS Ping
  3. Create SIP Trunk: Device → Trunk, select Security Profile and SIP Profile created above
  4. Configure Destination Address: sip.cainiaovoice.com:5060
  5. Create Route Pattern: Call Routing → Route/Hunt → Route Pattern
  6. Set Calling Search Space and Partition permissions

Troubleshooting Checklist

IssuePossible CauseTroubleshooting Steps
One-way audioNAT issues, RTP ports blocked1) Check firewall RTP ports 2) Configure nat parameters 3) Verify SDP IP reachable 4) Use rtp debug
Registration failureWrong credentials, port blocked1) sip debug for 401/403 2) telnet test port 5060 3) Verify username/password
DTMF not workingDTMF mode mismatch1) Verify matching dtmfmode 2) Prefer rfc2833 3) Avoid SIP INFO
Codec negotiation failureNo common codec1) sip debug for 488 response 2) Check disallow/allow 3) Ensure G.711 enabled
Call dropsSIP timeout, route instability1) Check qualify heartbeat 2) Review BYE reason code 3) Check jitter/packet loss
SIP 503 errorService unavailable, capacity exceeded1) Check concurrent channels 2) Contact provider 3) Configure failover route

Security Hardening Checklist

  • IP Whitelisting: Only allow SIP provider IPs on ports 5060/5061 and RTP range
  • SIP TLS: Use TLS (port 5061) to encrypt SIP signaling
  • SRTP: Enable SRTP to encrypt RTP media streams
  • Strong Passwords: 16+ character random passwords, rotate regularly
  • fail2ban: Auto-ban malicious IPs attempting brute force
  • International Call ACLs: Whitelist permitted international destinations to prevent toll fraud
  • Spending Limits: Configure daily/monthly limits with anomaly alerts
  • Disable Public AMI/HTTP: Never expose management interfaces to the internet

Cainiao Voice Security: Our SIP trunk service supports IP whitelist authentication by default, optional SIP TLS + SRTP encryption, and provides real-time traffic monitoring with anomaly alerts.

Frequently Asked Questions

Q: What ports need to be open for Asterisk SIP trunk?

A: Open SIP signaling port 5060 (UDP/TCP) or 5061 (TLS), and the RTP media port range (typically 10000-20000 UDP). Configure IP whitelisting on your firewall to only allow the SIP provider's IP addresses.

Q: How to configure FreeSWITCH SIP trunk gateway?

A: Create an XML gateway config file in /etc/freeswitch/sip_profiles/external/, setting realm (server address), username, password, and register parameters. Use sofia/gateway/gatewayname/number format in your dialplan.

Q: How to troubleshoot one-way audio?

A: One-way audio is typically caused by NAT issues. Steps: 1) Check RTP port firewall rules; 2) Configure nat=force_rport,comedia in Asterisk; 3) Set ext-rtp-ip and ext-sip-ip in FreeSWITCH; 4) Verify SDP IP addresses are reachable.

Q: Which DTMF mode should I use?

A: RFC2833 is recommended (dtmfmode=rfc2833 in Asterisk). SIP INFO has poor compatibility. INBAND requires G.711 codec. Most SIP trunk providers support RFC2833.

Q: How to prevent SIP toll fraud?

A: Measures include: 1) IP whitelisting for provider IPs only; 2) International call permission whitelists; 3) Daily spending limits; 4) fail2ban for brute force protection; 5) Strong passwords (16+ random characters); 6) Abnormal call pattern monitoring.

Need SIP Trunk Integration Support?

Cainiao Voice's technical team provides free Asterisk/FreeSWITCH/3CX configuration assistance

Free Consultation