• Basic asterisk setup after installation. Asterisk: installation and instructions

    The Linux program Asterisk is needed to create telephony and PBX servers. She has a lot useful functions, which will be appropriate in any office. Conferences, answering machines, call distribution, text messages, video, voice menu and voice mail. The utility supports popular communication protocols. They can be switched. But installing Asterisk on Ubuntu is not the easiest thing. The application is downloaded and configured via the terminal. Therefore, you need to learn console commands.

  • Go to the "contrib/scripts/" folder using the "cd" command.
  • Open the script "get_mp3_source.sh".
  • Type "make install".
  • Wait while the archives are downloaded.
  • Installed Asterisk must be configured both through the menu and through the terminal. So open your console.

  • Make configuration files. Can be used as a test. The command is “make samples”.
  • Activate the autorun function - “make config ldconfig”.
  • Now you can start the service - “service asterisk start”.
  • Or immediately open it as a daemon - “/etc/init.d/asterisk start”. To enable its console, enter the command “sudo asterisk -rvvvcd”.
  • For now, to work with Asterisk you need superuser rights. But it's better to create individual user and give him access to the program's functions. To do this:

  • Temporarily disable the utility - “service asterisk stop”.
  • Add a new user - “adduser [Name]”. You can create a group to which you will provide necessary rights. It will come in handy if you decide to create several users to work with different Asterisk services.
  • Now we need a directory to launch. Add it using the "mkdir" command. After it, write the parameter “-p” and the path to the folder “/var/run/asterisk”.
  • To make the application open immediately under the desired user, edit the file “/etc/default/asterisk”. Set the following parameters there: “AST_GROUP="dialout"" and "AST_USER="asterisk"".
  • You can do this easier - enter the script “sed -i ‘s/#AST_USER=”asterisk”/AST_USER=”asterisk”/g’ /etc/default/asterisk”.
  • Give the user access to all program folders - “chown -R [User-name] [Path-to-directory]”.
  • Open the “asterisk.conf” file, find the “runuser” parameter in it and specify the newly created user in it. If you made a group, also rewrite the line “rungroup”.
  • Reboot the system - “reboot”.
  • Log in as the Asterisk user - “su [Name]”.
  • And run the program.
  • To view information about it, enter “asterisk -rvvvv”.
  • The utility is ready to use. Next steps depend on the conditions under which the station will be used. There are several files that contain the configuration:

    • conf - general settings server. In it you can indicate how many subscribers are connected. They establish dialing rules.
    • conf - it also configures dialing rules and sets call parameters.
    • conf - configuration of subscriber accounts.

    With Asterisk you can create a PBX of any complexity. It has many useful functions and modules. After installation and configuration, you will be able to interact with the station using the client software. For example, Linphone.

    What you need to do before installation Refer to the section if you need to install a PBX that must cope with a heavy load, and you are not sure whether your software and hardware will handle it. Operating systems: the Asterisk server works great on Linux systems, was also done great job members of the project to port Asterisk server to BSD platforms, including FreeBSD, OpenBSD and Mac OS X. However, the zaptel driver and ISDN channel drivers may not be supported on these platforms. Refer to the Operating Systems for Asterisk Server section for operating system-specific information. Alternatively, you can use the methods described on the pages below: Asterisk Install CDROM Asterisk Bootable CDROM Quick Installation Instructions Read the 10-Minute Overview of Asterisk Server , if you want to know what the Asterisk server can do. Otherwise, you can skip this section. Read the section Step by step instructions on the Asterisk installation, where you will find information from setting up Linux to the first phone call running your Asterisk. http://www.automated.it/guidetoasterisk.htm http://asterisk.net.au/ Installation guide for Asterisk server from the guru of this matter System requirements You do not need any specific equipment to install and run the Asterisk server. Need for sound card no. You need to install the following software packages before compiling Asterisk: Kernel sources.h files for your kernel (kernel headers) bison (needed to process expressions in the file) Packages: openssl and openssl-dev or libssl-devlibnewt: required for the astman management interface to work. It is not required for the Asterisk server, but without this package you will not have the astman application, which is a separate program. You no longer need to install the "readline" and "readline-devel" packages for Asterisk. The server comes with its own implementation of the "readline" package, called "editline". If you plan to use add-ons to work with mysql database, install packages for mysql, mysql_devel & mysql server If you plan to use interface cards from Digium, then you will need to install the kernel module to support the Zaptel device driver before you can use them in Asterisk. However, you may want to first download and install Asterisk - test the operation of SIP and IAX phones - and only after that add support for your Digium cards. Installation See the section "Operating systems on which the Asterisk server runs" for additional instructions, which depend on the operating system used. How to get an Asterisk server Asterisk timer: needed for the MeetMe conference and for IAX2 trunks. Preparing third-party utilities Pay attention to the utilities section third-party developers on the main dedicated page for information about the following applications:
    Music-on-hold: Using mpg123voicemail: This requires sendmail to send email notifications. call detail recording: The Asterisk server can record this information in CSV files, in a PostgreSQL database, or in SQLite. Pay attention to the asterisk_addons package from SVN .odbc: for storing and retrieving data from other databases (other than MySQL). speex codec: installation of additional libraries is required. Speech synthesizer: Festival Speech recognition: integration with the Sphinx application.

    Websites, forums and entire portals like voip-info.org are dedicated to setting up Asterisk. But there are always people for whom this topic is a dense forest, and the product needs to be launched “yesterday”. Just a month and a half ago, all I knew about Asterisk was that it existed. This work is intended only to make life a little easier for those who find themselves in the same situation after me. It may contain errors of any degree. If you are an Asterisk configuration guru, point out the error, I will correct it, and my descendants will be grateful to you.

    First there was the word

    At some point in time, through my efforts, the company’s infrastructure development strategy was literally turned upside down. Goals and objectives were outlined and it became clear that we need a dynamic, mobile server infrastructure in order to save money, so that in case of any problems we can quickly recover and/or rise in another place, so that it is easier to care for the hardware, etc. p.

    Then there was the matter

    In general, on paper everything was beautiful and easy. It was just a matter of deploying and configuring Asterisk.
    First, two simple servers were purchased. Core i7-930, 12GB of memory and 12TB of SATA disks. Free Xen Server was installed on these servers and deployed virtual servers and workstations for remote workers.
    A QNAP NAS, which was inherited, is used as external storage.
    Terabyte local storage needed only to store the media bank, which is quite large. The servers themselves collectively weigh less than 3 terabytes.
    One of the servers was Asterisk to replace the old Panasonic TDE-200. Because the company needs cheap communication, direct numbers to different countries, and free negotiations between employees, then in general there is no alternative to it for 12 shekels.

    Day one: Make World

    It was decided to configure Asterisk natively for Citrix Xen operating system CentOS. The same one, only from the side. I’ll make a reservation right away: I’ve been a Windows administrator all my life, and I’ve only “played” with *nix in virtual machines, not counting a couple of web servers on hardware. Therefore, this deployment of Asterisk in Citrix Xen smacks of some naivety from the point of view of experienced people.
    In general, I followed the proven path: a detailed how-to instruction for dummies from the official manuals is opened on the laptop and executed on the server literally and without initiative. It will be possible to play as hero-fixers later, when everything is configured and working in the “default” state and the first full backup is made.

    Day two: yum install asterisk -y

    Not that I was very surprised, but, nevertheless, I went to a telecommunications friend for advice on setting up Asterisk when I discovered that there were already three living Asterisk forks: 1.4, 1.6 and 1.8. Each of them has their own cockroaches and lotions. Because I wasn’t flattered by the hope of defeating asterisk on a whim, so I decided to install version 1.4, like a friend’s, in order to have the highest possible compatibility of configs. Although, subsequently, we had to upgrade to 1.6 due to the lack of TCP support in 1.4, when such a need arose.
    To do this, a digium repository was attached to CentOS and Asterisk was installed from it.
    The installation went as expected, without a hitch. Basically, a sensible step-by-step roadmap with voip-info was used.
    iptables was immediately corrected to allow traffic on SIP ports.
    Not immediately, but I recommend that future generations install and configure a package called fail2ban immediately. Not at all extra program on a server exposed to the Internet. A day after installation, all of Taiwan went into drop, judging by iptables.

    Day three: Technical specifications for PBX functionality

    Let's start with the fun part - planning. Before any configuration process, it is necessary to write down and structure all the customer’s wishes and be sure to sign an agreement in order to avoid future conflicts of the type “no, I said something completely different.” In my case, the customer is the company I work for, but this does not change anything. We write terms of reference on the functionality, discuss it with the responsible people, settle disagreements and sign the final version and begin setting up Asterisk.
    The specifications for the configuration turned out like this:

    • Phone numbering is four digit.
    • The first digit of the number is a sign of the country where the office is located.
    • Numbering in each department begins with the first digit of the next hundred.
    • Each department is a separate call group.
    • If the called subscriber is in any way unavailable for the call, the call is transferred to the entire group.
    • Logic for servicing incoming calls:
    • Pick up the phone.
    • Play greeting.
    • Play an advertisement about current promotions.
    • Play options for calling various departments or offer to dial the subscriber’s number.
    • Starting from point 2, wait for any commands to be entered.
    • After completing step 4, wait another 10 seconds for commands to be entered.
    • If there are no commands, play the call options again.
    • If the subscriber is still dumb, then transfer the call to the secretary.
    • For users who need such a service, screw voicemail. In this case, if the user is in any way unavailable for calling, transfer the call to voicemail.
    • By default, calls are allowed only to Russia and Italy - the countries where our company mainly operates. The remaining directions are opened as needed with the narrowest masks, because we all remember scary stories about “Cuban telephone operators” and we don’t want one day our PBX suddenly starts calling Sierra Leone on all 50 channels at $14 per minute for each channel.

    At first glance, the task is simple and setting up Asterisk will not take much time, but in practice it took quite a lot of blood to coordinate it. Especially, to agree on a ban on all directions except those that are clearly permitted. The client had to agree to this only in the face of the otherwise inevitable need to configure a VPN on every device connecting to the PBX. I just try to keep the configurations as simple and understandable as possible, and the client always thinks that adding some functionality to the system is “just a couple of buttons to press.”

    Day four: nano sip.conf

    Now comes the fun part: the process of setting up Asterisk.
    In order not to drag out an already long article, burdening it detailed description torment of the initial configuration and subsequent tuning, I’ll just show my current configs with comments about what’s what.


    context=default ;default context
    allowguest=no ;no guests, we are not expecting anyone
    allowoverlap=no ;This parameter determines whether or not we allow the transfer of a call with additional digits. We do not allow it.
    alwaysauthreject=yes ;This parameter means that all errors for the external client look the same - authorization error. Designed to complicate hacking of PBX.
    useragent=Orgue de Barbaris ;This is how we introduce ourselves to others. I identified myself by the name of the first gramophone to make it easier for technical support of providers to find dialogues with my PBX, because... I have to communicate with them periodically.
    defaultexpiry=360 ;Interval for mandatory re-registration of clients.
    callevents=yes ;This is for the future so that the client can play music on hold controls
    limitonpeer=yes ;We count outgoing and incoming calls from peers together.
    tcpenable=yes ;Allow TCP protocol for SIP.
    rtptimeout=60 ;How long a client may not respond before being kicked out of the system.
    language=ru ;System language. Used for voice menu.
    bindport=5060 ;Default port. It can be changed to complicate the calculation and hacking of the PBX, but the solution is controversial.
    bindaddr=0.0.0.0 ;I have zeros because... The PBX has two interfaces and both have clients.
    srvlookup=yes
    tos_sip=cs3 ; http://www.voip-info.org/wiki/view/Asterisk+sip+tos
    tos_audio=efdisallow=all ;first disable all codecs
    allow=alaw ;then, we allow only those that we want to use. The order doesn't matter.
    allow=g729
    allow=g723
    allow=ulaw

    canreinvite=no ;This parameter prevents clients from communicating directly. Communication occurs only through the server. I do it this way because mobile clients use paid clients with the g.729a protocol, and landline clients use free clients without it. Therefore, I preferred to strain the server by transcoding alawg.729a on the fly in favor of connection quality for mobile clients. Moreover, the Core i7-930 does not notice this load at all.

    This article is a note in case I need to remember how to configure Asterisk to receive and send calls. This note should be enough to configure an office station on ip pbx Asterisk. Until now, I did not have a strong idea or experience of how to configure Asterisk to work without using FreePbx, that is, using only configuration files and the console. And now I’m just learning this. On the Internet, all settings come down to solving one problem or another, but I did not see an article capable of providing at least a basis for minimal configuration of an IP station. Maybe I didn't search well.

    So, I built and installed asterisk in the /etc/asterisk folder configuration files. What's next?

    1. The ability for internal subscribers to make calls to each other

    2. Setting up external lines in order for the station to receive the service of accessing city and long-distance numbers and receiving incoming calls

    3. Configuring the ability to make calls to subscribers to city and long-distance numbers. And take calls from the city.

    Here are three main tasks that need to be solved; naturally, the scheme may be different. That is, subscribers can be united into groups, there can be several external telecom operators, incoming call can be sent to an autoinformer, a queue, or maybe both. The scheme of services may vary and become more complex, but the first three conditions will be met in any case.

    Therefore, the first thing we do is create internal subscribers (peers) in the sip.conf file

    Subscriber A will have the following settings:

    Disallow=all
    allow=ulaw
    allow=alaw
    type=friend
    username=101
    secret=password
    qualify=yes
    context=101
    callerid=101
    host=dynamic
    call-limit=1
    canreinvite=yes
    accountcode=101
    amaflags=billing
    deny=0.0.0.0/0
    permit=192.168.0.66

    Where:
    disallow=all , prohibit the use of all codecs except G.711
    allow=ulaw
    allow=alaw

    type=friend, this parameter can take three values:

    - peer, this type is used to make incoming and outgoing calls. For incoming calls, the username and password will never be checked, but only the IP address and port number of the call source.

    - user an entry that can only make incoming calls

    - friend an entry that is both peer and user
    username=101
    secret=password
    Login and password respectively

    Periodically send a SIP message of the Options type to check monitoring of device availability for registration, useful when working through NAT to save values ​​in the translation table

    Context name, with routing rules

    Caller ID of our number

    host=dynamic
    host ip from which registration will take place

    call-limit=1
    (callcounter)
    Limit simultaneous calls, here you can set the number of channels

    canreinvite=yes
    (directmedia)

    This parameter is responsible for the RE-Invite procedure, if no, then all calls will go through Asterisk, if yes, the RTP stream will be sent between two devices bypassing Asterisk

    accountcode=101
    amaflags=billing

    The CDR record for the accountcode field will have the value 101
    The value of the AMA flag field for outgoing calls from this SIP user

    deny=0.0.0.0/0
    permit=192.168.0.66
    ACL ip, who we will allow registration

    Similarly for subscriber B:

    Disallow=all
    allow=ulaw
    allow=alaw
    type=friend
    username=102
    secret=password
    qualify=yes
    context=102
    callerid=102
    host=dynamic
    call-limit=1
    canreinvite=yes
    accountcode=102
    amaflags=billing
    deny=0.0.0.0/0
    permit=192.168.0.67

    Some more options in the feast that may be useful:

    transport=tcp,udp
    I can work not only using udp, it requires setting tcpenable=yes in general
    rtptimeout=180
    rtpholdtimeout=420

    Useful for SIP clients that do not Hangup when closed or disconnected. IN in this case The RTP session will be able to reset itself by timeout, rtpholdtimeout - if the call is on hold

    nat=force_rport,comedia

    If the device is behind NAT, then we fix the work via rport, send RTP packets back to the IP address and port from which they were received, ignoring information from SDP

    defaultexpiry=60
    Registration expiration time in seconds for incoming and outgoing registrations

    dtmfmode=rfc2833

    How we will work with DTMF signals

    1. So, task one, setting up routing between sip clients 101 and 102, in the simplest version can be solved with one line in the sip.conf file and include configs


    exten => _XXX,1,Dial(SIP/$(EXTEN),20,T)

    It is convenient to use sip.conf like this:

    Include => in_out_peer_local

    Now subscriber 101 will be able to communicate with subscriber 102 and vice versa, 102 will be able to call 101

    2. To create conditions under which internal subscribers will be able to access external lines, we will connect the station to the telecom operator using the same sip

    That is, we will create a trunk
    type=peer
    host=XX.XXX.XXX.XX
    port=5060
    fromdomain=ip of our station
    nat=no
    disallow=all
    allow=ulaw
    allow=alaw
    allow=gsm
    canreinvite=no
    ;allow=g722
    trustpid=yes
    sendrpid=yes
    dtmfmode=rfc2833
    qualify=yes
    insecure=invite,port
    deny=0.0.0.0/0.0.0.0
    permit=XX.XXX.XXX.XX/255.255.255.255
    context=provide

    The trunk settings are very similar to the peer settings, in principle this is a peer, important options
    fromdomain – set fromdomain in the sip packet so that you can understand where to return sip packets to our station
    trustpid=yes
    sendrpid=yes

    To trust or not the received Remote-Party-ID

    insecure=invite,port

    We do not require authentication of incoming INVITE messages, we do not check the port number only for compliance with the IP address

    3. It’s just a matter of small things, as soon as the trunk is activated, you need to register outgoing routing to make calls to subscribers A and B
    The de facto standard seems to say to always set up outgoing communication first

    Creating a context for making outgoing calls

    For outgoing calls to the city


    exten => _XXXXXX,1,Dial(SIP/ provider /$(EXTEN))
    exten => _XXXXXX,n,Hangup

    For outgoing calls to long-distance destinations


    exten => _8.,1,Dial(SIP/ provider /$(EXTEN))
    exten => _8.,n,Hangup

    After the outgoing connection is working, we set up the incoming connection

    In a simple case without autoinformer, groups and queues it will look like this


    exten => 2466754,1,Dial(SIP/$(EXTEN))
    exten => 2466754,n,Hangup

    Any station can be configured in the same way according to the principles discussed above.