Advanced Asterisk Configuration

We’re assuming Asterisk is already been installed on your system, if not then you can learn how to install asterisk here. After following this advanced Asterisk configuration article step by step you will be able to:

  • Make and receive VoIP calls with SIP
  • Access voice mail

To make or receive calls, we need to edit configuration files in /etc/asterisk directory. The files which we’re going to edit are:

  • /etc/asterisk/sip.conf
  • /etc/asterisk/extensions.conf
  • /etc/asterisk/voicemail.conf

Requirements

To make external calls you need to subscribe to any good VoIP service provider. You can select any one according to your location.

Your VoIP provider will provide you with some access details which includes your username, secret password, DID number, VLAN (optional), host/gateway etc. Using these details we can configure our system for outbound and inbound calling.

Some VoIP provider provides an IP address to access the services, while some provides simply a domain for e.g. “toronto.voip.ms”. Some wired VoIP service providers also give you a VLAN ID to set. To set a VLAN, you can check our tutorial on it.

The details which we are going to use in this tutorial are:

Main Username : 6651
Password: p@ss1234
DID Number: 6651300
DID Point of Presence: 10.0.71.2

This is just a test information, use your own VoIP details in the upcoming steps.

Making a Backup

Before editing any files mentioned above, always make a backup of original files, because these files sometimes contain very important information to refer in case you need.

To make backup files, you can either make copies of original files with cp command and edit the original ones. or you can simply rename the files with mv command and create new files with the same names, I mostly prefer second method…

Method 1

Type the following commands one by one to make backup copy files by:

sudo cp /etc/asterisk/sip.conf /etc/asterisk/sip.conf.bk
sudo cp /etc/asterisk/extensions.conf /etc/asterisk/extensions.conf.bk
sudo cp /etc/asterisk/voicemail.conf /etc/asterisk/voicemail.conf.bk

And then edit the original files in upcoming steps.

Method 2

Type the following commands to rename original files to backup files by:

sudo mv /etc/asterisk/sip.conf /etc/asterisk/sip.conf.bk
sudo mv /etc/asterisk/extensions.conf /etc/asterisk/extensions.conf.bk
sudo mv /etc/asterisk/voicemail.conf /etc/asterisk/voicemail.conf.bk

And then create new empty files with the same names sip.conf, extensions.conf and voicemail.conf

Configure “sip.conf”

Open the sip.conf file by any preferred editor, we are using gedit

sudo gedit /etc/asterisk/sip.conf

And update the following content after editing your details into the file

[general]
context=internal
register => 6651:p@ss1234@10.0.71.2:5060
disallow=all
allow=ulaw
allowguest=no
allowoverlap=no
bindport=5060
bindaddr=0.0.0.0
srvlookup=no
alwaysauthreject=yes
canreinvite=no
nat=yes
session-timers=refuse
localnet=192.168.1.0/255.255.255.0

[voip-host]
canreinvite=no
context=internal
host=10.0.71.2
secret=p@ss1234
type=friend
username=6651
disallow=all
allow=ulaw
fromuser=6651
trustrpid=yes
sendrpid=yes
insecure=invite
nat=yes

[301]
type=friend
host=dynamic
secret=p@ss301
context=internal

[302]
type=friend
host=dynamic
secret=p@ss302
context=internal

In the extension number options i.e. 301 and 302, use your own numbers with secret of your own choice.

Save the file by pressing Ctrl+s, and exit.

Configure “extensions.conf”

Open the extensions.conf file by typing:

sudo gedit /etc/asterisk/extensions.conf

And update the following content by replacing your own details into it…

[internal]
exten => s,1,Answer()
exten => s,n,Hangup()

exten => 301,1,Answer()
exten => 301,2,Dial(SIP/301,60)
exten => 301,3,VoiceMail(301@main)
exten => 301,4,Hangup()

exten => 302,1,Answer()
exten => 302,2,Dial(SIP/302,60)
exten => 302,3,VoiceMail(302@main)
exten => 302,4,Hangup()


exten => 401,1,VoicemailMain(401@main)
exten => 401,2,Hangup()
exten => 402,1,VoicemailMain(402@main)
exten => 402,2,Hangup()

include => voip-host-outbound
include => voip-host-inbound

[voip-host-outbound]
exten => _1NXXNXXXXXX,1,Dial(SIP/${EXTEN}@10.0.71.2)
exten => _1NXXNXXXXXX,n,Hangup()
exten => _NXXNXXXXXX,1,Dial(SIP/1${EXTEN}@10.0.71.2)
exten => _NXXNXXXXXX,n,Hangup()
exten => _011.,1,Dial(SIP/${EXTEN}@10.0.71.2)
exten => _011.,n,Hangup()
exten => _00.,1,Dial(SIP/${EXTEN}@10.0.71.2)
exten => _00.,n,Hangup()

[voip-host-inbound]
exten => 6651301,1,Answer()

Save the file and exit

Configure “voicemail.conf”

Open the voicemail.conf file by:

sudo gedit /etc/asterisk/voicemail.conf

And update the following settings:

[main]
301 => p@ss301, user1, user1_mail@gmail.com
302 => p@ss302, user2, user2_mail@gmail.com

Save the file and exit.

Restart Asterisk And Check Registration status

After editing configuration files, you must need to restart/reload Asterisk to apply the changes. Use any of the following method to restart Asterisk:

sudo service asterisk restart

OR

sudo /etc/init.d/asterisk restart

OR

sudo asterisk -rx reload

That’s it…the configuration part of Asterisk is completed now, we can check the registration status by typing following commands:

sudo asterisk -r
sip show registry

Under State if it shows Registered , means you are connected to your Vo-IP service provider now. Any time if you want to exit from CLI, type:

exit

Conclusion

Asterisk is a feature rich and powerful software that can be a good option to your PBX system. Asterisk is a complete subject in itself, and explaining all the features and their functionalities is beyond the scope of this article. We’ll try to cover it as much as possible in our upcoming blogs.

If you are a beginner, you might have feel that besides its feature rich functionalities its little bit complicated to configure Asterisk, If yes, then you are not the only one. Many newbies find it difficult to work on Asterisk. The GUI based Distributions are a simple solution to it. You can install PBX ready dedicated distributions (generally linux based distributions) directly to your server/system and can access and manage your PBX through web based GUI very easily. Some of the popular PBX distributions are FreePBX, Elastix, OpenPBX, 3CX etc.