SIP trunking error Failed to authenticate on INVITE to

Hi, I have two machines (with Asterisk on it) and I’m calling one machine from another through SIP trunking. I have made two SIP extension’s with type=peer and host= each other’s IP address.

When I call Dial() to dial one SIP extension on serverA to another on serverB it works, but it doesn’t work the other way around i.e. from serverB to serverA. When I do I get the error: "NOTICE[9243]: chan_sip.c:18458 handle_response_invite: Failed to authenticate on INVITE to "

[code]== START ==

<— SIP read from UDP:192.168.3.5:5060 —>
INVITE sip:111@192.168.3.114 SIP/2.0
Via: SIP/2.0/UDP 192.168.3.5:5060;branch=z9hG4bK2e2c8cd5;rport
Max-Forwards: 70
From: “101” sip:101@192.168.3.5;tag=as530a28cb
To: sip:111@192.168.3.114
Contact: sip:101@192.168.3.5
Call-ID: 5127c238769cb8ce3826d6ff094af781@192.168.3.5
CSeq: 102 INVITE
User-Agent: Asterisk PBX 1.6.2.22
Date: Tue, 11 Sep 2012 10:15:01 GMT
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO
Supported: replaces, timer
Content-Type: application/sdp
Content-Length: 282

v=0
o=root 1309525921 1309525921 IN IP4 192.168.3.5
s=Asterisk PBX 1.6.2.22
c=IN IP4 192.168.3.5
t=0 0
m=audio 19266 RTP/AVP 0 3 8 101
a=rtpmap:0 PCMU/8000
a=rtpmap:3 GSM/8000
a=rtpmap:8 PCMA/8000
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-16
a=ptime:20
a=sendrecv

<------------->
— (14 headers 13 lines) —
== Using SIP RTP CoS mark 5
Sending to 192.168.3.5 : 5060 (NAT)
Using INVITE request as basis request - 5127c238769cb8ce3826d6ff094af781@192.168.3.5
Found peer ‘101’ for ‘101’ from 192.168.3.5:5060

<— Reliably Transmitting (NAT) to 192.168.3.5:5060 —>
SIP/2.0 401 Unauthorized
Via: SIP/2.0/UDP 192.168.3.5:5060;branch=z9hG4bK2e2c8cd5;received=192.168.3.5;rport=5060
From: “101” sip:101@192.168.3.5;tag=as530a28cb
To: sip:111@192.168.3.114;tag=as33886021
Call-ID: 5127c238769cb8ce3826d6ff094af781@192.168.3.5
CSeq: 102 INVITE
Server: Asterisk PBX 1.6.2.22
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO
Supported: replaces, timer
WWW-Authenticate: Digest algorithm=MD5, realm=“asterisk”, nonce="3ce26e8c"
Content-Length: 0

<------------>
Scheduling destruction of SIP dialog ‘5127c238769cb8ce3826d6ff094af781@192.168.3.5’ in 32000 ms (Method: INVITE)

<— SIP read from UDP:192.168.3.5:5060 —>
ACK sip:111@192.168.3.114 SIP/2.0
Via: SIP/2.0/UDP 192.168.3.5:5060;branch=z9hG4bK2e2c8cd5;rport
Max-Forwards: 70
From: “101” sip:101@192.168.3.5;tag=as530a28cb
To: sip:111@192.168.3.114;tag=as33886021
Contact: sip:101@192.168.3.5
Call-ID: 5127c238769cb8ce3826d6ff094af781@192.168.3.5
CSeq: 102 ACK
User-Agent: Asterisk PBX 1.6.2.22
Content-Length: 0

<------------->
— (10 headers 0 lines) —

<— SIP read from UDP:192.168.3.131:65076 —>

<------------->
Really destroying SIP dialog ‘5127c238769cb8ce3826d6ff094af781@192.168.3.5’ Method: ACK
localhost*CLI>

== END ==

== extensions.conf ==

