Asterisk is an open-source framework for building communications applications, It has been around for decades, nowadays modern collaboration solutions such as Microsoft Teams, Webex, Zoom are taking the lead. This article is focused on Asterisk SIP and Extension configuration only.
The SIP protocol is still widely used when you need to connect your Session Board Controller(SBC), Voice Gateway, CUBE, or IP PABX with external PSTN networks such as mobile and landlines, SIP is also the universal language when you integrate multiple phone systems together. It might be encrypted by SIP over TLS but the fundamental concepts are the same. In the below example, both External PSTN and Extensions are using the SIP trunk to connect.
Environment
1.OpenVZ Virtual Private Server hosted in the cloud, with Centos 7 Minimal installed
[test@admin ~]# lsb_release -d
Virtualization: openvz
Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 3.10.0
Architecture: x86-64
2. A combination of Fail2Ban and IPtables are implemented to secure the server
Please check here for the previous post of IPtables example
Asterisk version
[root@admin ~]# asterisk -V
Asterisk 11.25.3
3. SIP Trunk Provider: TWILIO ELASTIC SIP TRUNKING
4. Twilio’s web portal debugging is awesome when you have an issue with the SIP trunk.
5. Endpoints device/Extension: Andriod phone with Linphone App installed, App is managed from F-droid (the Play Store alternative)
sip.conf Configuration
sip.conf file is located in “/etc/asterisk/” path and it manages all the SIP trunks, extension numbers, and registrations.
[general]
;fake context on purpose
context=incomingggg
nat=yes
;allow=g729
allow=ulaw
;allow=alaw
;2allow=gsm
;autodomain=yes
;Do NOT allow external domain calls for security
allowexternaldomains=no
;bindaddr=0.0.0.0
domain=sip.ictfella.com
;Do NOT allow guest calls
alwaysauthreject=yes
allowguest=no
;tcpenable=yes
;tcpbindaddr=0.0.0.0
;bindport=443
;directmedia=no
[Twilio]
type=peer
;Below crendentials are provided by Twilio.
username=test
remotesecret=GuestMe
host=ictfella.pstn.us2.twilio.com
;port=5060
comtext=incoming
qualify=no
;defaultexpiry=60
insecure=port,invite
disallow=all
allow=ulaw
;progressinband=yes
;qualify=1000
[1000]
; better use peer instead of friend to reduce the security risk
type=peer
username=1000
secret=GuestMe
dtmfmode=rfc2833
callerid=”ICT Fella” <1000>
; Our phones will register to Asterisk.
; Otherwise we would define the IP address or FQDN of the phone on the following line.
host=dynamic
sendrpid=yes
canreinvite=no
; Deny registration from anywhere first
;deny=0.0.0.0/0.0.0.0
; Replace the IP address and mask below with the actual IP address and mask
; of the computer running the softphone, or the address of the hardware phone,
; either a host address and full mask, or a network address and correct mask,
; registering will be allowed from that host/network.
permit=0.0.0.0/0.0.0.0
context=ICTFella
directmedia=no
;transport=tcp
;nat=yes
;send litter keepalive packets to keep the conneciton open, especially under NAT environment
keepalive=yes
;bindport=443
Extensions.conf Configuration
extensions.conf is controlling the Dial plan, number transformation
Note: +614xxxxxxxx is an Australian Mobile number that verified in the Twilio portal, so my caller ID can be shown as a legit number rather than a doggy “private number” when making an external call.
[general]
static=yes
writeprotect=no
clearglobalvars=no
[globals]
; Global variables goes here
[incoming]
exten => s,1,Log(NOTICE, Incoming call from ${CALLERID(all)})
exten => s,n,Dial(SIP/${EXTEN})
exten => s,n,Hangup()
; End of the “incoming” context
[ICTFella]
; Testing extension, prepare to be insulted like a
; Monthy Python knight
exten => 201,1,Answer()
exten => 201,n,Playback(tt-monty-knights)
exten => 201,n,Hangup()
; Echo-test, it is good to test if we have sound in both directions.
; The call is answered
exten => 202,1,Answer()
; Welcome message is played
exten => 202,n,Playback(welcome)
; Play information about the echo test
exten => 202,n,Playback(demo-echotest)
; Do the echo test, end with the # key
exten => 202,n,Echo()
; Plays information that the echo test is done
exten => 202,n,Playback(demo-echodone)
; Goodbye message is played
exten => 202,n,Playback(vm-goodbye)
; Hangup() ends the call, hangs up the line
exten => 202,n,Hangup()
;Internal and External calls
exten => 100X,1,Dial(SIP/${EXTEN}) exten => _100X,n,Hangup() ; Call International numbers through Twilio, this one can handle with “+” exten => +XXXX.,1,GotoIf($[${CALLERID(num)}=1000])
exten => +XXXX.,2,Set(CALLERID(num)=+614xxxxxxxx) exten => +xxxx.,3,Dial(SIP/${EXTEN}@Twilio)
exten => _+xxxx.,n,Hangup()
; Call International numbers through Twilio, this one can handle country code& number without “+” in the front.
exten => _XXXX.,1,GotoIf($[${CALLERID(num)}=1000])
exten => _XXXX.,2,Set(CALLERID(num)=+614xxxxxxxx)
exten => _XXXX.,3,Dial(SIP/+${EXTEN}@Twilio)
exten => _XXXX.,n,Hangup()
Australian Sample Dialplans
[Sample]
;Internal calls
exten => _100X,1,Dial(SIP/${EXTEN})
exten => _100X,n,Hangup()
; Call Australia 13/1300/1800 numbers
exten => _13XXXX,1,Dial(SIP/+61${EXTEN}@Twilio)
exten => _13XXXX,n,Hangup()
exten => _1[38]00XXXXXX,1,Dial(SIP/+61${EXTEN}@Twilio)
exten => _1[38]00XXXXXX,n,Hangup()
;Call Australia mobile numbers
exten => _04XXXXXXXX,1,GotoIf($[${CALLERID(num)}=1000])
exten => _04XXXXXXXX,2,Set(CALLERID(num)=+614xxxxxxxx)
exten => _04XXXXXXXX,3,Dial(SIP/+61${EXTEN}@Twilio)
exten => _04XXXXXXXX,n,Hangup()
;Call Australia landlines
exten => 0[2378]NXXXXXXX,1,GotoIf($[${CALLERID(num)}=1000])
exten => _0[2378]NXXXXXXX,2,Set(CALLERID(num)=+614xxxxxxxx)
exten => _0[2378]NXXXXXXX,3,Dial(SIP/+61${EXTEN}@Twilio)
exten => _0[2378]NXXXXXXX,n,Hangup()
; Call International numbers through Twilio, this one can handle with “+”
exten => +XXXX.,1,GotoIf($[${CALLERID(num)}=1000])
exten => +XXXX.,2,Set(CALLERID(num)=+614xxxxxxxx)
exten => +xxxx.,3,Dial(SIP/${EXTEN}@Twilio)
exten => _+xxxx.,n,Hangup()
; Call International numbers through Twilio, this one can handle country code& number without “+” in the front.
exten => _XXXX.,1,GotoIf($[${CALLERID(num)}=1000])
exten => _XXXX.,2,Set(CALLERID(num)=+614xxxxxxxx)
exten => _XXXX.,3,Dial(SIP/+${EXTEN}@Twilio)
exten => _XXXX.,n,Hangup()
Useful link
Asterisk related
https://whirlpool.net.au/wiki/asterisk