Multiple Incoming calls are failing

I have multiple calls incoming calls failing. Below is a good call versus a bad call.

From non-working call:
##Twilio extends the Invite to the PBX
INVITE sip:[email protected] SIP/2.0
Record-Route: sip:54.244.51.1;lr
From: sip:[email protected]:5060;isup-oli=62;pstn-params=9084818088;tag=80821793_c3356d0b_e6df40e9-b3d6-42f0-9401-37eb2bf4c00c
To: <sip:+ [email protected]>
CSeq: 197935 INVITE
Max-Forwards: 63
P-Asserted-Identity: <sip:[email protected]:5060>
Diversion: <sip:[email protected]>;reason=unconditional
Call-ID: [email protected]
Via: SIP/2.0/UDP 54.244.51.1:5060;branch=z9hG4bK9c15.7f33aeb479b845b2930c6f75cf840c0d.0
Via: SIP/2.0/UDP 172.18.81.147:5060;rport=5060;branch=z9hG4bKe6df40e9-b3d6-42f0-9401-37eb2bf4c00c_c3356d0b_623-15835286626790337852
Contact: sip:[email protected]:5060;transport=udp
Allow: INVITE,ACK,CANCEL,BYE,REFER,NOTIFY,OPTIONS
X-Twilio-VerStat: TN-Validation-Passed-A
X-Twilio-AccountSid: AC1055be922b479f6263a9f8cb8f90d80e
User-Agent: Twilio Gateway
Content-Type: application/sdp
X-Twilio-CallSid: CAe4619bbab3cc33606876017178157073
Content-Length: 276

v=0
o=root 165815579 165815579 IN IP4 172.18.97.123
s=Twilio Media Gateway
c=IN IP4 168.86.145.118
t=0 0
m=audio 11990 RTP/AVP 0 8 101
a=rtpmap:0 PCMU/8000
a=rtpmap:8 PCMA/8000
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-16
a=ptime:20
a=maxptime:20
a=sendrecv

##And the PBX (FPBX-16.0.40.13(16.30.0)) replied with 404 Not Found
SIP/2.0 404 Not Found
Via: SIP/2.0/UDP 54.244.51.1:5060;branch=z9hG4bK9c15.7f33aeb479b845b2930c6f75cf840c0d.0;received=54.244.51.1;rport=5060
Via: SIP/2.0/UDP 172.18.81.147:5060;rport=5060;branch=z9hG4bKe6df40e9-b3d6-42f0-9401-37eb2bf4c00c_c3356d0b_623-15835286626790337852
From: sip:[email protected]:5060;isup-oli=62;pstn-params=9084818088;tag=80821793_c3356d0b_e6df40e9-b3d6-42f0-9401-37eb2bf4c00c
To: <sip:[email protected]>;tag=as4f779f3d
Call-ID: [email protected]
CSeq: 197935 INVITE
Server: FPBX-16.0.40.13(16.30.0)
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE
Supported: replaces, timer
Content-Length: 0

From a working call:

##Twilio sends Invite to the PBX
INVITE sip:[email protected] SIP/2.0
Record-Route: sip:54.244.51.2;lr
From: sip:[email protected]:5060;isup-oli=62;pstn-params=9084818088;tag=37661217_c3356d0b_fa3f09a0-67e1-4e45-b868-0f2f98db416f
To: <sip:[email protected]>
CSeq: 372807 INVITE
Max-Forwards: 63
P-Asserted-Identity: <sip:[email protected]:5060>
Diversion: <sip:[email protected]>;reason=unconditional
Call-ID: [email protected]
Via: SIP/2.0/UDP 54.244.51.2:5060;branch=z9hG4bK80be.e42d33cdf2e80c6de8e49d62fceaf4c3.0
Via: SIP/2.0/UDP 172.18.78.33:5060;rport=5060;branch=z9hG4bKfa3f09a0-67e1-4e45-b868-0f2f98db416f_c3356d0b_579-15405402317341848310
Contact: sip:[email protected]:5060;transport=udp
Allow: INVITE,ACK,CANCEL,BYE,REFER,NOTIFY,OPTIONS
X-Twilio-VerStat: TN-Validation-Passed-A
X-Twilio-AccountSid: AC1055be922b479f6263a9f8cb8f90d80e
User-Agent: Twilio Gateway
Content-Type: application/sdp
X-Twilio-CallSid: CA5785fccb3ccb1aec69f3a0a74ec4abe5
Content-Length: 275

v=0
o=root 974674597 974674597 IN IP4 172.18.97.11
s=Twilio Media Gateway
c=IN IP4 168.86.145.142
t=0 0
m=audio 15494 RTP/AVP 0 8 101
a=rtpmap:0 PCMU/8000
a=rtpmap:8 PCMA/8000
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-16
a=ptime:20
a=maxptime:20
a=sendrecv

##And Twilio receives 200 OK from the PBX
SIP/2.0 200 OK
Via: SIP/2.0/UDP 54.244.51.2:5060;branch=z9hG4bK80be.e42d33cdf2e80c6de8e49d62fceaf4c3.0;received=54.244.51.2;rport=5060
Via: SIP/2.0/UDP 172.18.78.33:5060;rport=5060;branch=z9hG4bKfa3f09a0-67e1-4e45-b868-0f2f98db416f_c3356d0b_579-15405402317341848310
Record-Route: sip:54.244.51.2;lr
From: sip:[email protected]:5060;isup-oli=62;pstn-params=9084818088;tag=37661217_c3356d0b_fa3f09a0-67e1-4e45-b868-0f2f98db416f
To: <sip:[email protected]>;tag=as38bcd11d
Call-ID: [email protected]
CSeq: 372807 INVITE
Server: FPBX-16.0.40.13(16.30.0)
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE
Supported: replaces, timer
Contact: <sip:[email protected]:5060>
Content-Type: application/sdp
Content-Length: 278

v=0
o=root 564956469 564956469 IN IP4 184.190.137.60
s=Asterisk PBX 16.30.0
c=IN IP4 184.190.137.60
t=0 0
m=audio 47768 RTP/AVP 0 8 101
a=rtpmap:0 PCMU/8000
a=rtpmap:8 PCMA/8000
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-16
a=ptime:20
a=maxptime:150
a=sendrecv

I think we’ll need the full log, with enough verbosity to to see why the call was rejected, in the first case, and how it was handled, in the second.

Starting guess is that the first one came form and address which wasn’t in your match/permit settings, but you’ve lost the source address, from the log.

I’m assuming the bogus space, in the To header, is a mistake in transcribing the logs, not real.

Check that Match/Permit for your trunk includes 54.244.51.0/30 ; see

If that’s not your issue, paste the Asterisk log for a failing call, with pjsip logger on, at pastebin.com and post the link here.

Not lost at all. The Via headers of the two INVITEs show sent from 54.244.51.1 and 54.244.51.2 respectively. The received= tags of the Via headers of the responses confirm the correctness of the INVITE Via headers (not butchered by firewall, etc.)

I just uploadded the log file. I belive you are correct I might be missing that IP ragn


Attached is how I have it configured, I imagine I have to do the same for 54.244.51.1 and 54.244.51.2. do I have to do it individual or can I do as one or on the firewall as allowed?

Delete all the chan_sip trunks with names beginning with 54.
In the Advanced settings for Twilio_Trunk, set Match (Permit) to the addresses from which Twilio can send calls. It should include
54.244.51.0/30
If you still have trouble, paste the Asterisk log (with pjsip logger turned on) for a failing call, as noted previously.