[access]
exten => 111,1,Answer()
same => n,AGI(agi://192.168.3.131/testtreatment)

exten => 222,1,Dial(SIP/avaya/115)
same => n,AGI(agi://192.168.3.131/testtreatment)

== sip.conf ==
[100]
type=friend
context=access
secret=100
host=dynamic
allow=all

[101]
type=friend
context=access
secret=101
host=dynamic
allow=all

[avaya]
host=192.168.3.5
type=peer
context=access
nat=yes
registersip=yes
insecure=port,invite
username=
secret=[/code]

Another machine


== START ==



    -- Executing [116@test:1] Dial("SIP/101-00000014", "SIP/1101/111") in new stack
  == Using SIP RTP CoS mark 5
Audio is at 192.168.3.5 port 19266
Adding codec 0x4 (ulaw) to SDP
Adding codec 0x2 (gsm) to SDP
Adding codec 0x8 (alaw) to SDP
Adding non-codec 0x1 (telephone-event) to SDP
Reliably Transmitting (NAT) to 192.168.3.114:5060:
INVITE sip:111@192.168.3.114 SIP/2.0
Via: SIP/2.0/UDP 192.168.3.5:5060;branch=z9hG4bK2e2c8cd5;rport
Max-Forwards: 70
From: "101" <sip:101@192.168.3.5>;tag=as530a28cb
To: <sip:111@192.168.3.114>
Contact: <sip:101@192.168.3.5>
Call-ID: 5127c238769cb8ce3826d6ff094af781@192.168.3.5
CSeq: 102 INVITE
User-Agent: Asterisk PBX 1.6.2.22
Date: Tue, 11 Sep 2012 10:15:01 GMT
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO
Supported: replaces, timer
Content-Type: application/sdp
Content-Length: 282

v=0
o=root 1309525921 1309525921 IN IP4 192.168.3.5
s=Asterisk PBX 1.6.2.22
c=IN IP4 192.168.3.5
t=0 0
m=audio 19266 RTP/AVP 0 3 8 101
a=rtpmap:0 PCMU/8000
a=rtpmap:3 GSM/8000
a=rtpmap:8 PCMA/8000
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-16
a=ptime:20
a=sendrecv

---
    -- Called 1101/111

<--- SIP read from UDP:192.168.3.114:5060 --->
SIP/2.0 401 Unauthorized
Via: SIP/2.0/UDP 192.168.3.5:5060;branch=z9hG4bK2e2c8cd5;received=192.168.3.5;rport=5060
From: "101" <sip:101@192.168.3.5>;tag=as530a28cb
To: <sip:111@192.168.3.114>;tag=as33886021
Call-ID: 5127c238769cb8ce3826d6ff094af781@192.168.3.5
CSeq: 102 INVITE
Server: Asterisk PBX 1.6.2.22
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO
Supported: replaces, timer
WWW-Authenticate: Digest algorithm=MD5, realm="asterisk", nonce="3ce26e8c"
Content-Length: 0


<------------->
--- (11 headers 0 lines) ---
Transmitting (NAT) to 192.168.3.114:5060:
ACK sip:111@192.168.3.114 SIP/2.0
Via: SIP/2.0/UDP 192.168.3.5:5060;branch=z9hG4bK2e2c8cd5;rport
Max-Forwards: 70
From: "101" <sip:101@192.168.3.5>;tag=as530a28cb
To: <sip:111@192.168.3.114>;tag=as33886021
Contact: <sip:101@192.168.3.5>
Call-ID: 5127c238769cb8ce3826d6ff094af781@192.168.3.5
CSeq: 102 ACK
User-Agent: Asterisk PBX 1.6.2.22
Content-Length: 0


---
[Sep 11 15:15:01] NOTICE[9243]: chan_sip.c:18458 handle_response_invite: Failed to authenticate on INVITE to '"101" <sip:101@192.168.3.5>;tag=as530a28cb'
    -- SIP/1101-00000015 is circuit-busy
  == Everyone is busy/congested at this time (1:0/1/0)
    -- Auto fallthrough, channel 'SIP/101-00000014' status is 'CONGESTION'

<--- Reliably Transmitting (NAT) to 192.168.3.117:60700 --->
SIP/2.0 503 Service Unavailable
Via: SIP/2.0/UDP 192.168.3.117:60700;branch=z9hG4bK-d8754z-a0547937a31fc871-1---d8754z-;received=192.168.3.117;rport=60700
From: "101"<sip:101@192.168.3.5:5060>;tag=5640e519
To: <sip:116@192.168.3.5:5060>;tag=as0857e306
Call-ID: ZjFlNTkxN2NiYWY0NmNkNDBiN2MzMTU3NmM0ZmIzNmY.
CSeq: 2 INVITE
Server: Asterisk PBX 1.6.2.22
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO
Supported: replaces, timer
X-Asterisk-HangupCause: Call Rejected
X-Asterisk-HangupCauseCode: 21
Content-Length: 0


<------------>

<--- SIP read from UDP:192.168.3.117:60700 --->
ACK sip:116@192.168.3.5:5060 SIP/2.0
Via: SIP/2.0/UDP 192.168.3.117:60700;branch=z9hG4bK-d8754z-a0547937a31fc871-1---d8754z-;rport
Max-Forwards: 70
To: <sip:116@192.168.3.5:5060>;tag=as0857e306
From: "101"<sip:101@192.168.3.5:5060>;tag=5640e519
Call-ID: ZjFlNTkxN2NiYWY0NmNkNDBiN2MzMTU3NmM0ZmIzNmY.
CSeq: 2 ACK
Content-Length: 0


<------------->
--- (8 headers 0 lines) ---
Really destroying SIP dialog '5127c238769cb8ce3826d6ff094af781@192.168.3.5' Method: INVITE
Really destroying SIP dialog 'ZjFlNTkxN2NiYWY0NmNkNDBiN2MzMTU3NmM0ZmIzNmY.' Method: ACK

<--- SIP read from UDP:192.168.3.117:60700 --->



<------------->
Really destroying SIP dialog 'ZjdmZGFhYTY1YTFkMWNhZDZhMGE5N2Y0YTMwNDIwOWU.' Method: REGISTER
localhost*CLI>






== END == 



== extensions.conf ==

[test]
;exten => 115,1,Dial(SIP/100/111)

exten => 115,1,Answer()
same => n,Queue(Mezn)

exten => 116,1,Dial(SIP/1101/111)




== sip.conf ==

[1101]
type=peer
context=test
nat=yes
registersip=yes
insecure=port,invite
username=
secret=
host=192.168.3.114
;allow=all


[101]
type=friend
context=test
host=dynamic
allow=all
secret=101

Can anyone point any errors?

Use type=peer for the “extensions”. Asterisk is probably trying to match caller-ID against an extension.