Call drops after 30 secs and sip 401 unauthorized message

Hello guys,

I have asterisk 13.2.0 hosted on EC2 Amazon and two sip endpoints behind the same NAT. the problem is that when I make a call audio pass normally but after 30 secs the call is dropped.

asterisk server : public ip : 52.150. …
private server is in the following range: 172.31.32.0/20

here is my pjsip.conf configurations

[simpletrans]
type=transport
protocol=udp
bind=0.0.0.0:5061
local_net=172.31.32.0/20
external_media_address=52.25…
external_signaling_address=50.25…

[6002]
type=endpoint
transport = simpletrans
context=from-internal
direct_media=no
rtp_symmetric=yes
force_rport=yes
ice_support=yes
media_address=52.25…
rewrite_contact=yes
disallow=all
allow=ulaw
auth=6002
aors=6002

[6002]
type=auth
auth_type=userpass
password=1234
username=6002

[6002]
type=aor
max_contacts=2

[6005]
type=endpoint
transport = simpletrans
context=from-internal
direct_media=no
rtp_symmetric=yes
force_rport=yes
ice_support=yes
media_address=52.25…
rewrite_contact=yes
disallow=all
allow=ulaw
auth=6005
aors=6005

[6005]
type=auth
auth_type=userpass
password=5678
username=6005

here are sip traces

ACK, MESSAGE, REGISTER, REFER
Contact: sip:50.25......:5061
Supported: 100rel, timer, replaces, norefersub
Session-Expires: 1800;refresher=uac
Require: timer
Content-Type: application/sdp
Content-Length: 667

v=0
o=- 3643358120 3643358122 IN IP4 52.25…
s=Asterisk
c=IN IP4 52.25…
t=0 0
m=audio 19020 RTP/AVP 0 101
a=ice-ufrag:28f0d25260468e3b5089974a4519d371
a=ice-pwd:34fc3c8f4a624d1c6e4c8c6e69091cb7
a=candidate:Hac1f26d2 1 UDP 2130706431 172.31… 19020 typ host
a=candidate:S34199619 1 UDP 1694498815 52.25…19020 typ srflx raddr 172.31… rport 19020
a=candidate:Hac1f26d2 2 UDP 2130706430 172.31… 19021 typ host
a=candidate:S34199619 2 UDP 1694498814 52.25… 19021 typ srflx raddr 172.31… rport 19021
a=rtpmap:0 PCMU/8000
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-16
a=ptime:20
a=maxptime:150
a=sendrecv

<— Received SIP request (896 bytes) from UDP:94.252.20.200:61840 —>
REGISTER sip:52.25…:5061 SIP/2.0
Accept: application/reginfo+xml, application/sdp, application/simple-message-summary, message/sipfrag, multipart/mixed, multipart/related
Via: SIP/2.0/UDP 192.168.178.78:5062;branch=z9hG4bK258f9c0b5f5333943;rport
Max-Forwards: 70
From: “6002” sip:6002@52.25......:5061;tag=2d71febe7e
To: “6002” sip:6002@52.25......:5061
Call-ID: fc7ea4bad486d0e3
CSeq: 2109275808 REGISTER
Allow: ACK, BYE, CANCEL, INVITE, MESSAGE, NOTIFY, OPTIONS, REFER, SUBSCRIBE, UPDATE
Authorization: Digest username=“6002”,realm=“asterisk”,nonce=“1434362076/336e2669ae68744e01ad882393f237c1”,uri=“sip:52.25…:5061”,response=“03994bd874d6ee117a66b9d812a3e89e”,algorithm=md5,opaque=“662590457d716772”,qop=auth,cnonce=“38dc4776”,nc=00000002
Contact: sip:6002@192.168.178.78:5062;audio;expires=120
User-Agent: Media5-fone/4.1.3.3034 iOS/7.1.2
Content-Length: 0

