Asterisk 18 PJSIP response Unauthorized 401 in a INVITE for a registered trunk

I have an Asterisk 18 PJSIP that response Unauthorized 401 in a INVITE for a registered trunk when receive calls.

Here is the settings:






The trunk is registered, but when it receives calls return 401 “Unauthorized” as bellow:

    -- Contact 100940102/sip:100940102@;x-ast-orig-host= is now Unreachable.  RTT: 0.000 msec
<--- Received SIP request (1007 bytes) from UDP: --->
INVITE sip:6430517999@ SIP/2.0
Via: SIP/2.0/UDP;branch=z9hG4bK+0f4f2effab344b09e6994efe6e1c9c3e1+sip+4+affb3393
From: <>;tag=
To: <>
CSeq: 1056043366 INVITE
Expires: 180
Content-Length: 173
Call-Info: <sip:>;method="NOTIFY;Event=telephone-event;Duration=2000"
Supported: resource-priority,siprec
Contact: <sip:bc09e2ebe56528149443df48b9545573@>
Content-Type: application/sdp
Allow-Events: message-summary,refer,dialog,line-seize,presence,call-info,as-feature-event,calling-name,ua-profile
Call-ID: 0gQAAC8WAAACBAAALxYAADwFnoyIm9FMzuTXazy9x1kCi4rC76KM3a5xa3Mg/Uww@
Max-Forwards: 59
Accept: application/sdp, application/dtmf-relay

o=- 78681103284218 78681103284218 IN IP4
c=IN IP4
t=0 0
m=audio 22570 RTP/AVP 8 101
a=rtpmap:101 telephone-event/8000

<--- Transmitting SIP response (647 bytes) to UDP: --->
SIP/2.0 401 Unauthorized
Via: SIP/2.0/UDP;rport=5060;received=;branch=z9hG4bK+0f4f2effab344b09e6994efe6e1c9c3e1+sip+4+affb3393
Call-ID: 0gQAAC8WAAACBAAALxYAADwFnoyIm9FMzuTXazy9x1kCi4rC76KM3a5xa3Mg/Uww@
From: <>;tag=
To: <>;tag=z9hG4bK+0f4f2effab344b09e6994efe6e1c9c3e1+sip+4+affb3393
CSeq: 1056043366 INVITE
WWW-Authenticate: Digest realm="asterisk",nonce="1713493301/04374a3e70b4096eb242776aa9184f8d",opaque="70954d2c55512c9c",algorithm=MD5,qop="auth"
Server: Ligmee
Content-Length:  0

<--- Received SIP request (484 bytes) from UDP: --->
ACK sip:6430517999@ SIP/2.0
Via: SIP/2.0/UDP;branch=z9hG4bK+0f4f2effab344b09e6994efe6e1c9c3e1+sip+4+affb3393
From: <>;tag=
To: <>;tag=z9hG4bK+0f4f2effab344b09e6994efe6e1c9c3e1+sip+4+affb3393
CSeq: 1056043366 ACK
Content-Length: 0
Call-ID: 0gQAAC8WAAACBAAALxYAADwFnoyIm9FMzuTXazy9x1kCi4rC76KM3a5xa3Mg/Uww@
Max-Forwards: 59

Can anyone helps?

Add this IP address to your identify section as well:, and then try again.

@ambiorixg12 I changed, same issue.

The difference is that before the Asterisk is logging in console the message bellow, actually doesn’t do that anymore, but I can see the 401 with debug mode.

[Apr 19 10:01:08] NOTICE[741877]: res_pjsip/pjsip_distributor.c:673 log_failed_request: Request ‘INVITE’ from ‘’ failed for ‘’ (callid: 0gQAAC8WAAACBAAALxYAALuIIlkwDU+ztlpjWzKKg26NuHVxmSdh5MuQqFGGHInj@ - No matching endpoint found

I was comparing this scenario with other trunk we have that works well.

The unique difference is the “To” field another trunks request arrived with our IP “” and in this scenario the invite arrive as “”. Is it possible ignore the validation on this step, or change the domain to server IP?


These other trunks doesnt require authentication.

Asterisk doesn’t use the To header except for registrations (and then it only, normally, uses the user part), or when explicitly read by user code.

Also, this is not a validation problem. It has failed to identify the endpoint, and, until you identify an endpoint, you cannot validate it.

For some reason, your type=identify section appears to be failing. Are you trying to use a minimal set of modules? You may have failed to load the module that matches by IP address.

Well, One point, I am using realtime…

And we have others trunks working perfectly, the difference is these others doesn’t use auths.

The error is failed to identify, not authentication error. Also the only authentication settings you have, in the information you have provided here, are outbound ones, and this is an inbound call.

The reason you are getting a 401 is so that an attacker cannot tell the difference between an unknown caller and a known one with the wrong password. chan_sip had an always_auth_reject one, that caused this behaviour, rather than a more explicit rejection reason, although there would still be rejections, unless you allowed guest callers. I’m not sure if chan_pjsip has an option; it may always send 401 to callers who don’t match anything.

It is sending authentication required when it really means you are not a permitted caller.

@david551 It doesn’t have a toggle for it, it always behaves this way.

This issue was solved, I was filling the field auth of the section endpoint, that was not sending in my settings in the post (It happens because in my tests I changed the params many times).

Thank you to all.

Now I have an issue to make calls, but I will open another topic, if necessary.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.