TNEWS... articles about innovation and telecommunication

How to configure IP PBX Asterisk from scratch

Hardware selection and step-by-step instructions for setting up and configuring Asterisk IP-PBX

Modernization of office PBX

In connection with the expansion of the company and areas of activity, the question arose of organizing communication between all divisions and branches. Office PBX could not cope with the load, so it was decided to add IP PBX based on Asterisk to it.

Old communication scheme:

Organization of fixed-line telephony of an office PBX enterprise

Figure 1. The network diagram of the organization of telephone communications of the enterprise before upgrading the office PBX.

Realized telephone communication scheme:

Asterisk IP PBX organization diagram after upgrade

Figure 2. Network diagram of the organization of telephone communications of the enterprise after the modernization of the office PBX.

PSTN – Public switched telephone network.

PBX – Office PBX.

E1 – Digital channels.

SIP – (Session Initialization Protocol) is an IP telephony signal exchange protocol used to set up, modify and end telephone calls.

Asterisk is a software server for managing computer telephony (ATS).

LAN – local area network.

Asterisk-interface is a specialized protocol between Asterisk and SFP-E1 module.

Asterisk-based IP PBX is the next generation communications for modern business. In terms of capabilities, it fully covers the functionality of office PBXs, and in some cases even superior.

Hardware selection

Considering that the implementation of this project was built using the Asterisk IP PBX platform, all the hardware used should be software compatible with Asterisk software.

Asterisk is an open source open source VoIP telephony application running on the Linux operating system.

To install the Asterisk IP PBX software platform, a personal computer (PC) with pre-installed Linux OS was used, in which there was a free PCI slot.

A Terratel 4E1 Digital Telephone Card with a hardware echo cancellation module (up to 128 voice channels) was installed in this PCI slot.

photo of a digital board up to 4 E1 telephony for Asterisk with a hardware echo cancellation module

Figure 3. Digital Telephony Card in configuration 4 Е1 and PCI form-factor

Digital E1 Telephony Card Brief technical specifications:

  • Up to 120 simultaneous calls to 4 E1 ports
  • Support for TDM protocols: ISDN PRI, CAS
  • PCI form factor
  • Support for hardware echo cancellation module

This software and hardware complex was located in the premises of an analog automatic telephone exchange, where all commissioning work was subsequently carried out.

For modernization of office PBX with 1 E1, used for telephoning a remote office, an original solution of the same manufacturer, Terratel SFP VoIP Converter, was chosen.

Photo of the SFP-E1 digital telephone module for Asterisk

Figure 4. SFP VoIP Converter for Asterisk project

Technical specifications of SFP VoIP Converter for Asterisk project:

  • Up to 30 simultaneous calls on port 1E1
  • Support for TDM protocols: ISDN PRI, CAS
  • SFP form factor

The main advantage was the minimal cost of the solution, mainly due to the fact that it did not require the installation of another PC to install the Asterisk server.

Using a specialized driver, SFP VoIP Converter was connected to the Asterisk IP PBX server located in the main office.

This scheme made it possible to modernize and integrate the existing telephone network with minimal resources, as well as introduce VoIP telephony and expand subscriber capacity.

Operating system installation

Since Asterisk has minimal hardware requirements, one of the free computers with a Celeron processor, 2 GB memory and an 80 GB screw was chosen.

The first step is to install the operating system. We settled on Ubuntu. The version of the Ubuntu ISO image can be downloaded on the official page http://www.ubuntu.com.

We used version 16.04.

To quickly prepare a bootable USB flash drive with Ubuntu from under Windows, we used the free Unetbootin program.

Download from the site, and run the program unetbootin-windows-647.exe. A window will appear in which we select the UBUNTU distribution and version 16.04_Live.

Select UBUNTU distribution

Figure 5. UBUNTU distribution selection window.

The program begins the installation process.

Another option for creating a bootable USB flash drive is to select a disk image with the UBUNTU system (.ISO extension), for example, at http://releases.ubuntu.com/14.04/.