<— Transmitting SIP response (483 bytes) to UDP:94.252.20.200:61840 —>
SIP/2.0 401 Unauthorized
Via: SIP/2.0/UDP 192.168.178.78:5062;rport=61840;received=94.252.20.200;branch=z9hG4bK258f9c0b5f5333943
Call-ID: fc7ea4bad486d0e3
From: “6002” sip:6002@52.25......;tag=2d71febe7e
To: “6002” sip:6002@52.25......;tag=z9hG4bK258f9c0b5f5333943
CSeq: 2109275808 REGISTER
WWW-Authenticate: Digest realm=“asterisk”,nonce=“1434362165/9c5eda9d53d68fb26608b8430d564056”,opaque=“121f0f2608ee925c”,stale=true,algorithm=md5,qop="auth"
Content-Length: 0

<— Received SIP request (637 bytes) from UDP:94.252.20.200:61840 —>
REGISTER sip:52.25…:5061 SIP/2.0
Accept: application/reginfo+xml, application/sdp, application/simple-message-summary, message/sipfrag, multipart/mixed, multipart/related
Via: SIP/2.0/UDP 192.168.178.78:5062;branch=z9hG4bK25f0be37e07340d04;rport
Max-Forwards: 70
From: “6002” sip:6002@52.25.....:5061;tag=2d71febe7e
To: “6002” sip:6002@52.25.....:5061
Call-ID: fc7ea4bad486d0e3
CSeq: 2109275809 REGISTER
Allow: ACK, BYE, CANCEL, INVITE, MESSAGE, NOTIFY, OPTIONS, REFER, SUBSCRIBE, UPDATE
Contact: sip:6002@192.168.178.78:5062;audio;expires=120
User-Agent: Media5-fone/4.1.3.3034 iOS/7.1.2
Content-Length: 0

<— Transmitting SIP response (472 bytes) to UDP:94.252.20.200:61840 —>
SIP/2.0 401 Unauthorized
Via: SIP/2.0/UDP 192.168.178.78:5062;rport=61840;received=94.252.20.200;branch=z9hG4bK25f0be37e07340d04
Call-ID: fc7ea4bad486d0e3
From: “6002” sip:6002@52.25.....;tag=2d71febe7e
To: “6002” sip:6002@52.25......;tag=z9hG4bK25f0be37e07340d04
CSeq: 2109275809 REGISTER
WWW-Authenticate: Digest realm=“asterisk”,nonce=“1434362166/32a375a8f2ea929d013c35b6ee46da9c”,opaque=“3ef7997a50443513”,algorithm=md5,qop="auth"
Content-Length: 0

<— Received SIP request (896 bytes) from UDP:94.252.20.200:61840 —>
REGISTER sip:52.25…:5061 SIP/2.0
Accept: application/reginfo+xml, application/sdp, application/simple-message-summary, message/sipfrag, multipart/mixed, multipart/related
Via: SIP/2.0/UDP 192.168.178.78:5062;branch=z9hG4bK887090fed4987f65b;rport
Max-Forwards: 70
From: “6002” sip:6002@52.25......:5061;tag=2d71febe7e
To: “6002” sip:6002@52.25......:5061
Call-ID: fc7ea4bad486d0e3
CSeq: 2109275810 REGISTER
Allow: ACK, BYE, CANCEL, INVITE, MESSAGE, NOTIFY, OPTIONS, REFER, SUBSCRIBE, UPDATE
Authorization: Digest username=“6002”,realm=“asterisk”,nonce=“1434362166/32a375a8f2ea929d013c35b6ee46da9c”,uri=“sip:52.25…:5061”,response=“3ce35944322638f6e6e6e6aac98a5f11”,algorithm=md5,opaque=“3ef7997a50443513”,qop=auth,cnonce=“4b04d1c0”,nc=00000001
Contact: sip:6002@192.168.178.78:5062;audio;expires=120
User-Agent: Media5-fone/4.1.3.3034 iOS/7.1.2
Content-Length: 0

