The call does not come for a long time and crashes

Please help me, I’ve been struggling for a week now, I can’t solve the problem.

There is:
centos 7
Asterisk 18.11.1

When I call an internal number, I see in the log that the request goes immediately, instantly, and then some long pause of 20-30 seconds, sometimes more, up to a minute, and only then a call. Call from internal number to internal. I read that sometimes there is a problem due to DNS. Changed everything to IP. Even the caching DNS server installed its own, but nothing has changed.

I don’t know where to look, what to do. I reinstalled asterisk several times.

cat pjsip.conf

[global]
user_agent=Phone
allow_reload=yes
nat=force_rport,comedia

[transport-udp]
type=transport
protocol=udp
bind=0.0.0.0:6677
external_media_address=26.89.31.175
external_signaling_address=26.89.31.175

[endpoint_tpl](!)
type=endpoint
transport=transport-udp
context=sip_local
dtmf_mode=rfc4733
media_encryption=no
aggregate_mwi=yes
use_avpf=no
message_context=messages
disable_direct_media_on_nat=yes
rtcp_mux=no
rtp_symmetric=yes
rewrite_contact=yes
force_rport=yes
direct_media=no
language=ru
disallow=all
allow=alaw
allow=gsm
media_address=26.89.31.175

[auth_tpl](!)
type=auth
auth_type=userpass

[aor_tpl](!)
type=aor
<--- Received SIP request (746 bytes) from UDP:100.65.148.136:44982 --->
INVITE sip:101@26.89.31.175:6677;transport=UDP SIP/2.0
Via: SIP/2.0/UDP 192.168.1.12:44982;branch=z9hG4bK-524287-1---f0467f055bf50947;rport
Max-Forwards: 70
Contact: <sip:202@93.185.36.44:29959;transport=UDP>
To: <sip:101@26.89.31.175:6677>
From: <sip:202@26.89.31.175:6677;transport=UDP>;tag=a6449c6d
Call-ID: QGte_MV5DwfTRG38U_pS9w..
CSeq: 1 INVITE
Allow: INVITE, ACK, CANCEL, BYE, NOTIFY, REFER, MESSAGE, OPTIONS, INFO, SUBSCRIBE
Content-Type: application/sdp
User-Agent: Zoiper v2.10.17.3-mod
Allow-Events: presence, kpml, talk
Content-Length: 179

v=0
o=Zoiper 236247790 1 IN IP4 93.185.36.44
s=Z
c=IN IP4 93.185.36.44
t=0 0
m=audio 29737 RTP/AVP 0 101 8 3
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-16
a=sendrecv

<--- Transmitting SIP response (502 bytes) to UDP:100.65.148.136:44982 --->
SIP/2.0 401 Unauthorized
Via: SIP/2.0/UDP 192.168.1.12:44982;rport=44982;received=100.65.148.136;branch=z9hG4bK-524287-1---f0467f055bf50947
Call-ID: QGte_MV5DwfTRG38U_pS9w..
From: <sip:202@26.89.31.175>;tag=a6449c6d
To: <sip:101@26.89.31.175>;tag=z9hG4bK-524287-1---f0467f055bf50947
CSeq: 1 INVITE
WWW-Authenticate: Digest realm="asterisk",nonce="1649863082/99d468c62db4792a526e75957351f923",opaque="32530c5a4cef852a",algorithm=md5,qop="auth"
Server: Asterisk PBX 18.11.1
Content-Length: 0


<--- Received SIP request (356 bytes) from UDP:100.65.148.136:44982 --->
ACK sip:101@26.89.31.175:6677;transport=UDP SIP/2.0
Via: SIP/2.0/UDP 192.168.1.12:44982;branch=z9hG4bK-524287-1---f0467f055bf50947;rport
Max-Forwards: 70
To: <sip:101@26.89.31.175>;tag=z9hG4bK-524287-1---f0467f055bf50947
From: <sip:202@26.89.31.175:6677;transport=UDP>;tag=a6449c6d
Call-ID: QGte_MV5DwfTRG38U_pS9w..
CSeq: 1 ACK
Content-Length: 0


