(3/5) VoIP-How to Configure your Asterisk (SIP Accounts & Dialplans)
April 19th, 2015 // 1:36 pm @ Arad Gharagozli
Introduction
Hopefully by this article, you have got your Asterisk up and running, now it’s time to configure it to run, and create some accounts, then assign extension to them so they can call each other, and some basic Dialplans, which are scenarios that can handle the calls as the come in.
In this article we will discuss
- Network Security – Porting & NAT
- Creating SIP accounts
- Creating extensions
- Creating Dialplans
So without further ado, let’s jump right in
One-2-One NAT & Ports
Like any other service, if you are running the asterisk on a different subnet as your softphone, you need to create the routing paths. Moreover, if you are planning to access your asterisk from outside, example using your cell phone in 4G/LTE to connect to your Asterisk, then you need to configure your firewall.
On your firewall, open the following ports:
Protocol – Port number – Transport
SIP – 5060/5061 – TCP/UDP
IAX2 – 4569 -UDP
MGCP – 2727 – UDP
SCCP – 2000 – TCP
RTP – 10,000 to 20,000 – UDP
Manager – 5038 – TCP
H323 – 1720 – TCP
Dundi – 4520 – UDP
Unistim – 5000 – UDP
NOTE: The most important one is your SIP port, 5060 & the RTP ports. some of the other ports provide additional services such as Fax, Video etc, but you do need a 5060/UDP to have a SIP connection.
NOTE: Just a reminder that you will need an static IP address in order to perform this. If you are not a business client with your ISP or for any reason do not have static IP, you may acquire a Dynamic DNS Service. Some companies offer this for free (i.e http://www.noip.com/ )
Creating SIP Accounts
Open “sip_general_additional.conf” , and copy/paste the block. I have commented the action on top of each line. Just a reminder “;” is a comment in Asterisk OS
;Method of communication – UDP
transport=udp
; Creating our SIP Subscribers
;;[NAME OF THE GROUP]
[friends_internal](!)
type=friend ;For two way communications RX/TX calls
host=dynamic ; Any IP Address can lock on to – Needs User/pass
context=from-internal ;Treat calls that are coming from-internal like this
disallow=all ;Voice codec – Reject all – Start a clean list
allow=ulaw ;Voice Codec – add uLaw to the list (Used in Europe and Middle East)-Fairly high bitrate-good quality
allow=gsm ;Voice Codec – add gsm – Used by mobile subscribers, lower sound quality
allow=alaw ;Voice Codec – add alaw – used in North and south America, mainly
;; [USERNAME] use this as the username to connect to your server
[user-one](friends_internal)
secret=A9ahui ;; password- Since you have a dynamic host, you have to have a STRONG password
callerid=”Mrs. Campbell”<6020>
;; this is the caller ID and the format is ==> callerid=”Name To be Displayed”
[user-two](friends_internal)
secret=a13UI98a
host=dynamic
type=friend
callerid=”Mr. Bond” <3060>
So, based on the file above, we just created two account as follow:
1- Username: user-one
Password: A9ahui
Extension: 6020
2- Username: user-two
Password: a13UI98a
Extension: 3060
You may want to take a note of these settings then move along to the next part- Now, save the sip config file and exit.
Creating extensions
Open “extensions_additional.conf” and add the following sections. This creates an extension plan, so users can call each other
[from-internal] exten=>6020,1,Dial(SIP/user-one,50) exten=>3060,1,Dial(SIP/user-two,50)
- Wait your Asterisk is NOT ready for test, Yet!
So to explain the lines above, which are just a copy of each other;
[from-internal] just defines the context that your mailboxes belong to
exten=>6020,1,Dial(SIP/user-one,50) says: "Create an Exten"=>"Exten Number","FWD call",ACTION(SIP_Connection/USERNAME,RING_This_Many_Seconds) and the second line is similar to that. so technically you can create your accounts in the SIP as explained above, then create an extension for them down here in the extensions.conf pretty easy.
Creating a Dial Plan
This section is very important. As I explained before Asterisk is an immensely powerful software, you can create any scenarios with Asterisk, from running a small office, to a complex multi continent call center. and it will be all possible if you know how to create Dialplans. Just so you know, it is very easy to create a Dial Plan, you just have to familiarize yourself with syntax, the rest is just like building a Lego! Use your imaginations
Now, open “extensions_additional.conf” again, and add the following
Dialplan#1 : Two COMM Test
; This is Asterisk echo test function, so we can use that funtion
; and buld ourselves a test call-function. You can use this test to check
; COMM for both ways
;Creating extension 1001
exten => 1001,1,Answer()
; Play the wlcome message - Playback() is an internal func, it plays things!
exten => 1001,n,Playback(welcome)
; Asterisk will tell you about the demo
exten => 1001,n,Playback(demo-echotest)
; After PlayBack() is over Echo() function will start
exten => 1001,n,Echo()
; When done (By Pressing #) Playback() something for us
exten => 1001,n,Playback(demo-echodone)
; Another Playback
exten => 1001,n,Playback(vm-goodbye)
; Hangup() ends the call - Terminating the line
exten => 1001,n,Hangup()
As you can see, the bare bone is similar in every line, we start by exten, giving couple parameters, call a function and move on. So it's really easy to build things when you know the Syntax! - Wait your Asterisk is NOT ready for test, Yet! VERY IMPORTANT NOTE: ALWAYS FINISH EVERY DIALPLAN WITH Hangup(), like my last line!! If you don't you will end up with lose hanging calls, that are not in use. BAD things will happen!
Dialplan#2 : One Way COMM test
So the Dial plan above gave us the ability to check for, add this block to the end of “extensions_additional.conf”
;; ONE WAY TEST - A really short test, if you dial 1005 ;; You should hear a welcome message then hang up ; Create exten, 1005 exten=>1005,1,Answer() ; when reached, answer and PlayBack() something exten=>1005,n,Playback(welcome) ; When Done terminate the call exten=>1005,n,Hangup
Now, let’s save the extensions config file and exit
Applying the settings
Hopefully we got everything entered correctly, with no errors. So now we need to apply the changes, so we can test them. We can do sby restarting Asterisk, but later on don’t do that as it will interrupt your server. I will give you a code that will Reload the files as apposed restarting
[root@localhost ~]# service asterisk restart
Now hit enter, you should see the following:
Stopping safe_asterisk: [ OK ]
Shutting down asterisk: [ OK ]
Starting asterisk: [ OK ]
If all Ok, you got yourself an Asterisk! in the next article, I will let you know how to connect a softphone, and make test calls.
Category : VoIP - telephony