How to create an endpoint and Dialplan on Asterisk

To Create An Endpoint And Dial Plan On Asterisk

Introduction

A SIP endpoint is simply a configuration profile for a device such as a phone or a remote server. Asterisk Dialplan context, which handles calls originating from the endpoint, and the audio codecs allowed for the endpoint are defined here.

Procedure

Step 1: Check the OS version by using the below command

root@linuxhelp:~# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 22.04.2 LTS
Release:        22.04
Codename:       jammy

Step 2: Check the status of the Asterisk by using the below command

root@linuxhelp:~# systemctl status asterisk
● asterisk.service - LSB: Asterisk PBX
     Loaded: loaded (/etc/init.d/asterisk; generated)
     Active: active (running) since Tue 2023-07-18 08:48:30 IST; 1min 24s ago
       Docs: man:systemd-sysv-generator(8)
    Process: 1398 ExecStart=/etc/init.d/asterisk start (code=exited, status=0/SUCCESS)
      Tasks: 73 (limit: 4537)
     Memory: 131.3M
        CPU: 2.695s
     CGroup: /system.slice/asterisk.service
             └─1441 /usr/sbin/asterisk
Jul 18 08:48:30 linuxhelp systemd[1]: Starting LSB: Asterisk PBX...
Jul 18 08:48:30 linuxhelp asterisk[1398]:  * Starting Asterisk PBX: asterisk
Jul 18 08:48:30 linuxhelp asterisk[1398]:    ...done.
Jul 18 08:48:30 linuxhelp systemd[1]: Started LSB: Asterisk PBX.
Jul 18 08:48:37 linuxhelp asterisk[1441]: radcli: rc_read_config: rc_read_config: can't open /etc/radiusclient-ng/radiusclient.conf: No such file or directory
Jul 18 08:48:37 linuxhelp asterisk[1441]: radcli: rc_read_config: rc_read_config: can't open /etc/radiusclient-ng/radiusclient.conf: No such file or directory

Step 3: Change the directory to the Asterisk configuration location by using the below command

root@linuxhelp:~# cd /etc/asterisk/

Step 4: Add the following lines to pjsip.conf file for add the endpoints by using vim editor

root@linuxhelp:/etc/asterisk# vim pjsip.conf
[167]
auth_type=userpass
type=auth
username=167
password=123456

[167]
type=aor
qualify_frequency=60
max_contacts=1
remove_existing=yes
qualify_timeout=3.0
authenticate_qualify=no


[167]
context=internal
auth=167
aors=167
type=endpoint
language=en
deny=0.0.0.0/0.0.0.0
trust_id_inbound=yes
send_rpid=no
transport=tcp_transport
rtcp_mux=no
call_group=
pickup_group=
disallow=all
allow=ulaw,alaw,gsm
mailboxes=300
permit=0.0.0.0/0.0.0.0
ice_support=no
use_avpf=no
dtls_cert_file=
dtls_private_key=
dtls_ca_file=
dtls_setup=actpass
dtls_verify=no
media_encryption=no
message_context=
subscribe_context=
allow_subscribe=yes
rtp_symmetric=yes
force_rport=yes
rewrite_contact=yes
direct_media=no
media_use_received_transport=no
callerid="linuxhelp" <167>

[168]
auth_type=userpass
type=auth
username=168
password=123456

[168]
type=aor
qualify_frequency=60
max_contacts=1
remove_existing=yes
qualify_timeout=3.0
authenticate_qualify=no


[168]
context=internal
auth=168
aors=168
type=endpoint
language=en
deny=0.0.0.0/0.0.0.0
trust_id_inbound=yes
send_rpid=no
transport=tcp_transport
rtcp_mux=no
call_group=
pickup_group=
disallow=all
allow=ulaw,alaw,gsm
mailboxes=300
permit=0.0.0.0/0.0.0.0
ice_support=no
use_avpf=no
dtls_cert_file=
dtls_private_key=
dtls_ca_file=
dtls_setup=actpass
dtls_verify=no
media_encryption=no
message_context=
subscribe_context=
allow_subscribe=yes
rtp_symmetric=yes
force_rport=yes
rewrite_contact=yes
direct_media=no
media_use_received_transport=no
callerid="linuxhelp2" <168>

Step 5: Login to the Asterisk CLI mode by using the below command

root@linuxhelp:/etc/asterisk# asterisk -rvvvvvvv
Asterisk 20.3.1, Copyright (C) 1999 - 2022, Sangoma Technologies Corporation and others.
Created by Mark Spencer <markster@digium.com>
Asterisk comes with ABSOLUTELY NO WARRANTY; type 'core show warranty' for details.
This is free software, with components licensed under the GNU General Public
License version 2 and other licenses; you are welcome to redistribute it under
certain conditions. Type 'core show license' for details.
=========================================================================
Connected to Asterisk 20.3.1 currently running on linuxhelp (pid = 1441)

Step 6: Reload the pjsip.conf file by using the below command

linuxhelp*CLI> pjsip reload
Module 'res_pjsip.so' reloaded successfully.
Module 'res_pjsip_authenticator_digest.so' reloaded successfully.
Module 'res_pjsip_endpoint_identifier_ip.so' reloaded successfully.
Module 'res_pjsip_mwi.so' reloaded successfully.
Module 'res_pjsip_notify.so' reloaded successfully.
Module 'res_pjsip_outbound_publish.so' reloaded successfully.
Module 'res_pjsip_publish_asterisk.so' reloaded successfully.
Module 'res_pjsip_outbound_registration.so' reloaded successfully.
    -- Reloading module 'res_pjsip.so' (Basic SIP resource)