<--- Received SIP request (1046 bytes) from UDP:100.65.148.136:44982 --->
INVITE sip:101@26.89.31.175:6677;transport=UDP SIP/2.0
Via: SIP/2.0/UDP 192.168.1.12:44982;branch=z9hG4bK-524287-1---12deb004a21b4555;rport
Max-Forwards: 70
Contact: <sip:202@93.185.36.44:29959;transport=UDP>
To: <sip:101@26.89.31.175:6677>
From: <sip:202@26.89.31.175:6677;transport=UDP>;tag=a6449c6d
Call-ID: QGte_MV5DwfTRG38U_pS9w..
CSeq: 2 INVITE
Allow: INVITE, ACK, CANCEL, BYE, NOTIFY, REFER, MESSAGE, OPTIONS, INFO, SUBSCRIBE
Content-Type: application/sdp
User-Agent: Zoiper v2.10.17.3-mod
Authorization: Digest username="202",realm="asterisk",nonce="1649863082/99d468c62db4792a526e75957351f923",uri="sip:101@26.89.31.175:6677;transport=UDP",response="32bef6ed9342518be95b2f6422079123",cnonce="0c6609e835f61208f172c8b02ea63f43",nc=00000001,qop=auth,algorithm=md5,opaque="32530c5a4cef852a"
Allow-Events: presence, kpml, talk
Content-Length: 179

v=0
o=Zoiper 236247790 1 IN IP4 93.185.36.44
s=Z
c=IN IP4 93.185.36.44
t=0 0
m=audio 29737 RTP/AVP 0 101 8 3
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-16
a=sendrecv

<--- Transmitting SIP response (310 bytes) to UDP:100.65.148.136:44982 --->
SIP/2.0 100 Trying
Via: SIP/2.0/UDP 192.168.1.12:44982;rport=44982;received=100.65.148.136;branch=z9hG4bK-524287-1---12deb004a21b4555
Call-ID: QGte_MV5DwfTRG38U_pS9w..
From: <sip:202@26.89.31.175>;tag=a6449c6d
To: <sip:101@26.89.31.175>
CSeq: 2 INVITE
Server: Asterisk PBX 18.11.1
Content-Length: 0`Preformatted text`

tell me where to look, what to do. check?

hi the sip dialog look fine
can you post some of the log that show the delay
please make sure that there are time stamps in the log

Is your hostname in /etc/hosts with its IP address? Do you have a STUN server configured in rtp.conf?

This log that I posted is the log before the pause starts. Everything is going well, but after a long pause, I did not send it.

cat /etc/hosts
127.0.0.1 localhost mydomain.com
::1 localhost

rtp.conf - I did not change, there is only this
cat /etc/asterisk/rtp.conf
[general]
rtpstart=10000
rtpend=20000

Your configuration doesn’t include any endpoints; they are all marked as templates.

There is no such option for chan_pjsip

the fourth line this. Or is not supposed to be there?

endpoins are there, I just didn’t show, they are all like

[100](endpoint_tpl)
auth=100
aors=100

[100](auth_tpl)
password=****
username=100

[100](aor_tpl)

“nat” is not supported, as an option, anywhere in pjsip.conf.

You don’t seem to have any contacts.

I see nothing that indicates what I would call a “crash”.

Here are my settings right now. I put “nat” in the template so they can’t connect to the server at all, writes that “No matching endpoint found”

[global]
user_agent=Phone
domain=mydomain.com
external_media_address=26.89.31.175
external_signaling_address=26.89.31.175
local_net=192.168.63.0/24
local_net=172.16.64.0/19
allow_reload=yes
;nat=force_rport,comedia

[transport-udp]
type=transport
protocol=udp
bind=0.0.0.0:6677

[endpoint_tpl](!)
type=endpoint
transport=transport-udp
nat=force_rport,comedia
context=sip_local
dtmf_mode=rfc4733
media_encryption=no
aggregate_mwi=yes
use_avpf=no
message_context=messages
disable_direct_media_on_nat=yes
rtcp_mux=no
rtp_symmetric=yes
rewrite_contact=yes
force_rport=yes
direct_media=no
language=ru
disallow=all
allow=alaw
allow=gsm
allow=ilbc
allow=ulaw
media_address=26.89.31.175

[auth_tpl](!)
type=auth
auth_type=userpass

[aor_tpl](!)
type=aor
max_contacts=2

[101](endpoint_tpl)
auth=101
aors=101

[101](auth_tpl)
password=*****
username=101

[101](aor_tpl)

[102](endpoint_tpl)
auth=102
aors=102

[102](auth_tpl)
password=*****
username=102

[102](aor_tpl)

There is no such setting in pjsip.conf. You already have the equivalents set, in your configuration but you need to understand that these are not required for the use of NAT, they are deliberate protocol violations to get round badly configured NAT settings, elsewhere.