After creating a bootable flash drive, insert it into the selected computer. In the BIOS, indicate the boot from USB-HDD0. Save changes and overload. During the boot process, the computer will automatically boot from the USB flash drive and installation of the system to the hard drive will begin.

During the installation, you need to make some settings (language, time zone, etc.).

At boot time, Ubuntu launches seven full-screen consoles, each with its own independent session, from the first to the sixth with a command line interface, in the seventh it starts graphical mode. The user sees only graphical mode during loading.

You can switch to one of the virtual consoles by pressing the key combination:

Ctrl + Alt + F1 – the first virtual console;


Ctrl + Alt + F7 – the seventh virtual console, return to graphical mode.

Launch the terminal by pressing the key combination: Ctrl + Alt + T

Install ASTERISK software and drivers

Installing the ASTERISK server software is as follows.

root                     // Install as root
apt-get update           // Check and install updates
apt-get install ntp      // Install Time Sync Service
apt-get install asterisk // Install Asterisk
asterisk –r              // Information about Asterisk

DAHDI Installation

DAHDI driver is responsible for the operation of telephony interface cards installed directly in the server or working on TDM over IP from various manufacturers: Digium, Openvox, Terratel, Sangoma, Parabel, Cronyx, etc.

Installing an additional module from the source code for the Linux kernel in Ubuntu without violating the package structure of the distribution takes place using the module-assistant application.

We assemble the desired module, which after assembly will be automatically installed (a-i = auto-install):

m-a a-i dahdi

View the status of kernel modules.

lsmod

dpkg – It is a package manager for Debian systems. It can install, remove, and create packages, but, unlike other package management systems, it cannot automatically download and install packages or their dependencies. We carry out:

dpkg -L dahdi-modules-4.8.0-36-generic   // lists the files installed by the package

View Linux kernel module wct4xxp module information.

modinfo wct4xxp

Load the kernel module into memory and activate it.

modprobe wct4xxp

View the state of kernel modules.

lsmod                             // will show a list of loaded modules
apt search dahdi                  // search for packages
apt install dahdi asterisk-dahdi  // installs the dahdi package

Check that the module has started.

lsmod | grep dahdi

Answer:

dahdi 221184 2 oct612x,wct4xxp

If the module does not start, repeat the installation of the dahdi module.

Command line options when starting an Asterisk server

In fact, you can start the Asterisk server without any arguments. The Asterisk server, if it starts without parameters, runs in the background:
/usr/sbin/asterisk
You can connect to the Asterisk server already running in the background and access its console by typing:
/usr/sbin/asterisk -r
on the same machine where the Asterisk server is running. Several CLI consoles can be connected to the same running Asterisk server at the same time.

Stop and restart Asterisk

To stop and restart Asterisk, there are several commands:

core stop now         // stops Asterisk immediately, ending
                      // all current calls
core stop gracefully  // prevents new calls, but lets end
                      // current calls

When all calls are over, Asterisk stops.

core stop when convenient    // wait for calls to be made to Asterisk, and then
                             // stop the service.

This does not interfere with new challenges.

To restart, similarly:

core restart now        // overload Asterisk immediately, ending everything
                        // current calls.
core restart gracefully   // prevents new calls, but allows you to end current calls.

When all calls are over, Asterisk is rebooted.

core restart when convenient   // waits for calls to be made in Asterisk, and then reloads the service.

This does not interfere with new challenges.

There is also a team if you change your mind.

core abort shutdown     //cancels shutdowns or reboots that you previously started.

Configuring the Terratel D-401E telephone card with Asterisk

Turn on the server, execute the command that displays PCI device and buse:

lspci -v

In the list you can see the parameters of the installed E1 telephone card.

If there is no information about the E1 board, you should try moving board to other PCI slots or check the switch on the board, which should be set to number 1.

After successful registration of the E1 telephone card, its parameters are automatically written in the configuration: /etc/dahdi/ and /etc/asterisk/dahdi-channels.conf.

If errors occur with the dahdi_cfg command, then dahdi may not be installed.

In the file /etc/dahdi/system.conf, change the zone to ours (it may be reset after the dahdi_genconf command is executed):

