Configuring SIP Trunk in Asterisk from Ukrtelecom

I will give an example of setting up SIP Trunk in Asterisk, that is, Asterisk will be in the role of a SIP client.
From the provider Ukrtelecom received data: number, password and address of the telephony server (sip.ukrtel.net).
SIP number was taken to make multi-channel not an ordinary city number, by forwarding in case of busy lines.
I will configure on a Linux server with a real IP without using NAT, as well as on another with NAT (in the second case, you need to change nat=no to nat=yes and comment out canreinvite).

First, write the SIP registration line in the /etc/asterisk/sip.conf file, in the [general] section:

register => NUMBER:PASSWORD@sip.ukrtel.net
defaultexpiry=120
;registerexpired=3600
registertimeout=900
registerattempts=0
registerretry403=yes

Next, we write the context for SIP in sip.conf or users.conf, I prefer to register trunks in users.conf, in sip.conf I write only my SIP numbers:

[ukrtelecom1]
secret=PASSWORD
remotesecret=PASSWORD
defaultuser=NUMBER
trunkname=ukrtelecom1
host=sip.ukrtel.net
context=from-ukrtelecom1
insecure=invite
fromuser=NUMBER
fromdomain=sip.ukrtel.net
type=peer
disallow=all
allow=alaw
allow=ulaw
allow=g729
allow=gsm
canreinvite=no
dtmfmode=rfc2833
nat=no
qualify=yes
qualifyfreq=30

In /etc/asterisk/extensions.conf we will write the context for incoming calls:

[from-ukrtelecom1]
exten => s,1,DIAL(SIP/205,60)
exten => s,n,Hangup()

I’ll give an example of an outgoing call template:

exten => _380892XXXXXX,1,Dial(SIP/ukrtelecom1/${EXTEN},60)
exten => _097XXXXXXX,1,Dial(SIP/ukrtelecom1/${EXTEN},60)
exten => _095XXXXXXX,1,Dial(SIP/ukrtelecom1/${EXTEN},60)
и т.д.

Whether Ukrtelecom’s SIP has been registered can be viewed in the Asterisk console:

asterisk -rvv
sip show peers
sip show registry
quit

In case of connection problems, you can specify the IP address instead of the sip.ukrtel.net domain.

I noticed that sometimes the connection falls off and an error is displayed during outgoing calls (incoming calls work at the same time):

Received response: "Forbidden" from '<sip:38089XXXXXXX@sip.ukrtel.net>

If you execute “sip reload”, then calls can be made again.
Therefore, I specified the IP address in the configuration instead of sip.ukrtel.net and added the script to run in cron hourly:

nano /etc/crontab
0 * * * * root /dir/sip_ukrtel_register.sh > /dev/null 2>&1

The contents of the script (if the status is not “Registered”, then the “sip reload” command is executed):

#!/bin/sh
asterisk -rx 'sip show registry' | grep ':5060' | awk '{print $5}' | grep -v 'Registered' && asterisk -rx 'sip reload'

In order for the script to execute, you may have to specify live_dangerously=yes in asterisk.conf.

See also my articles:
Setting up SIP Trunk in Asterisk from Kyivstar
My other articles about Asterisk

Leave a comment

Leave a Reply