Introduction
Good day. Writing an article led me to the need to transfer my knowledge to my subordinates, who already had time to delve into the work of Asterisk.
When I noticed an interest in the platform from their side, I was extremely happy, but I was perplexed when all the zeal stopped at the clacking on trixbox and its like.
I have nothing against add-ons to Asterisk, which make life easier, but I am afraid that a generation of Asterisk administrators soon appeared, who did not see the console live in the future.
The goal of my articles is to show that the asterisk is beautiful in itself, without additional add-ons, which is possible using minimal scripting languages ​​that speed up the work - to work wonders. I want to show people who are looking for and wanting to learn new things, the nuances and subtleties of the system.
What is Asterisk?
About the asterisk there are many articles describing the functionality and features. A beginner needs to know the most important thing - at the initial stage (as a training), the Asterisk is able to perform any tasks related to telephony, or almost all.
There are a number of inconveniences or limitations that are inherent in working with Asterisk, we will try to eliminate them in the process of familiarization with the system.
You should also understand that it is extremely difficult to build a high-load system on an asterisk - there are other solutions for this.
For simplicity, we can assume that the asterisk is advisable to use in systems where the number of simultaneous calls does not exceed 100.
')
Start from here
Honestly looking through the 10 pages of the Asterisk search query results on a habr, I realized that I had to start all over again, but without fanaticism. I will not talk about the installation, but we will talk about the structure of the Asterisk and what we need when working. We will talk about Asterisk 1.8, but the principles work on all versions of the asterisk.
System structure
Asterisk, like any application, works on the basis of configuration files, of which there are quite a lot. Honestly, I still do not know the role of half of the configs. For our initial work, we need to know and understand the settings stored in the sip.conf and extensions.conf files. I note that with a standard installation all configs files are stored in / etc / asterisk /.
Sip.conf file
This file contains a description of the basic parameters of the SIP protocol, setting up NAT, codecs, and most importantly - accounts. Later I will talk about how to store accounts in the database.
The default sip.conf config allows you to run Asterisk, provided that you are prescribed accounts, and it will work while listening to incoming connections on all interfaces.
Accounts in sip.conf can be of three types:
- user (user)
- peer
- friend (user + peer)
I almost always set up accounts as a friend, for the reason that it combines all the functions of both a peer and a user.
A simple example of an account looks like this:
[1001]; the name of the feast, we will use it in the future, to work with the rules of calls,; matching with the login is optional
type = friend; account type
host = dynamic; we allow login from different IP addresses
username = 1001; Username
secret = 1234; password
context = default; context about it later
disallow = all; ban all codecs
allow = alaw; allow G.711a codec (alaw)
Such a record is enough to register on a fresh server with user parameters 1001 and password 1234.
Create two entries with the names 1001 and 1002 at the very bottom of the sip.conf file.
File extensions.conf
This file is a key file in the Asterisk system, since it describes the rules for working with any voice traffic that has appeared in the system. This is like a static routing table. On the storage of data in the database will talk later.
The file structure is quite simple:
- global parameters are written inside the file, including variables
- further, the file is divided into contexts, each of which lives its own life and the rules for the operation of calls within each context can be different.
Contexts are needed to distinguish between the behavior of a telephone call and the separation of some user groups and their calls from others. Contexts allow to create multiple subsystems with their own rules and users (analogue of virtual machines) within the same system.
Contexts are denoted as [CONTEXT NAME].
The context structure is as follows:
exten => MASK, ORDER, ACTION
where
MASK - number mask, or statically specified number
ORDER - order of action for a specific MASK (a sequence of actions is possible)
ACTION - a command executed by the system in case of a call to this rule.
Our test users are created in the default context, so if you just launch an asterisk and call any number, you can hear the Asterisk test demo menu.
We open for editing extensiond.conf, do a search on [default] and in the next one after the line [default] we boldly enter the local call rule:
Static rule:
exten => 1001,1, Dial (SIP / 1001)
exten => 1002.1, Dial (SIP / 1002)
Dynamic rule:
exten => _XXXX, 1, Dial (SIP / $ {EXTEN}); here X says that any number will be dialed, about methods; making masks (extensions) - later.
These rules will allow you to make a local call between test users.
Finally: Work with the server console
The server is started with the asterisk command from under the root, or / usr / sbin / asterisk.
To enter the console, enter asterisk -r from under the root, or / usr / sbin / asterisk -r (hereafter, for convenience, we will use asterisk, meaning that we are talking about working with the server executable file).
In order for Asterisk to re-read configs from the console, it is enough to reload.
homework
1. Make a local call.
2. Get acquainted with configuration examples that are in sip.conf and extensions.conf
3.Add to bookmarks
www.voip-info.org/wiki/view/AsteriskThanks for attention.
Thank you so much for the feedback and comments.
I want to note that the article is designed for people who are starting to study Asterisk and is aimed at making their lives easier. In the future, I want to take into account all the comments, and make and write new articles according to the wishes, while maintaining the general line of development from simple things to complex ones.
It is nice to receive criticism, I will try, and in case of inaccuracies to correct.
Thank.