<— Transmitting SIP response (404 bytes) to UDP:94.252.20.200:61840 —>
SIP/2.0 200 OK
Via: SIP/2.0/UDP 192.168.178.78:5062;rport=61840;received=94.252.20.200;branch=z9hG4bK887090fed4987f65b
Call-ID: fc7ea4bad486d0e3
From: “6002” sip:6002@52.25......;tag=2d71febe7e
To: “6002” sip:6002@52.25.150.25;tag=z9hG4bK887090fed4987f65b
CSeq: 2109275810 REGISTER
Date: Mon, 15 Jun 2015 09:56:06 GMT
Contact: sip:6002@50.25......:61840;expires=119
Content-Length: 0

<— Transmitting SIP response (1307 bytes) to UDP:94.252.20.200:61835 —>
SIP/2.0 200 OK
Via: SIP/2.0/UDP 94.252.20.200:61833;rport=61835;received=94.252.20.200;branch=z9hG4bKPj316a2e35c0a24a9ca27df54025090aa9
Call-ID: f3dd132983a744eca856ccef5a880f28
From: sip:6005@52.25......;tag=cb79bd3abb98401ba1108104859dd840
To: sip:6002@52.25.......;tag=1196d68b-8fdb-47d2-9c78-6bbfbd68bfb9
CSeq: 8921 INVITE
Allow: OPTIONS, SUBSCRIBE, NOTIFY, PUBLISH, INVITE, ACK, BYE, CANCEL, UPDATE, PRACK, MESSAGE, REGISTER, REFER
Contact: sip:50.25.....:5061
Supported: 100rel, timer, replaces, norefersub
Session-Expires: 1800;refresher=uac
Require: timer
Content-Type: application/sdp
Content-Length: 667

v=0
o=- 3643358120 3643358122 IN IP4 52.25…
s=Asterisk
c=IN IP4 52.25…
t=0 0
m=audio 19020 RTP/AVP 0 101
a=ice-ufrag:28f0d25260468e3b5089974a4519d371
a=ice-pwd:34fc3c8f4a624d1c6e4c8c6e69091cb7
a=candidate:Hac1f26d2 1 UDP 2130706431 172.31… 19020 typ host
a=candidate:S34199619 1 UDP 1694498815 52.25… 19020 typ srflx raddr 172.31…rport 19020
a=candidate:Hac1f26d2 2 UDP 2130706430 172.31… 19021 typ host
a=candidate:S34199619 2 UDP 1694498814 52.25… 19021 typ srflx raddr 172.31…rport 19021
a=rtpmap:0 PCMU/8000
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-16
a=ptime:20
a=maxptime:150
a=sendrecv

<— Transmitting SIP request (360 bytes) to UDP:94.252.20.200:61835 —>
BYE sip:6005@94.252.20.200:61835;ob SIP/2.0
Via: SIP/2.0/UDP 50.25…:5061;rport;branch=z9hG4bKPj660d3ccc-668b-4735-bf1c-a1ca0816c531
From: sip:6002@52.25.....;tag=1196d68b-8fdb-47d2-9c78-6bbfbd68bfb9
To: sip:6005@52.25......;tag=cb79bd3abb98401ba1108104859dd840
Call-ID: f3dd132983a744eca856ccef5a880f28
CSeq: 27661 BYE
Content-Length: 0

The traces are incomplete and don’t include console output. Nothing immediately stands out, besides ICE being used - is it supported by the devices?

Looks like it is missing an ACK from the peer. Presumably the peer doesn’t like sip:50.25…:5061 as a contact address. 5061 is non-standard for UDP.

Hello David,

you are right , there is no ACK, could you know any cause behind this ?

It’s perfectly fine to use a different port. If the remote side considers that a problem, then ouch. As well - what are the endpoints behind NAT?

here is the first endpoint with sip register request:

private IP address for this peer :192.168.178.22
public IP:94.242.20.200

peer <------------>FritzBox-NAT -DSL<------->ASterisk

