Asterisk Guide
Asterisk Guide
SIP
IAX – Inter Asterisk Exchange: can do some interesting things between 2 Asterisk PBX’s
DAHDI (Digium Asterisk Hardware Device Interface): analog FXO or FXS channels, TDM channels
.conf files
command line interface
Asterisk Gateway Interface
Asterisk Manager Interface
[section-heading]
key=value
; comment
./configure
If there are dependencies that are not installed, navigate to /contrib /scripts and run:
./install_prereq install
make menuselect
make
make install
Optionally, run <make samples> to create some sample config files and for a sample basic PBX: make
basic-pbx
to install asterisk program documentation run: make progdocs (requires doxygen to be installed)
asterisk is located inside /usr /sbin
to open CLI for asterisk, run /usr /sbin/asterisk -r (or rasterisk)
• extensions.conf syntax
- Contexts, Extensions, Priorities
- ‘n’ priority
- Priority labels
- ”same” designator
CONTEXTS:
Def: Contexts are containers that separate extensions. Like bucket for extensions
[context-name]
Example:
[context1]
extension
extension
extension
[context2]
extension
extension
extension
The way the contexts work is that by default, they separate extensions
Exemple:
[demo]
3000
500
3001
3002
[default]
6000
500
6001
6002
6005
If you comment a context, you must comment the extensions associated with that context too, because
otherwise those extensions will become part of the previous context; To avoid this, you can either
comment the extensions under the desired context, or comment the whole thing (group)
extension@context [context]
extension
• application
• application
• application
The concept of an extension being a phone is a legacy concept. A phone might have multiple extensions
configured
Each extension is a script that is gonna be executed: it could dial a phone, an IVR, a voice mail etc.
Each extension will have a series of actions (applications) that will be executed one at a time
• Syntax:
extension@context [context]
extension
1. application
2. application
3. application
4. application
1,2,3,4 are priorities
exten => extension,priority,application
To see all available applications, run <core show applications>
You can also run <asterisk -rx “core show applications”> and return to the bash CLI
TRAINING:
What is Asterisk?
It is an Open Source Telephony Platform. Using Digium Interface Cards, it can communicate directly
with analog phones.
Asterisk Characteristics: It is featureful. It supports: called ID, call recording, conference calling and
voice mail are just a few features that Asterisk provide.
-as a traditional PBX: in conjunction with Digium DAHDI interface cards, Asterisk can connect to the
public telephone network
- using VoIP, Asterisk can serve as a complete IP PBX, without any need to directly connect to a local
Telecom.
- as a hybrid PBX.
- Call Center
Operating System Requirements: it is supported on RedHat, fedora, Ubuntu, debian and CentOS
Minimum system requirements:
Dimensioning your Asterisk Server:
-how many simultaneous calls do I expect?
-will my system be transcoding audio from one codec to another?
- will my system be using conferences? If so, how many room and with how many users?
- will I be recording any calls?
- what other applications or services do I want to run on my Asterisk system?
Downloading& Installing:
It is best practice to install DAHDI before installing Asterisk, even if you don’t use it. Necessary
dependencies are: libnewt (C library for text screen widgets), kernel-headers(C header files for the
Linux kernel)
When Asterisk is installed for the first time, it is recommended that you run the command: make
samples
Configuration files:
asterisk.conf is an important configuration file since it specifies where asterisk should look for it’s
configuration files
This is where Asterisk is told how to handle both incoming and outgoing calls
In legacy PBXs, extension might refer to a physical line or an endpoint. In Asterisk, extensions are just
a dial string, used to access services as well as endpoints.
An Asterisk dialplan not unlike a router table in a modern networking switch
In the extensions.conf you will find the General section, followed by the globals sections
If you deleted a configuration file, you can find a copy in the /usr/local/src/asterisk/configs/ folder
Asterisk does not re-read the configuration files. If you made a change, you need to reload the module
for which the change was done or reload Asterisk. The command reload can be used: Run asterisk -r,
then reload
sip reload
module reload chan_sip.so
Asterisk.conf , extensions.conf and sip.conf are the three most important configuration files you’ll use
Modules are files in the Linux system and end in .so standing for Shared Object
These library files are loaded by default from the /usr/lib/asterisk/modules directory or from wherever
the astmoddir option is set in asterisk.conf
/etc/asterisk/modules.conf lets an administrative decide whether Asterisk should automatically load all
modules found in the modules directory or whether individual modules must be specified to be loaded
Asterisk core also provides System Timing so that audio from different sources can be syncronized
Asterisk is capable of handling many different types of media channels. Traditional analog and digital
telephony channels can be configured using Digium Hardware in the DAHDI driver package
Various VOIP channel types including SIP and IAX can also be used with Asterisk (chan_sip.so and
chan_iax2.so)
For each channel type that Asterisk supports, a channel driver module must be written. These drivers
are custom written Asterisk modules.
Applications are Asterisk modules used for dialplan processing. The actual routing calls in the dialplan
happens in the PBX core modules but the various actions calls take or actions done to calls are
implemented in applications (ex: dial an extension, play an audio file or record a voicemail message)
Each application module is dynamically loaded by the core when needed and most applications live in
a file with a name similar to app_dial.so or app_playback.so
Functions get or set channel data. They can manage func_callerid.so, func_cdr.so – Call detail records
Resources perform an action on or to the channel statically loaded. May operate simultaneously on
multiple channels. Ex: res_musiconhold.so
Digital media carried by Asterisk must be formatted in a specific predefined way. An audio or video
codec defines a standardized representation format that converts between that format and a needed
internal format.
you can hang up an ongoing call, update configuration settings or stop asterisk completely
asterisk -c will start asterisk and put you on the asterisk CLI
asterisk -r Start the Asterisk CLI when Asterisk is already running
core stop now will shutdown the Asterisk core
core restart now restart Asterisk
core stop gracefully it rejects new calls but only stops when the currently ongoing calls
terminate
core stop when convenient stops when call volume hits zero
core abort shutdown will cancel the shutdown for the command gracefully and when
convenient
core show version displays which version of Asterisk you’re running
core show settings show several configuration settings for Asterisk core
core show applications shows all applications that are currently available
core show channels outputs a list of currently available channels
! lets you execute a Linux shell command while you’re on the Asterisk CLI
Asterisk Dialplan is the heart of Asterisk. This is where all call routing occur
An asterisk dialplan is unlike traditional dialplans. There’s no direct association between an endpoint
and an extension
Asterisk dial plan routes calls to extensions and each extension performs one or more applications.
To map an extension to a phone, we use the dial application, but instead of dialing a phone, we could
use a voice mail application.
priority – is the first action asterisk will take when this extension is executed
Each new line or priority of an extension must begin with the same extension name
Example:
[internal_users]
exten => 6000,1,Answer()
exten => 6000,2,Playback(hello-world)
Playback with play the file contained as a parameter within (). The audio file reside in the asterisk’s
sounds directory
sip.conf
host=dynamic means that user doesn’t have a static IP address and must register to let Asterisk
know it’s IP address
context=internal_users Setting it like this points Asterisk get a context in the dialplan configured
in extensions.conf When the user dials a number on this phone, Asterisk will try to match the dialed
number against extensions in this context.
More than one extension can dial the same phone. For example, you can set up two extensions that will
dial the from at Reception. A user can dial 300, for example, and 400, both will dial the same phone in
the Reception
We can easily have another extension that looks identical except for the extension name and other
extentions, living in another context, can dial the same phone
20 is the timeout; this is the maximum number of seconds the endpoint will ring
Visual breakdown
What is a Dialplan?
Extension Syntax
An Asterisk priority is “a tag that tells each step in an extension when to execute”
Example:
Syntax:
exten =>6000,1,Playback(hello-world)
same => n(start-loop),Playback(goodbye)
same => n,Goto(start-loop)
Pjsip was introduced in Asterisk 12. Is the new de facto SIP channel driver
• 3 step process
1. Configure an account on Asterisk
2. Create an extension to dial the account
3. Configure the endpoint to match
When you configure an endpoint, you will define which context that endpoint is allowed to dial into
sip.conf:
[account-name]
type=friend
host=dynamic → this tells Asterisk that IP address might change, so use registration instead of IP addr
context=inside → tells Asterisk which part of the dialplan this phone can use
secret=password
To be reviewed:
pjsip.conf:
[transport-udp]
type=transport
protocol=udp
bind=0.0.0.0
pjsip.conf example:
In the endpoint section we’re defining the characteristics of the devices itself-the endpoint
An endpoint could be a trunk or a phone, anything that uses SIP
aors=7001 → address of record; basically you can have multiple devices attached to a single account.
So now you can dial that account and all the phones configured with it will ring simultaneously and the
first that answers gets the call.
Useful when you have for example a SIP phone on the desk, but also a softphone installed.
max_contacts=1 OR
[email protected]
If you leave just max_contacts=1 you’re expecting a registration and it basically tells Asterisk that only
one devices is allowed to register; if you change it to 2, then 2 devices can simultaneously register
Example:
[inside]
exten => 7001,1,Dial(PJSIP/7001,20)
The above extension means that endpoints with access to the “inside” context can dial that endpoint
you configured in sip.conf at 7001.
SIP Callflow:
First we have Doug who has an endpoint (205) and Jane also has an endpoint (200)
Doug dials 200 and that channel is set up with Asterisk and the phone sends the information to Asterisk
and says “Hey, I’m this endpoint and I need to dial extension 200”
So inside the pjsip.conf, that endpoint will be checked and we see context=inside so Doug has access to
the “inside” context
So now we go to the extensions.conf and within the “inside” context we find that one of the extensions
is 200 and that 200 extension executes the Dial application using the PJSIP channel driver against the
jane endpoint
Dialplan Basics:
an extension is a named set of actions that Asterisk will perform when that extension is dialed
each context is distinct, so extensions in one context are completely separated by extensions in another
context
Contexts:
if you want to include extensions from one context to another, you can use the include syntax:
Dialplan Priorities:
Asterisk Applications:
Applications execute synchronously and dynamically loaded by the Asterisk core when they’re called
Resources are statically loaded and can’t operate simultaneously on more than one channel
When an application module is loaded, is making available the Application to be used. For example,
when the app_dial.so is loaded, it makes it possible to use Dial()
Dialplan Application categories:
• Call Control
Dial(SIP/phone-1,20,etc..)
Answer()
Auto fallthrough occurs when there is nothing left for an extensions context to do, and a dial
fails.
OTHER NOTES:
explicit extensions
pattern match extensions
includes
switches
#include filename reads the contents of filename and place them in the current filename
#exec program runs a program and the output of that program will be place here
${EXTEN} is a variable and is going to be replaced with the dialed extension
ex: exten => _NXXNXXXXXX,1,Dial(SIP/provider/${EXTEN})
FreeSwitch - FusionPBX
Asterisk - FreePBX
3cx