[Jul 18 10:43:29] NOTICE[1656]: sorcery.c:1348 sorcery_object_load: Type 'system' is not reloadable, maintaining previous values
    -- Reloading module 'res_pjsip_authenticator_digest.so' (PJSIP authentication resource)
    -- Reloading module 'res_pjsip_endpoint_identifier_ip.so' (PJSIP IP endpoint identifier)
    -- Reloading module 'res_pjsip_mwi.so' (PJSIP MWI resource)
    -- Reloading module 'res_pjsip_notify.so' (CLI/AMI PJSIP NOTIFY Support)
    -- Reloading module 'res_pjsip_outbound_publish.so' (PJSIP Outbound Publish Support)
    -- Reloading module 'res_pjsip_publish_asterisk.so' (PJSIP Asterisk Event PUBLISH Support)
    -- Reloading module 'res_pjsip_outbound_registration.so' (PJSIP Outbound Registration Support)

Step 7: Show the endpoints by using the below command

linuxhelp*CLI> pjsip show endpoints
 Endpoint:  <Endpoint/CID.....................................>  <State.....>  <Channels.>
    I/OAuth:  <AuthId/UserName...........................................................>
        Aor:  <Aor............................................>  <MaxContact>
      Contact:  <Aor/ContactUri..........................> <Hash....> <Status> <RTT(ms)..>
  Transport:  <TransportId........>  <Type>  <cos>  <tos>  <BindAddress..................>
   Identify:  <Identify/Endpoint.........................................................>
        Match:  <criteria.........................>
    Channel:  <ChannelId......................................>  <State.....>  <Time.....>
Exten: <DialedExten...........>  CLCID: <ConnectedLineCID.......>
==========================================================================================

 Endpoint:  167/167                                              Unavailable   0 of inf
     InAuth:  167/167
        Aor:  167                                                1
  Transport:  tcp_transport             tcp      3     96  0.0.0.0:5060

 Endpoint:  168/168                                              Unavailable   0 of inf
     InAuth:  168/168
        Aor:  168                                                1
      Contact:  168/sip:168@192.168.6.101:60884;ob         6172a74b12 Unavail         nan
  Transport:  tcp_transport             tcp      3     96  0.0.0.0:5060

Objects found: 2

Step 8: Add the following lines in the pjsip.conf file for transport protocol by using vim editor

root@linuxhelp:/etc/asterisk# vim pjsip.conf
[tcp_transport]
type=transport ; Must be of type 'transport'
protocol=tcp
bind=0.0.0.0
tos=cs3
cos=3
allow_reload=false
[udp_transport]
type=transport ; Must be of type 'transport'
protocol=udp
bind=0.0.0.0
tos=cs3
cos=3
allow_reload=false

Step 9: Add the following lines in extensions.conf for dialplan by using the vim editor

root@linuxhelp:/etc/asterisk# vim extensions.conf
[internal]
exten => 167,1,Dial(PJSIP/167)
exten => 168,1,Dial(PJSIP/168)

Step 10: Login to the asterisk CLI mode and reload the extensions.conf file to reload the dialplan by using the below command

root@linuxhelp:/etc/asterisk# asterisk -rvvvvvvv
Asterisk 20.3.1, Copyright (C) 1999 - 2022, Sangoma Technologies Corporation and others.
Created by Mark Spencer <markster@digium.com>
Asterisk comes with ABSOLUTELY NO WARRANTY; type 'core show warranty' for details.
This is free software, with components licensed under the GNU General Public
License version 2 and other licenses; you are welcome to redistribute it under
certain conditions. Type 'core show license' for details.
=========================================================================
Connected to Asterisk 20.3.1 currently running on linuxhelp (pid = 1441)
linuxhelp*CLI> dialplan reload
Dialplan reloaded.
  == Setting global variable 'CONSOLE' to 'Console/dsp'
  == Setting global variable 'IAXINFO' to 'guest'
  == Setting global variable 'TRUNK' to 'DAHDI/G2'
  == Setting global variable 'TRUNKMSD' to '1'
    -- Including switch 'DUNDi/e164' in context 'dundi-e164-switch'
    -- Including switch 'Lua/' in context 'default'
    -- Including switch 'Lua/' in context 'local'
    -- Including switch 'Lua/' in context 'demo'
    -- Including switch 'Lua/' in context 'public'
    -- Including switch 'DUNDi/e164' in context 'ael-dundi-e164-switch'
    -- Time to scan old dialplan and merge leftovers back into the new: 0.005089 sec
    -- Time to restore hints and swap in new dialplan: 0.000034 sec
    -- Time to delete the old dialplan: 0.000143 sec
    -- Total time merge_contexts_delete: 0.005266 sec
    -- pbx_config successfully loaded 51 contexts (enable debug for details).
[Jul 18 10:52:10] WARNING[17401]: pbx.c:8797 ast_context_verify_includes: Context 'local' tries to include nonexistent context 'iaxtel700'

Step 11: Register the endpoints with the Zoiper and MicroSIP as shown in the below images

Step 12: Test the call from one endpoint to another as shown in the below image

Call successfully receiving

Conclusion:

By this how to create endpoint and dialplan in Asterisk has come to an end.

FAQ
Q
How to reload the extensions.conf file?
A
By running the following command dialplan reload
Q
How reload the pjsip.conf file?
A
By running the following command pjsip reload
Q
What is an Asterisk call?
A
Asterisk is a powerful tool for building call center systems and solutions.
Q
What is a SIP endpoint?
A
A SIP endpoint is a device that makes and receives calls through your gateway.
Q
What is Dialplan in asterisk ?
A
The Asterisk dialplan is responsible for routing calls, so it is often referred to as the heart of an Asterisk system.