loadzone=ua
defaultzone=ua

In the file /etc/asterisk/modules.conf, in the [modules] block there should be a line for autoload of the chan_dahdi module:

load => chan_dahdi.so

You can restart dahdi from the Asterisk console with the command:

dahdi restart

You can check the status of the board with the command:

dahdi show status

Dahdi teams at CLI Asterisk

The following commands are used to configure and configure DAHDI:

core show help dahdi             // Show all dahdi commands
dahdi destroy channel            // Destroy the channel
dahdi restart                    // Restart dahdi
dahdi set dnd                    // Activate/deactivate the DND function (do not disturb)
dahdi set hwgain                 // Install channel hardware gain
dahdi set swgain                 // Install channel gain software
dahdi show channels [group | con // Show active channels
dahdi show channel               // Show channel information
dahdi show status                // Show the status of all DAHDI cards
dahdi show version               // Show the version used by DAHDI

Setting up the ASTERISK software application

General Asterisk Settings (/etc/asterisk/asterisk.conf)

Check the following in the asterisk.conf configuration file:

  • The location, access rights and owner of socket that used to connect the remote server management console.
  • location of various directories used by the Asterisk server to determine the location of configuration files, libraries, scripts and the place where log files will be created.

Configure E1 Channels (/etc/dahdi/system.conf)

We indicate the zonal (regional) affiliation.

loadzone=ua
defaultzone=ua

We configure flow coordination between the operator’s exchange and Asterisk.

1,0,0,CCS,HDB3,CRC4  // Set the synchronization source, encoding type and
                     // the need for parity
bchan=1-15,17-31     // Set time slots for voice                       
dchan=16             // Set alarm time slots for data
                     // (0th - default)
echocanceller=mg2,1-15,17-31 // Specifies the type of echo canceller and time slots,
                     // on which it will be involved. If the line is commented out,
                     // devices use hardware echo cancellation.

To apply the new configuration system.conf must be run.

dahdi_cfg -v

DAHDI Setup (/etc/asterisk/chan_dahdi.conf)

The chan_dahdi.conf file defines the parameters of the TDM channels of the DAHDI interface.

context             // link the channel to the dialplan
channel             // assigns a channel or several channels
group               // assigns channels to the group

For outgoing communication, the first free channel will be selected. To assign to several groups, you must list the values separated by commas. To not assign to a group, leave the value empty. Groups are intended for choosing the outgoing strategy and the rules for processing incoming calls.

group = 1
group = 2,3
group =
      switchtype    // sets the type of alarm for PRI.
      national      // National ISDN type 2 (American)
      ni1           // National ISDN type 1
      euroisdn      // EuroISDN
      qsig          // Minimum Functionality Protocol Used
                    // to build a network between two or more exchanges.
switchtype => euroisdn

signalling – The parameter sets the type of connection and / or signaling. These parameters should correspond to what is described in the DAHDI driver configuration (/etc/dahdi/system.conf). The value of this parameter partially depends on the type of interface card you are using.

The Asterisk server will not start in such cases: if the connection type definition for the channel is incorrect or inoperative, if the value does not match what is described in the Zaptel driver configuration, or if the device is not installed or configured incorrectly.

In many cases, the correct value for this parameter is one of these next four meanings: fxs_ks, fxo_ks, pri_cpe or pri_net. This parameter does not have a default value; you must definitely determine its values ​​before describing any channel.

fxo_ks: Used to signal FXS devices.

fxs_ks: Used to signal FXO devices.

ATTENTION! These analog interfaces can be a source of confusion in Asterisk.
For FXS interfaces fxo_ks is used, and for FXO – fxs_ks.

pri_cpe: Alarm PRI. Client side of equipment (user)

pri_net: Alarm PRI, network side.

priindication: This parameter sets how the Asterisk server should signal the status of Busy() and Congestion () for the remote switch or user. Default: inband. The available values are as follows:

inband: The Asterisk server will itself play tones without changing the channel to the answered state; not available for all PRI/BRI connections.

outofband: The Asterisk server will disconnect from the busy / congestion information code, while the telephone switch itself will play tones to the user. Busy(), in this case, is the same as setting: PRI_CAUSE = 17 and executing the command: Hangup().

pridialplan – sets the dial plan type for ISDN PRI. Ignored in most cases. It may be necessary for CallerID to work correctly. Available values: unknown, local, private, national, international.

pridialplan => national

overlapdial: if – yes, then the dialed numbers will be immediately sent to the stream. Default: no. (enblock)

overlapdial => yes

Audio Quality Options

echocancel enable echo cancellation. The default is always on.

echocancelwhenbridged enable or disable bridge echo cancellation between TDM interfaces. In principle, this mode does not require echo cancellation, but sometimes can improve the quality of communication. Value (yes/no).

rxgain – receiver gain adjustment.
txgain – transmitter gain adjustment.

echocancel = yes
echocancelwhenbridged = no
rxgain = 20%
dahdi restart           // reboot dahdi

User Connections (/etc/asterisk/sip.conf)

There are two ways to connect users to the Asterisk — through the users.conf file, which is common for the entire Asterisk or through dedicated files — sip.conf and iax.conf — respectively, for the SIP and IAX2 protocols.

The second option with separate files will allow you to more finely configure different sections.

In the [general] section, to begin with, make the minimum necessary settings.

[general]
context=internal_phones  // This context will be used
                         // for calls from / to internal phones
allowoverlap=no          // Disabling dialing as a number arrives, i.e.
                         // the system will wait for the full number and only
                         // then it will start typing.
srvlookup=no             // The function allows you to dial a number
                         // by user domain name

Now you need to register the phone itself.

[300]                    // client's number (login)
type=friend              // the user can receive calls and make calls
secret=300               // password to connect the phone
username=300             // for simplicity, the username is the same as its number
host=dynamic             // because phones get IP over
                         // DHCP, then you need to set the value to dynamic
dtmfmode=rfc2833         // method for transmitting dtmf – dialing tones
disallow=all             // prohibit all codecs
allow=ulaw               // allow ulaw codec, the codec should be
                         // which is supported by the client
context=default          // the context describes which section of the dialplan
                         // customer calls will be held
callerid=300             // set the number to display. With outgoing
                         // calls this number will be displayed.
deny=0.0.0.0/0           // restrictions on the IP address for the client
permit=192.168.110.25    // allow IP address for client

Open the extensions.conf file in the editor:

sudo nano /etc/asterisk/extensions.conf

And we’ll indicate the following lines at the end so that users can call each other:

[sip-dialout]
exten => 6000,1,Dial(SIP/6000)
exten => 6001,1,Dial(SIP/6001)

Restart Asterisk to apply the changes:

sudo service asterisk restart

As a result of these actions, we added two users and they can call each other.

We reboot the SIP configuration and look at the result.

asterisk*CLI> sip reload
asterisk*CLI> sip show users

Username    Secret    Accountcode    Def.Context    ACL Forcerport
300           300       default          Yes              No
301           301       default          Yes              No

Both phones are connected.

Dialplan File (extensions.conf)

The extensions.conf dialplan file defines how Asterisk will behave on incoming and outgoing calls. Essentially, it consists of a list of instructions or steps that Asterisk will follow. Dialplan consists of four main elements: contexts, extensions, priorities, and applications.

Contexts

Dialplans are divided into sections called contexts. Contexts are named extension groups that perform several functions.

Contexts isolate different parts of the dialplan, preventing them from interacting. An extension defined in one context is completely isolated from extension numbers in another context, unless interaction is specifically permitted.

Contexts vary by name. All instructions posted after the description of the context and before the description of the next context are part of this context. At the beginning of the dialplan there are two special contexts, [general] – contains a list of general settings for the dialplan and [globals] – global variables.

Another important application of contexts (perhaps the most important) is security.

Extension numbers

When you call a specific extension (either an incoming or an internal call), Asterisk will follow the steps defined for that extension.

Extension Syntax:

exten =>

Next is the name (or number).

A full extension consists of three components:

  • Name (or number)
  • Priority (each extension can include many steps; the sequence number of a step is called its priority)
  • An application (or command) that performs some action on the call

These three components are separated by commas:

exten => name,priority,application()

Here is an example of what the extension looks like:

exten => 123,1,Answer()

Extension number s

When calls are received in the context for which a specific extension is not specified, they are transferred to extension s.

For each call, three actions will be performed (answering it, playing a sound file and disconnecting):

[incoming]
exten => s,1,application()
exten => s,n,application()
exten => s,n,applications()

Priorities

Each extension can include many steps, called priorities. Each priority is numbered sequentially, starting at 1, and runs one specific application. For example, the following extension answers the call (priority 1) and then disconnects (priority 2):

exten => 123,1,Answer()
exten => 123,n,accomplish something
exten => 123,n,accomplish something else
exten => 123,n,complete the last
exten => 123,n,Hangup()

Applications

Each application performs a specific action on a given channel, for example, playing sound, receiving tonal input, calling a channel, disconnecting, etc.

Some applications, such as Answer() and Hangup(), do not require any additional instructions. Some applications require additional information.

Answer(), Playback() and Hangup() Applications

The Answer() application is used to answer the channel on which the call is being made. It performs the initial setup for the channel receiving the incoming call.

The Playback() application plays a pre-recorded audio file on the channel. Sound files, by default, are located in the directory/var/lib/asterisk/sounds (This path can be changed in the asterisk.conf file).

The Hangup() application disconnects the active channel.

Background(), WaitExten() and Goto() Applications

Background() – The application plays the recorded sound file.

The Background() application is used to create voice menus (in our case, we used it as an answering machine or an interactive secretary).

Syntax Background():

exten => 123,1,Answer()
exten => 123,n,Background(main-menu)

Приложение WaitExten() (Ожидание добавочного номера):

exten => 123,1,Answer()
exten => 123,n,Background(main-menu)
exten => 123,n,WaitExten()

If you want WaitExten() to wait for a response for a certain amount of time (instead of using the default timeout), simply specify the number corresponding to the required number of seconds as the first argument in WaitExten():

exten => 123,n,WaitExten(5)

Both Background() and WaitExten() allow the subscriber to dial.

The Goto() application is used to redirect a call to another part of the dialplan.

Handling erroneous entries and timeouts

Now that the creation of our first voice menu is nearing completion, we’ll introduce special extensions. Firstly, we need an extension for invalid entries; when the subscriber presses the wrong button, the call is routed to extension k. Secondly, an extension number is needed to handle situations when the subscriber does not make input on time (the default timeout is 10 s). If the subscriber does not press the button for too long after starting the WaitExten() application, calls are routed to extension m.

External subscribers do not have the ability to connect with a real living person. To connect an external subscriber with a real person, the application responds – Dial() (Call).

Dial() takes four arguments. The first is the recipient of the call. It consists (in its simplest form) of the name of the technology (or transport protocol) with which the call is made, the slash character (/) and the name of the remote endpoint or resource. The most widely used types of technology are Zap (for analog and E1 channels), SIP, and IAX2.

You can also call on several channels at the same time, combining call recipients using the ampersand (&) symbol:

exten => 123,1,Dial(Zap/1&Zap/2&SIP/Jane)

The Dial() application also allows you to establish a connection with a remote VoIP endpoint that was not previously described in the channel configuration files. Here is the complete syntax for this type of connection:

The second argument to the Dial() application is the timeout specified in seconds.

The third argument to Dial() is a string of options. It may contain one or more characters that affect the behavior of the Dial() application.

The fourth argument to the Dial() application is the URL.

exten => s,1,Dial(Zap/4/2317154,,tTm,1)

Introduction to extensions and contexts

Channels are assigned contexts. Contexts define set rules for channels
A dial plan consists of one or more contexts. Each context is simply a set of extensions (extensions). Each extension in the context has a unique name.

Contexts are used to perform the basic functions of the PBX:

  • Security: You can allow long distance / international calls only to specific subscribers
  • Call routing: Call routing depending on the number of the subscriber
  • Auto Attendant: Play a greeting and prompt for an extension
  • Multi-level voice menus: Voice menus for support, sales, etc
  • Authorization: Request a password to access some extensions
  • Callback: Allows you to reduce the cost of long-distance / international calls
  • Access Lists: Blacklisting annoying subscribers, preventing them from contacting you
  • Virtual PBX: You can create a virtual PBX within your primary PBX
  • Day/Night mode: You can change the behavior of your PBX depending on the time of day
  • Macros: You can create scripts to solve repetitive tasks in terms of typing

What is extension?

In Asterisk, extension is defined as a list of applications and their arguments executed in a specific order. The order of execution is determined by priorities.

Dialing a number

Most often, a different interface is called. The call is made by the command Asterisk Dial.

[default]
exten => 100,1,Dial(DAHDI/1,20)
exten => 100,2,Voicemail(u100@default)
exten => 100,102,Voicemail(b100@default)

This example illustrates the different options in the event that the call is not answered. First, the DAHDI / 1 channel is called, if after 20 seconds no one answered, the call is routed to VoiceMail() with the announcement “Subscriber does not answer” (u100), If the subscriber is busy, the call will go to priority N+101, in our case it is priority 102.

CallerID Routing

Example routing by caller ID.

[default]
exten => 100/1234567,1,Congestion
exten => 100,1,Dial(DAHDI/1,20)
exten => 100,2,Voicemail(u100)
exten => 100,102,Voicemail(b100)

If extension 100 is called, the call is routed to the DAHDI/1 interface, unless the call is made by subscriber 1234567. In this case, the call is rejected. The example shows that the caller ID is set by the form ‘/1234567’.

If CallerID is missing, the routing example will look like this:

[default]
exten => 100/,1,Zapateller
exten => 100,1,Wait(0)
exten => 100,2,Dial(DAHDI/1)

In this example, if a call arrives without a CallerID, the call is blocked using the Zapateller() application.

Call a group of phones

It is often required that a “non-answer” call is transferred to another phone. An example is as follows.

[operator]
exten => 0,1,Dial(DAHDI/1,10)
exten => 0,2,Dial(DAHDI/1&DAHDI/2&DAHDI/3,10)
exten => 0,3,Playback(companymailbox)
exten => 0,4,Voicemail(100)
exten => 0,5,Hangup

The call arrives at DAHDI/1, if the phone is busy or does not answer within 10 seconds, the call goes to a group of phones, including DAHDI/1. If this time no one picks up the call, the call goes to voicemail.

There is a special mechanism for processing and distributing multiple calls – a queue, which is called by the Queue() command.

Asterisk IVR

An example of creating a voice menu:

[sales]
exten => s,1,Background(welcome-sales)
exten => 1,1,Goto(default,100,1)
exten => 2,1,Goto(default,101,1)
[mainmenu]
exten => s,1,Background(welcome-mainmenu)
exten => 1,1,Goto(sales,s,1)
exten => 2,1,Dial,DAHDI/2
exten => 9,1,Directory(default)
exten => 0,1,Dial,DAHDI/3

The ad plays on extension ‘s’. The ad suggests dialing ‘1’ for a call, for example, of a sales department (the transition is made to the context of ‘sales’). Dial ‘2’ – call DAHDI/2. Set ‘9’ is a directory call (see Directory) and ‘0’ is a DAHDI/3 call.

Using Variables

Asterisk has global variables used as arguments to commands. Variables are written in the dialplan as ${foo}, where ‘foo’ is the name of the variable. Names must begin with a letter and can consist of any numbers and letters, but there are predefined names, here are some of them:

  • ${CONTEXT} The current context
  • ${EXTEN} Current extension
  • ${EXTEN: x} Current extension with deleting the first digits (where x is the number of digits to be deleted)
  • ${PRIORITY} Current Priority
  • ${CALLERID} Current CallerID (name and number)
  • ${CALLERIDNUM} Current Caller ID
  • ${CALLERIDNAME} Current name is Caller ID
  • ${RDNIS} DNIS redirection

Global variables are assigned in the [globals] section of the dialplan.

By organizing a dialplan in this way, you can quickly and easily reassign physical interfaces to specific users, often used in contexts.

Time Routing – Day & Night modes

Nested contexts can be used to implement day, night and holiday modes. Consider the following example:

[newyears]
exten => s,1,Playback(happy-new-years)
[daytime]
exten => s,1,Dial(DAHDI/1,20)
[nighttime]
exten => s,1,Playback(after-hours-msg)
[default]
include => newyears||||1|jan
include => daytime|9:00-17:00|mon-fri
include => nighttime

In this example, the day, night and holiday modes of arrival of call processing are set.

Outgoing calls

The direction of outgoing communication can be realized by defining a short access code (for example, ‘9’), or by defining a completely pattern of dialed numbers.

[international]
ignorepat => 9       // do not turn off the ready tone after dialing the specified digit
exten => _9810.,1,Dial(DAHDI/g2/${EXTEN:1})
exten => _9810.,2,Congestion
include => longdistance

[longdistance]
ignorepat => 9
exten => _98[02-9]XXXXXXXXX,1,Dial(DAHDI/g2/${EXTEN:1})
exten => _98[02-9]XXXXXXXXX,2,Congestion
include => local

[local]
ignorepat => 9
exten => _9[02-79]XXXXXX,1,Dial(DAHDI/g2/${EXTEN:1})
exten => _9[02-79]XXXXXX,2,Congestion
include => default

In this example, 3 contexts with different access rights to the public telephone network are considered.

The [international] context allows you to dial an international number with any number of digits.

Context [longdistance] – long-distance number up to 11 digits.

Context [local] – city number up to 7 digits long.

The variable ${EXTEN: 1} removes the prefix.

Patterns Patterns

Extensions can be matched to a template, instead of uniquely specified numbers. The pattern must begin with an underscore (_) and can use any of the following characters:

X – any digit from 0-9

Z – any digit from 1-9

N – any digit from 2-9

[14-6] – numbers 1,4, 5 and 6

. – any possible characters.

Redundant Trunks and LCR (Low Cost Direction Selection)

The LCR (Least Coast Routing) setting is responsible for the optimal route with respect to cost and redirection rules in the event of an external line failure.

Asterisk Call Recording

[macro-mixmonitor]
exten => s,1,Set(RECORD_FILENAME=${STRFTIME(${EPOCH},,%Y%m%d-%H%M%S)}-${CALLERID(num)})
same => n,MixMonitor(${RECORD_FILENAME}.wav,b)
same =>  n,Dial(${ARG1},180,)
[outbound_route1]
exten => _9.,1,Macro(mixmonitor,PJSIP/sipprovider/${EXTEN:1})

In this example, a call with the prefix ‘9’ must be switched through the ITSP SIP trunk. The conversation will be recorded in the ‘wav’ format and saved to the default directory /var/lib/asterisk/monitor/YearMonthDay-HoursMinutesSeconds-Number of the Caller.wav

The same structure allows us to shorten the code by avoiding the numerous repeating exten ⇒ s, in this case.

Customization Voicemail.conf, queues.conf

These files are responsible for setting up voicemail.

Command line options when starting an Asterisk server

In fact, you can start the Asterisk server without any arguments. The Asterisk server, if it starts without parameters, runs in the background:
/usr/sbin/asterisk
You can connect to the Asterisk server already running in the background and access its console by typing:
/usr/sbin/asterisk -r
on the same machine where the Asterisk server is running. Several CLI consoles can be connected to the same running Asterisk server at the same time.

Restart Asterisk

After final configuration of the Asterisk software application, it is advisable to restart the system of one of the commands:

To stop and restart Asterisk, there are several commands:

core stop now                // stops Asterisk immediately, ending
                             // all current calls
core stop gracefully         // prevents new calls, but lets end
                             // current calls
core stop when convenient    // wait for calls to be made to Asterisk, and then
                             // stop the service.