<— Received SIP request (635 bytes) from UDP:94.252.20.200:62123 —>
REGISTER sip:52.25.150.25:5061 SIP/2.0
Accept: application/reginfo+xml, application/sdp, application/simple-message-summary, message/sipfrag, multipart/mixed, multipart/related
Via: SIP/2.0/UDP 192.168.178.78:5062;branch=z9hG4bKd85ac74351020c405;rport
Max-Forwards: 70
From: “6002” sip:6002@52.25.150.25:5061;tag=ddbfee0f89
To: “6002” sip:6002@52.25.150.25:5061
Call-ID: 715836c02d2c156e
CSeq: 2113956514 REGISTER
Allow: ACK, BYE, CANCEL, INVITE, MESSAGE, NOTIFY, OPTIONS, REFER, SUBSCRIBE, UPDATE
Contact: sip:6002@192.168.178.78:5062;audio;expires=0
User-Agent: Media5-fone/4.1.3.3034 iOS/7.1.2
Content-Length: 0

<— Transmitting SIP response (472 bytes) to UDP:94.252.20.200:62123 —>
SIP/2.0 401 Unauthorized
Via: SIP/2.0/UDP 192.168.178.78:5062;rport=62123;received=94.252.20.200;branch=z9hG4bKd85ac74351020c405
Call-ID: 715836c02d2c156e
From: “6002” sip:6002@52.25.150.25;tag=ddbfee0f89
To: “6002” sip:6002@52.25.150.25;tag=z9hG4bKd85ac74351020c405
CSeq: 2113956514 REGISTER
WWW-Authenticate: Digest realm=“asterisk”,nonce=“1434385115/816fe3a568d51fdda72a0742fb6679e5”,opaque=“1460633349b3bd5b”,algorithm=md5,qop="auth"
Content-Length: 0

<— Received SIP request (894 bytes) from UDP:94.252.20.200:62123 —>
REGISTER sip:52.25.150.25:5061 SIP/2.0
Accept: application/reginfo+xml, application/sdp, application/simple-message-summary, message/sipfrag, multipart/mixed, multipart/related
Via: SIP/2.0/UDP 192.168.178.78:5062;branch=z9hG4bKcd132bca5838d6e66;rport
Max-Forwards: 70
From: “6002” sip:6002@52.25.150.25:5061;tag=ddbfee0f89
To: “6002” sip:6002@52.25.150.25:5061
Call-ID: 715836c02d2c156e
CSeq: 2113956515 REGISTER
Allow: ACK, BYE, CANCEL, INVITE, MESSAGE, NOTIFY, OPTIONS, REFER, SUBSCRIBE, UPDATE
Authorization: Digest username=“6002”,realm=“asterisk”,nonce=“1434385115/816fe3a568d51fdda72a0742fb6679e5”,uri=“sip:52.25.150.25:5061”,response=“17ce3d3f85b1ae39532e092b5ac97553”,algorithm=md5,opaque=“1460633349b3bd5b”,qop=auth,cnonce=“7bc35eba”,nc=00000001
Contact: sip:6002@192.168.178.78:5062;audio;expires=0
User-Agent: Media5-fone/4.1.3.3034 iOS/7.1.2
Content-Length: 0

-- Attempted to remove non-existent contact 'sip:6002@94.252.20.200:62123' from AOR '6002' by request

<— Transmitting SIP response (352 bytes) to UDP:94.252.20.200:62123 —>
SIP/2.0 200 OK
Via: SIP/2.0/UDP 192.168.178.78:5062;rport=62123;received=94.252.20.200;branch=z9hG4bKcd132bca5838d6e66
Call-ID: 715836c02d2c156e
From: “6002” sip:6002@52.25.150.25;tag=ddbfee0f89
To: “6002” sip:6002@52.25.150.25;tag=z9hG4bKcd132bca5838d6e66
CSeq: 2113956515 REGISTER
Date: Mon, 15 Jun 2015 16:18:35 GMT
Content-Length: 0

