
Modern problems need modern solutions, and Asterisk is a tool built to make telephone exchanges work better. It has to be installed and configured correctly for the PBX to run reliably.
What is Asterisk?
Asterisk is a computer telephony platform for building an IP PBX from scratch. It is open source and runs well on a range of operating systems.
Together with the other equipment you need, it provides the full feature set of a telephone exchange and supports several VoIP protocols at once.
It also supports voicemail, video conferencing and interactive voice response (IVR), handles incoming and outgoing calls, and keeps detailed call records.
Extra functionality can be written in Asterisk's own dial plan language, as a module in C, or through the more flexible Asterisk Gateway Interface (AGI) for integration with external systems.
How to install Asterisk: where to start
The Asterisk source code can be downloaded as an archive from the official website.
Next, update the system and configure SELinux. Install Midnight Commander and enable syntax highlighting for script files straight away.
Install the packages for the various network utilities, one package for each.
Then add the EPEL repository, install the required packages, and download and install pjproject and jansson. Do the same with the Asterisk archive.
Next, choose the modules and sounds you need; other settings can be left at their defaults. Many modules are installed at once, but you won't need them all, so disable the ones you don't use.
Set up the sound prompts in the language you need, choosing the wav format. In the original set-up the Russian core sounds were used, in good quality; the extra sounds are only available in English.
Finally, add Asterisk to start-up, start it and check that it is running from the console.
Configuration
Asterisk needs iptables to be configured, and there are two scenarios.
If the PBX has its own public IP address and connects to the internet directly, open only the ports you need and block the rest.
If the server sits behind a gateway without its own public address, it reaches the internet through NAT.
To run Asterisk behind NAT, forward port 5060 and the RTP range 10000–20000. Both use UDP by default; forward those ports unless you change the settings.
Adding users and testing calls
Now make test connections to check that the PBX works. A free softphone such as 3CXPhone v6, which is simple and easy to use, is fine for testing.
After downloading and installing it, configure the general settings and add new users.
To let users pick up each other's calls, set the callgroup and pickupgroup parameters. This is handy for colleagues in the same room who can see when someone has stepped away. These settings can also be made per user.
The CallerID can in theory be set in Cyrillic, but in practice that can cause call failures, so it is best to enter staff names or job titles in Latin characters.
Next, set the number of calls each phone can take at once, typically one call per phone: call-limit=1. You can allow several lines and put calls on hold, but that isn't always convenient.
Internal calls are built around one main number with several three-digit extensions, so you need a dial plan for the extensions.
Errors may appear at this stage, because much is still unconfigured. You can correct the list you have created from the management console, which shows names, passwords and contexts. The list may not be sorted, so some numbers aren't obvious at first.
Next, install a softphone or use a nearby phone to make test calls, calling from one device to another on the same channel.
FreePBX
Connect to the FreePBX web interface by entering the Asterisk IP address set during installation. If you've lost it, connect a monitor and keyboard to the server and log in as root: the IP address is shown at login.
Once you've connected to FreePBX, the browser asks you to create an administrator account with a username, password and the system administrator's email address.
Then select this option again on the home page to activate it. Follow the installer's prompts, entering your email address, password and phone number and the server's location.
SIP settings: anonymous calls, local networks, RTP ranges, strict RTP and codecs
SIP Settings is the module that shows these parameters graphically. It is used to set the external IP address, NAT and codecs, and is found in the Settings section.
Allow Anonymous Inbound SIP Calls restricts incoming calls, especially from withheld numbers. Always block unidentified numbers so that fraudsters can't use the connection to harm the business.
Local Networks is where you enter your local subnets. Asterisk will trust these addresses and keep connections open.
RTP Ranges sets the port range, but it is best left at the default.
Always enable Strict RTP, so the system automatically drops packets arriving from other addresses. This protects the system: the valid endpoints are fixed when the RTP stream between phones is set up.
Finally, tick the codecs you need under Codecs.
NAT settings
Connection problems such as dropped calls or one-way audio mean this option needs adjusting.
Go to the Asterisk SIP Settings module and open the Chan SIP Settings tab. Set NAT to Yes, choose a static address under IP Configuration and enter your public address under Override External IP.
Leave Reinvite Behavior set to No. Make sure your local subnet is listed under Local Networks, and forward port 5060 and the RTP Ranges port range on your router.
FreePBX network settings
The network settings must always include a static IP address, the time zone and DNS.
To set the network address, log in as the system administrator and open Network Settings. Under Network Interface select the network card (NIC), set IP Assignment to Static, set Gateway to the default gateway and tick Start Automatically so the interface comes up when the server boots.
Then set DNS on the tab of the same name by entering the DNS server's address.
The system clock should be right for your location, so set the time zone under Time Zone.
Enable Asterisk notifications so you hear about failures.
Next, set the sender address (From Address), the mailbox for system notifications (Storage Notifications) and a separate one for alerts about unauthorised login attempts (Intrusion Detection Notifications).
Security
Asterisk has a built-in intrusion detection system under Intrusion Detection. Configure it carefully: if your company's internal PBX addresses aren't entered, the system bans them and they can't work properly.
Keep an eye on its status, which should always be "Running". Restart it from Intrusion Detection if needed. Ban Time sets how many seconds an address stays banned.
Limit the number of connection attempts straight away with Max Retry, and limit the time window for attempts with Find Time. E-Mail is where you enter the address that receives alerts. The administrator should prepare a list of trusted addresses that can always connect and add them to the Whitelist.
Extensions and call routing
Phone settings and internal extensions are managed under Applications → Extensions.
Once the three-digit extensions are set up, configure the SIP trunk under Connectivity → Trunks.
Next, set up call routing so the server handles incoming and outgoing calls. This is done under Connectivity → Inbound/Outbound Routes.
A voice menu helps callers and makes transfers easier. Its settings are in the IVR module under Applications → IVR.
You can extend the dial plan for routing. Done properly, it enables speed dialling within the organisation and local calls without a prefix, just by dialling the number.
Save the edited dial plan and reload Asterisk with the reload command, or with the sip or dialplan commands.
Then test calls between phones, with one on an external channel and one on an internal one. Make sure outgoing and incoming calls work cleanly on both.
Voice menu
With the core of Asterisk configured, you can add the features you need.
Most companies set up an automated attendant that greets callers and directs them to the right person. The simplest and most convenient is an IVR.
It can be a simple greeting inviting the caller to enter a known three-digit extension or to press one of the options read out in tone mode. Either way, the recording ends by inviting the caller to wait for an operator (receptionist), who can answer general questions and transfer them to the right specialist.
You can record the audio messages any way you like and copy them into Asterisk. Alternatively, record them directly from a phone and use the recorded file.
That second option involves the dial plan, since the information has to be added to the common call context.
Once the extra lines are added, reload the dial plan. Now every caller will hear the recorded voice menu instead of silence or music. After a test listen, the file is saved to its own folder within Asterisk.
Voicemail
The next step is setting up voicemail in Asterisk.
If the person being called takes too long to answer, it is better to let the caller leave an audio message for them to listen to later. As well as an indicator on the phone, the owner gets an email notification, which makes it more likely the message will be heard.
In practice this extension isn't the most widely used.
To set it up, edit voicemail.conf. Leave the default parameters alone and add a voicemail entry for each member of staff to the default section: their extension, voicemail password and a working email address.
For notifications to work reliably, set up a properly configured local or external mail server straight away.
Then reload the voicemail module, check that the details shown are correct and add the same function to the dial plan.
Assign a special number that staff dial to access their messages: to listen to, delete or change them.
Call queues
To manage the flow of incoming calls, they need to be distributed properly. A queue routes incoming calls to free phones: the caller waits for the first available agent and is answered in turn.
In other words, the call goes to whichever phone becomes free first.
To configure it, list the phones that should receive calls at the end of the queue definition and leave the other options at their defaults. The strategy option has several values; choose the one that suits you.
Then set the call order by adjusting the exten entry.
From then on, callers go to the next free agent rather than a single receptionist. Add as many numbers as you need, as long as staff can physically handle the calls.
Statistics on incoming and outgoing calls are in the Asterisk call records at /var/log/asterisk/cdr-csv/Master.csv. Making them readable may need a developer's help, but you can try free tools yourself.
It is a good idea to record calls with customers to improve service and resolve disputes. This takes just a couple of changes to the dial plan.
Store the files so that recordings can be played back and copied to external media; MP3 is very convenient for this.