<— Received SIP request (637 bytes) from UDP:94.252.20.200:62123 —>
REGISTER sip:52.25.150.25:5061 SIP/2.0
Accept: application/reginfo+xml, application/sdp, application/simple-message-summary, message/sipfrag, multipart/mixed, multipart/related
Via: SIP/2.0/UDP 192.168.178.78:5062;branch=z9hG4bK7dd787588bb770587;rport
Max-Forwards: 70
From: “6002” sip:6002@52.25.150.25:5061;tag=ac5633e484
To: “6002” sip:6002@52.25.150.25:5061
Call-ID: 57f3568f116f697b
CSeq: 1297658023 REGISTER
Allow: ACK, BYE, CANCEL, INVITE, MESSAGE, NOTIFY, OPTIONS, REFER, SUBSCRIBE, UPDATE
Contact: sip:6002@192.168.178.78:5062;audio;expires=120
User-Agent: Media5-fone/4.1.3.3034 iOS/7.1.2
Content-Length: 0

<— Transmitting SIP response (472 bytes) to UDP:94.252.20.200:62123 —>
SIP/2.0 401 Unauthorized
Via: SIP/2.0/UDP 192.168.178.78:5062;rport=62123;received=94.252.20.200;branch=z9hG4bK7dd787588bb770587
Call-ID: 57f3568f116f697b
From: “6002” sip:6002@52.25.150.25;tag=ac5633e484
To: “6002” sip:6002@52.25.150.25;tag=z9hG4bK7dd787588bb770587
CSeq: 1297658023 REGISTER
WWW-Authenticate: Digest realm=“asterisk”,nonce=“1434385116/26c8c45fc6e3d66dee9364e758911ef2”,opaque=“7a8228f564b7a7b1”,algorithm=md5,qop="auth"
Content-Length: 0

<— Received SIP request (896 bytes) from UDP:94.252.20.200:62123 —>
REGISTER sip:52.25.150.25:5061 SIP/2.0
Accept: application/reginfo+xml, application/sdp, application/simple-message-summary, message/sipfrag, multipart/mixed, multipart/related
Via: SIP/2.0/UDP 192.168.178.78:5062;branch=z9hG4bK81e6101b16de0232b;rport
Max-Forwards: 70
From: “6002” sip:6002@52.25.150.25:5061;tag=ac5633e484
To: “6002” sip:6002@52.25.150.25:5061
Call-ID: 57f3568f116f697b
CSeq: 1297658024 REGISTER
Allow: ACK, BYE, CANCEL, INVITE, MESSAGE, NOTIFY, OPTIONS, REFER, SUBSCRIBE, UPDATE
Authorization: Digest username=“6002”,realm=“asterisk”,nonce=“1434385116/26c8c45fc6e3d66dee9364e758911ef2”,uri=“sip:52.25.150.25:5061”,response=“9cad3d2a8ab150c9db26df0a20193534”,algorithm=md5,opaque=“7a8228f564b7a7b1”,qop=auth,cnonce=“6b807b54”,nc=00000001
Contact: sip:6002@192.168.178.78:5062;audio;expires=120
User-Agent: Media5-fone/4.1.3.3034 iOS/7.1.2
Content-Length: 0

-- Added contact 'sip:6002@94.252.20.200:62123' to AOR '6002' with expiration of 120 seconds

<— Transmitting SIP response (404 bytes) to UDP:94.252.20.200:62123 —>
SIP/2.0 200 OK
Via: SIP/2.0/UDP 192.168.178.78:5062;rport=62123;received=94.252.20.200;branch=z9hG4bK81e6101b16de0232b
Call-ID: 57f3568f116f697b
From: “6002” sip:6002@52.25.150.25;tag=ac5633e484
To: “6002” sip:6002@52.25.150.25;tag=z9hG4bK81e6101b16de0232b
CSeq: 1297658024 REGISTER
Date: Mon, 15 Jun 2015 16:18:36 GMT
Contact: sip:6002@50.25.150.25:62123;expires=119
Content-Length: 0

<— Received SIP request (639 bytes) from UDP:94.252.20.200:62123 —>
SUBSCRIBE sip:6002@52.25.150.25:5061 SIP/2.0
Accept: application/simple-message-summary
Via: SIP/2.0/UDP 192.168.178.78:5062;branch=z9hG4bK9caa32327f3d37a4b;rport
Max-Forwards: 70
From: “6002” sip:6002@52.25.150.25:5061;tag=fbdaf2c377
To: sip:6002@52.25.150.25:5061
Call-ID: a3f6f0c2fc423bd2
CSeq: 2041957276 SUBSCRIBE
Allow: ACK, BYE, CANCEL, INVITE, MESSAGE, NOTIFY, OPTIONS, REFER, SUBSCRIBE, UPDATE
Allow-Events: message-summary
Contact: sip:6002@192.168.178.78:5062;audio
Event: message-summary
Expires: 3600
Supported: eventlist, replaces, timer
User-Agent: Media5-fone/4.1.3.3034 iOS/7.1.2
Content-Length: 0

<— Transmitting SIP response (466 bytes) to UDP:94.252.20.200:62123 —>
SIP/2.0 401 Unauthorized
Via: SIP/2.0/UDP 192.168.178.78:5062;rport=62123;received=94.252.20.200;branch=z9hG4bK9caa32327f3d37a4b
Call-ID: a3f6f0c2fc423bd2
From: “6002” sip:6002@52.25.150.25;tag=fbdaf2c377
To: sip:6002@52.25.150.25;tag=z9hG4bK9caa32327f3d37a4b
CSeq: 2041957276 SUBSCRIBE
WWW-Authenticate: Digest realm=“asterisk”,nonce=“1434385116/26c8c45fc6e3d66dee9364e758911ef2”,opaque=“04d431792e90dd37”,algorithm=md5,qop="auth"
Content-Length: 0

<— Received SIP request (903 bytes) from UDP:94.252.20.200:62123 —>
SUBSCRIBE sip:6002@52.25.150.25:5061 SIP/2.0
Accept: application/simple-message-summary
Via: SIP/2.0/UDP 192.168.178.78:5062;branch=z9hG4bKfa797b64cdff64b86;rport
Max-Forwards: 70
From: “6002” sip:6002@52.25.150.25:5061;tag=fbdaf2c377
To: sip:6002@52.25.150.25:5061
Call-ID: a3f6f0c2fc423bd2
CSeq: 2041957277 SUBSCRIBE
Allow: ACK, BYE, CANCEL, INVITE, MESSAGE, NOTIFY, OPTIONS, REFER, SUBSCRIBE, UPDATE
Allow-Events: message-summary
Authorization: Digest username=“6002”,realm=“asterisk”,nonce=“1434385116/26c8c45fc6e3d66dee9364e758911ef2”,uri=“sip:6002@52.25.150.25:5061”,response=“1fe9d0d07c80ec375e1eb6db86a3c0dd”,algorithm=md5,opaque=“04d431792e90dd37”,qop=auth,cnonce=“66f2e4c2”,nc=00000001
Contact: sip:6002@192.168.178.78:5062;audio
Event: message-summary
Expires: 3600
Supported: eventlist, replaces, timer
User-Agent: Media5-fone/4.1.3.3034 iOS/7.1.2
Content-Length: 0

[Jun 15 16:18:37] NOTICE[6299]: res_pjsip_mwi.c:679 mwi_new_subscribe: AOR 6002 has no configured mailboxes. MWI subscription failed
<— Transmitting SIP response (316 bytes) to UDP:94.252.20.200:62123 —>
SIP/2.0 404 Not Found
Via: SIP/2.0/UDP 192.168.178.78:5062;rport=62123;received=94.252.20.200;branch=z9hG4bKfa797b64cdff64b86
Call-ID: a3f6f0c2fc423bd2
From: “6002” sip:6002@52.25.150.25;tag=fbdaf2c377
To: sip:6002@52.25.150.25;tag=z9hG4bKfa797b64cdff64b86
CSeq: 2041957277 SUBSCRIBE
Content-Length: 0

You are registering to a public address but specifying a private contact address.

[quote]Contact: sip:6002@192.168.178.78:5062;audio;expires=0

[/quote]

You should set up an Stun server on your SIP client, This could solve the issue

I think you mean specify the address of a STUN server.

Exactly David, thanks for the correction… English issue lol :smiley: